Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math parser should do more complicated parsing for spec templating #25

Closed
ishubin opened this issue Nov 23, 2013 · 5 comments
Closed

Math parser should do more complicated parsing for spec templating #25

ishubin opened this issue Nov 23, 2013 · 5 comments

Comments

@ishubin
Copy link
Member

ishubin commented Nov 23, 2013

At the moment galen allows this:

[1 - 9]
menu-item-@
    near: menu-item-@{+1} 0 px right

But what would be nice to have is more complex parsing like this:

[1 - 9]
menu-item-@
    near: menu-item-@{*2 + 1} 0 px right

Or reusing the @ symbol together with brackets

[1 - 9]
menu-item-@
    near: menu-item-@{+(@*2 - @/(@-1))} 0 px right
@ishubin ishubin added p3 and removed p2 labels Oct 6, 2014
@alecky
Copy link

alecky commented Oct 7, 2014

It would also be good to be able to Iterate based on a condition such as every odd, even element or every 3rd or 4th element

[3n+1]
menu-item-@
    near: menu-item-@{+1} 0 px right

@ishubin
Copy link
Member Author

ishubin commented Oct 7, 2014

@alecky Awesome idea! Will work on the concept

@ishubin
Copy link
Member Author

ishubin commented Oct 9, 2014

@alecky
I've just realized that this piece of string in Galen Specs "${.....}" - is actually a javascript executor. But the parsing is very stupid so you can't use '{' and '}' symbols inside it. I had to implement a quick solution for ${count("menu-item-*")} so I chose javascript. But here is the crazy thing I tried and it worked:

====================
menu-item-*     css #menu li a
====================

[ ${var a = 2, b = 4; a + " - " + b;} ]
menu-item-@
    width: 100px

In the end that gave me this [ 2 - 4 ]. This means that in theory we can do much more advanced stuff ourselves without waiting for additional function to appear in Galen. But not at the moment as this javascript executor is very limited and doesn't support load("myscript.js") function. So thats what I am going to pick up with this issue. Its hanging for a long time but I just completely forgot about this solution.

So here is how it could look in the end

====================
menu-item-*     css #menu li a
====================

@@ import myscript.js

# or like this

${load("myscript.js")}

[ ${everyEven("menu-item-*")} ]
menu-item-@
    width: 100px

And here is the content of myscript.js:

this.everyEven = function (namePattern) {
    var amountOfAllObjects = count(namePattern);

    var arr = [];

    for (var i=2;i<amountOfAllObjects.length; i+=2) {
        arr.push(i);
    }

    return arr.join(",");
};

@ishubin
Copy link
Member Author

ishubin commented Nov 2, 2014

Ready in release-1.4 branch

@ishubin
Copy link
Member Author

ishubin commented Nov 2, 2014

Implemented two things Javascript in specs and complex operations in @{ } expression.
Will work like this :

[ 1 - 10]
object-@
   above: object-@{index + 2 * (index - 1)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants