Skip to content

Commit

Permalink
Expose Haml configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
lautis committed Nov 6, 2012
1 parent 79d6af0 commit 74b1eca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ And then execute:

$ bundle

Hamstache compilation can be configured using [Haml options](http://haml.info/docs/yardoc/Haml/Options.html). For example:

HoganAssets::Config.configure do |config|
config.haml_options[:ugly] = true
end

## Configuration

### Lambda Support
Expand Down
7 changes: 6 additions & 1 deletion lib/hogan_assets/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ module HoganAssets
# config.lambda_support = false
# config.path_prefix = 'templates'
# config.template_extensions = ['mustache', 'hamstache']
# config.haml_options[:ugly] = true
# end
#
module Config
extend self

attr_writer :lambda_support, :path_prefix, :template_extensions, :template_namespace
attr_writer :lambda_support, :path_prefix, :template_extensions, :template_namespace, :haml_options

def configure
yield self
Expand Down Expand Up @@ -43,5 +44,9 @@ def template_extensions
['mustache']
end
end

def haml_options
@haml_options ||= {}
end
end
end
2 changes: 1 addition & 1 deletion lib/hogan_assets/tilt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def evaluate(scope, locals, &block)

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?
Haml::Engine.new(data, @options).render
Haml::Engine.new(data, HoganAssets::Config.haml_options.merge(@options)).render
else
data
end
Expand Down
9 changes: 9 additions & 0 deletions test/hogan_assets/tilt_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,14 @@ def test_template_namespace
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

def test_haml_options
HoganAssets::Config.configure do |config|
config.haml_options[:ugly] = true
end
scope = make_scope '/myapp/app/assets/javascripts', 'path/to/template.hamstache'
template = HoganAssets::Tilt.new(scope.s_path) { "%p\n This is {{mustache}}" }
assert_match /\"This is "/, template.render(scope, {})
end
end
end

0 comments on commit 74b1eca

Please sign in to comment.