In erubis, I do the following:
<% ['reset-min-2.6.0.css', 'jquery-ui-1.7.2.custom.css',
'main.css'].each do |css| %>
<%= partial :style, { :css => css } %>
<% end %>
partial is a helper function that renders the partial, passing in the
context. I've been attempting to conceptualize the Mustache
equivalent and this is the best I could do
# layout.rb
class Main
module ViewHelpers
def partial klass, ctx={}
markup =
klass.new
ctx.each { |k,v| markup[k] = v }
markup.render
end
end
module Views
class Layout < Mustache
include ViewHelpers
def css
[ { :style => partial(Style, { :css => 'reset-
min-2.6.0.css'}) },
{ :style => partial(Style, { :css => 'jquery-
ui-1.7.2.custom.css'}) },
{ :style => partial(Style, { :css => 'main.css'}) } ]
end
end
end
end
# in layout.mustache
{{#css}}
{{{style}}}
{{/css}}
Is there a better method to accomplish what I am seeking? There is no
way to pass variables into methods from the templates correct?
Thanks,
~Paul