That said, many client-side templating languages use different or
customizable delimiters, and support different subsets of javascript
within the templates, from full-js-interpretation all the way down to
only-top-level-properties-of-a-single-data-object, and extending haml
to deal with all of these is pretty much guaranteed to only serve a
subset of the needs programmers will have down the line.
haml itself is already a member of the school of templating languages
that provide access to the full functionality of the ruby interpreter
within the template. Adding extra delimiters means a human looking
over a templates needs to mentally parse two to three languages just
to figure out what's going on.
Is haml the way forward? Should it be re-plumbed to make adding custom
delimiters part of its public API? Should it embrace generation of
client-side templates and include first-class support for this new
family of consumers?
I don't know. So far, using haml for these purposes has been a mixed
bag. The results have been great, but the friction on the way has not
been pleasant.
On Sat, Apr 21, 2012 at 12:40 PM, Bernie <bte...@gmail.com> wrote:
> Just want to make sure I don't use time that could be spent somewheret
> else. Here's the idea:
>
> Many JS templating languages appear to use the "{{ some_content }}"
> strategy for delimiting content, and Mustache and Handlebars appear to
> be the most popular among those lang's.
>
> Since Haml appears to not have an easy way to add custom delimeters
> (parsing occurs all the way in the parser.rb file), would it make
> sense to add these "{{" delimeters directly to haml?
>
> The end result would be something like this:
>
> %table
> %tbody
> {{# each MyApp.MyArray
> %tr
> %td {{ someValue }}
> %tfoot
> %tr
> %td Some footer content
>
> Thoughts, concerns?
>
> --
> You received this message because you are subscribed to the Google Groups "Haml" group.
> To post to this group, send email to ha...@googlegroups.com.
> To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/haml?hl=en.
>
There have been a number of approaches to help make it simpler to use
haml for client-side templates. One popular implementation is hamlbars
https://github.com/jamesotron/hamlbars which provides some helper
methods, and my own academic experiments in extending haml in a
similar fashion here: https://github.com/duncanbeevers/haml-ejsThat said, many client-side templating languages use different or
customizable delimiters, and support different subsets of javascript
within the templates, from full-js-interpretation all the way down to
only-top-level-properties-of-a-single-data-object, and extending haml
to deal with all of these is pretty much guaranteed to only serve a
subset of the needs programmers will have down the line.haml itself is already a member of the school of templating languages
that provide access to the full functionality of the ruby interpreter
within the template. Adding extra delimiters means a human looking
over a templates needs to mentally parse two to three languages just
to figure out what's going on.Is haml the way forward? Should it be re-plumbed to make adding custom
delimiters part of its public API? Should it embrace generation of
client-side templates and include first-class support for this new
family of consumers?I don't know. So far, using haml for these purposes has been a mixed
bag. The results have been great, but the friction on the way has not
been pleasant.
> --
> You received this message because you are subscribed to the Google Groups
> "Haml" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/haml/-/w9UJnuQWDngJ.
At the same time it's a good idea it's a bad idea. You can already do:
%table
%tbody
-MyApp.MyArray.each
%tr
%td=some_value
%tfood
Jordan, I'm not sure I understand...isn't that just the Ruby way to do the same thing? How would that look on the client side?
--
You received this message because you are subscribed to the Google Groups "Haml" group.
To view this discussion on the web visit https://groups.google.com/d/msg/haml/-/h9M7fHBAFiUJ.
%span= username
In the current implementation, the result of compiling this would be
something like:
<span>duncan</span>
Retargeted, I imagined haml outputting something like this instead:
<span>{{username}}</span>
But I found that I still needed and wanted access to pieces of the
Ruby environment like configuration values, url-generation methods,
and markup-generating methods like link_to. Faced with the trade-off,
I elected to extend the semantics of haml to make it easy to generate
the kinds of simple expressions in wanted in my client-side templates
while continuing to express myself using the elegant style haml
brought to the Ruby in my templates.
Right now, in order to generate simple mustache conditional I have to
jump through a few hoops.
In an ideal world I'd write:
%p
{{#sunny}}
My kind of weather
But mustache ain't haml, so I have to close the block myself. However,
because of haml's indentation rules, I can't just write this:
%p
{{#sunny}}
My kind of weather
{{/sunny}}
So I have a couple of options. I can either write this:
%p
:text
{{#sunny}}
My kind of weather
{{/sunny}}
Or this:
%p
{{#sunny}}My kind of weather{{/sunny}}
I wanted haml's indentation awareness to make the loops and
conditionals in my templates feel like coffeescript, and like haml
itself, without having to give up (read, change or modify) the bits of
template I'd written that relied on Ruby.
As far as the specific sigils I introduced, I knew I wanted more
control over the generated output than I would get targeting mustache
which can do a number of different things when it encounters a sigil
like {{#, such as performing a conditional check, invoking a function,
or looping over a collection of values. Instead, I had
explicitly-specified output for the specific pieces of functionality I
wanted to allow the client-side template access to.
I never opened a pull request for this because I never believed it was
something that belonged in haml core. I feel the first approach was
likely to get bound up in painful compromises trying to effectively
translate Ruby to JavaScript/template dialect, and my approach changes
the semantics of haml in a backwards-incompatible way.