Hi everybody,
Yesterday I added some new functionality into Sintags I think is worth sharing.
If you don't know Sintags yet, it is a simple way to make your views prettier writing less code. There are two kinds of Sintags, the basic Sintags
{print_this_var}
and the Ruby-like Sintags
<%= link_to 'Forum', :controller => 'forum' %>
Right now there is not much documentation about Sintags, but I think that looking to the test data for basic, ruby and the new blocks and assignments can be helpful at this point. In those tests to will see Sintags and its equivalent PHP, which is only generated once if the template has modifications in order to to take advantage of PHP accelerators.
For those of you who already knew Sintags this is what's new!
String assignment
<% simple_var = 'value' %>
Array element assignment
<% simple_var = var-foo %>
Object attribute assignment
<%= var = var.foo %>
Assigning the result of a helper
<% url = url_for(:controller => 'page') %>
Assigning a Sintags array
<% url = {:controller => 'page'} %>
or
<% url = :controller => 'page' %>
This is the simples for of block and it is just like a loop. With one downside inner code can only be PHP at the moment.
<% keys {|key| echo $key} %>
This is the same as before but will run the block first on keys and then on values.
<% keys, values {|key| ++$key } %>
This will store an incremented version of keys on incremented.
<% incremented = keys {|key| ++$key} %>
Support for key pairs on blocks and iterating overs methods and Active Records are not implemented yet.
If you like Sintags and think that can a write great Sintags guide, we really need your help. Open a ticket on the Trac notifying the core team that you want to overtake that task and start writing great user centered narrative documentation for others to easily get on Sintags.
Please report any issue into the Trac site.
Enjoy
1 to 1 of 1