allow jammit to serve up our handlebars templates, making them cacheable! added bonus: changing a handlebars template now doesn't involve re-running rspec to regenerate them. zing.

This commit is contained in:
danielgrippi 2012-02-04 15:50:36 -08:00
parent d1fbf7b55c
commit 39ff47150b
13 changed files with 31 additions and 8 deletions

View file

@ -3,9 +3,3 @@
- template_name = File.basename(template, ".jst").gsub("_","-")
%script{:id => "#{template_name}-template", :type => 'text/template'}
!= File.read(templates_dir.join(template))
- #don't tell my mom I did this, okay?
- Dir[templates_dir.to_s + "/*.handlebars"].each do |template|
- template_name = File.basename(template, ".handlebars").gsub("_","-")
%script{:id => "#{template_name}-template", :type => 'text/template'}
!= File.read(templates_dir.join(template))

View file

@ -82,7 +82,8 @@
= jquery_include_tag
- unless @landing_page
= include_javascripts :main
= include_javascripts :main, :templates
:javascript
Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale).to_json}, "#{I18n.locale}");
Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}";

View file

@ -2,9 +2,17 @@ package_assets: on
embed_assets: datauri
compress_assets: on
gzip_assets: off
template_function: off
template_extension: 'handlebars'
javascripts:
jquery:
- public/javascripts/vendor/jquery-1.7.1.min.js
templates:
- public/javascripts/app/templates/*.handlebars
main:
- public/javascripts/vendor/underscore.js
- public/javascripts/vendor/backbone.js

7
config/assets_test.yml Normal file
View file

@ -0,0 +1,7 @@
package_assets: on
template_function: off
template_extension: 'handlebars'
javascripts:
app:
- public/javascripts/app/templates/*

View file

@ -30,7 +30,7 @@ app.views.Base = Backbone.View.extend({
this.template = _.template(templateHTML);
} else {
window.templateCache = window.templateCache || {}
templateHTML = $("#" + this.templateName + "-template").html(); //don't forget to regenerate your jasmine fixtures ;-)
templateHTML = JST[this.templateName];
this.template = templateCache[this.templateName] = templateCache[this.templateName] || Handlebars.compile(templateHTML);
}

View file

@ -11,6 +11,9 @@
# - dist/**/*.js
#
src_files:
# load up our outputted templates, bound to window.JST
- public/assets/app.js
- public/javascripts/vendor/underscore.js
- public/javascripts/vendor/jquery-1.7.1.min.js
- public/javascripts/vendor/jquery-ui-1.8.9.custom.min.js
@ -59,6 +62,7 @@ src_files:
- public/javascripts/aspects-dropdown.js
- public/javascripts/content-updater.js
- public/javascripts/tag-followings.js
# stylesheets
#
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.

View file

@ -0,0 +1,9 @@
require 'jammit'
module Jasmine
class Config
Jammit.reload!
Jammit.package!({ :config_path => Rails.root.join("config", "assets_test.yml")})
end
end