Skip to content

Instantly share code, notes, and snippets.

@vgdub
Created May 27, 2014 18:53
Show Gist options
  • Save vgdub/ae37669fc6f587223a61 to your computer and use it in GitHub Desktop.
Save vgdub/ae37669fc6f587223a61 to your computer and use it in GitHub Desktop.
template_cache_rails_assets_angular.js.erb
'use strict';
angular.module('templates', []).run([ '$templateCache', function($templateCache) {
<%
environment.context_class.instance_eval { include ActionView::Helpers::JavaScriptHelper }
app_root = File.expand_path('../', __FILE__)
html_templates = File.join(app_root, %w{templates ** ** *.html })
templates = Dir.glob(html_templates)
templates.each do |f|
depend_on(f)
key = f.gsub(%r(^#{app_root}/templates/),'').split('.').first
content = environment.find_asset(f).body
%>
$templateCache.put("<%= key %>.html", "<%= escape_javascript(content) %>" );
<% end %>
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment