Hi,
I'm trying out Mustache translating some erb files I have. I use this
idiom quite a bit to dynamically build a select with numbers:
<select name="something"><%= (0..10).map {|x| %Q{<option
value="#{x}">#{x}</option>}} %></select>
What would be the best way to move this to "the Mustache way"? Having
a method in the mustache like
def zero_to_ten
(0..10).map {|i| {:i => i}}
end
and then in the view:
<select name="something">
{{#zero_to_ten}}
<option value="{{i}}">{{i}}</option>
{{/zero_to_ten}}
Doesn't look very nice to me, cause I'd need a method for each range I
would have.
I tried making a method in the view that receives parameters but I
don't know how to call it from the view. I tried:
def range(first,last)
(first..last).map {|i| {:i => i}}
end
{{#range(0,10)}}
<option value="{{i}}">{{i}}</option>
{{/range(0,10)}}
But it doesn't work. I was wondering, in the example about the
gravatar here (
http://github.com/defunkt/mustache) how do you go about
calling the methods included in the view such as gravatar(email,
size=30)?
Thanks,
Jesus.