Source code using HAML:
<% Dir.glob(Rails.root.join('app','assets','templates', '*.haml')).each do |f| %> $templateCache.put("<%= File.basename(f).gsub(/\.haml$/, '') %>", <%= Haml::Engine.new(File.read(f)).render.to_json %>); <% end %>
To select all ERB templates, use
Dir.glob(Rails.root.join('app', 'assets', 'templates', '*.erb'))
To get the template name from the file name, use
File.basename(f, '.erb')
To make an ERB template, use
ERB.new(File.read(f)).result
See the documentation for #result .
Putting it all together, we get
<% Dir.glob(Rails.root.join('app','assets','templates', '*.erb')).each do |f| %> $templateCache.put("<%= File.basename(f, '.erb') %>", <%= ERB.new(File.read(f)).result.to_json %>); <% end %>
James lim
source share