Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
Commits on Sep 10, 2012
@adamstrickland adamstrickland add custom template namespace support c78ddd0
@leshill Merge pull request #12 from adamstrickland/master
Adding template_namespace support (similar to handlebars_assets)
ccfc03d
Showing with 23 additions and 3 deletions.
  1. +5 −1 lib/hogan_assets/config.rb
  2. +3 −2 lib/hogan_assets/tilt.rb
  3. +15 −0 test/hogan_assets/tilt_test.rb
View
6 lib/hogan_assets/config.rb
@@ -14,7 +14,7 @@ module HoganAssets
module Config
extend self
- attr_writer :lambda_support, :path_prefix, :template_extensions
+ attr_writer :lambda_support, :path_prefix, :template_extensions, :template_namespace
def configure
yield self
@@ -32,6 +32,10 @@ def path_prefix
@path_prefix ||= 'templates'
end
+ def template_namespace
+ @template_namespace ||= 'HoganTemplates'
+ end
+
def template_extensions
@template_extensions ||= if haml_available?
['mustache', 'hamstache']
View
5 lib/hogan_assets/tilt.rb
@@ -12,6 +12,7 @@ def initialize_engine
def evaluate(scope, locals, &block)
template_path = TemplatePath.new scope
+ template_namespace = HoganAssets::Config.template_namespace
text = if template_path.is_hamstache?
raise "Unable to complile #{template_path.full_path} because haml is not available. Did you add the haml gem?" unless HoganAssets::Config.haml_available?
@@ -26,8 +27,8 @@ def evaluate(scope, locals, &block)
# Only emit the source template if we are using lambdas
text = '' unless HoganAssets::Config.lambda_support?
<<-TEMPLATE
- this.HoganTemplates || (this.HoganTemplates = {});
- this.HoganTemplates[#{template_path.name}] = new Hogan.Template(#{compiled_template}, #{text.inspect}, Hogan, {});
+ this.#{template_namespace} || (this.#{template_namespace} = {});
+ this.#{template_namespace}[#{template_path.name}] = new Hogan.Template(#{compiled_template}, #{text.inspect}, Hogan, {});
TEMPLATE
end
View
15 test/hogan_assets/tilt_test.rb
@@ -75,5 +75,20 @@ def test_path_prefix
this.HoganTemplates[\"template\"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||\"\");t.b(\"This is \");t.b(t.v(t.f(\"mustache\",c,p,0)));return t.fl(); },partials: {}, subs: { }}, "", Hogan, {});
END_EXPECTED
end
+
+ def test_template_namespace
+ HoganAssets::Config.configure do |config|
+ config.template_namespace = 'JST'
+ end
+
+ scope = make_scope '/myapp/app/assets/javascripts', 'path/to/template.mustache'
+
+ template = HoganAssets::Tilt.new(scope.s_path) { "This is {{mustache}}" }
+
+ assert_equal <<-END_EXPECTED, template.render(scope, {})
+ this.JST || (this.JST = {});
+ this.JST[\"path/to/template\"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||\"\");t.b(\"This is \");t.b(t.v(t.f(\"mustache\",c,p,0)));return t.fl(); },partials: {}, subs: { }}, "", Hogan, {});
+ END_EXPECTED
+ end
end
end

No commit comments for this range

Something went wrong with that request. Please try again.