whoward / cadenza

parser and renderer library for liquid-like templates
13 stars 6 forks source link

Tag Modifiers #3

Closed joefiorini closed 11 years ago

joefiorini commented 12 years ago

Something else I noticed that would make it difficult to convert from Liquid is the lack of "modifiers" on the for loop tag. For example, in Liquid I can do:

{% for post in posts limit: 3 offset: 2 %}
...
{% endfor %}

This is extremely useful for designers since they don't have much access to filter the collection any other way. What would be even better is the ability to use filters within tags like:

{% for post in posts | limit: 3 | offset: 2 %}
...
{% endfor %}
{% if posts | empty %}
...
{% endif %}

etc.

I believe the latter example would just require a couple small changes to src/cadenza.y, is that correct? Is that something you'd be interested in having?

Thanks! Joe

whoward commented 12 years ago

Actually that's a pretty good idea, I'm wondering if we could just generalize the concept a bit and allow filter syntax to be applied anywhere where a variable is used that way. That way all of these would be treated the same to the parse tree:

   {{ foo | bar | baz: 123 }}
   {% for x in y | foo | bar: 123 %}...{% endfor %}
   {% for x in (y | foo | bar: 123) %}...{% endfor %}
   {% if posts | empty %}...{% endif %}

Doing this would require changing src/cadenza.y and also moving the filter evaluation logic from lib/cadenza/nodes/inject_node.rb to lib/cadenza/nodes/variable_node as well as any fixing specs that'll break so it'll probably be a large commit.

If we can do it without causing any Shift/Reduce or Reduce/Reduce conflicts in the parser then I'd say lets go for it!

joefiorini commented 12 years ago

I like that a lot. I'm not incredibly experienced with parsers but it's something I'd like to learn. Unless you have time to get to it first, I'll take a stab at it in the next couple weeks (I have a number of features for my app I need to get to first). Do you mind me posting my newbie questions as they come up?

Thanks!

whoward commented 12 years ago

Haha for sure, ask away, I can't guarantee I'll be able to answer them - I really can't claim to be an expert myself on parsers but I will try :)

If you're really interested there is the classic book: http://www.amazon.com/dp/0321486811/ref=cm_sw_su_dp which I have as well but be prepared for a really tough read!

You can also try the book by Marc-André Cournoyer, Its not nearly as comprehensive but its a lot easier to get through http://createyourproglang.com/

joefiorini commented 12 years ago

I have a couple of MA's books but haven't read that one yet. It just moved up my list!

On Oct 21, 2012, at 1:09 AM, William Howard notifications@github.com wrote:

Haha for sure, ask away, I can't guarantee I'll be able to answer them - I really can't claim to be an expert myself on parsers but I will try :)

If you're really interested there is the classic book: http://www.amazon.com/dp/0321486811/ref=cm_sw_su_dp which I have as well but be prepared for a really tough read!

You can also try the book by Marc-André Cournoyer, Its not nearly as comprehensive but its a lot easier to get through http://createyourproglang.com/

— Reply to this email directly or view it on GitHub.

whoward commented 12 years ago

awesome, i'm going to tag this for v0.8.0 as it may result in some backwards-incompatible changes

whoward commented 11 years ago

alright and now we have this feature in master, let me know if you run into any issues!