Permalink
Browse files

Add the possibility to configure options that are passed to Haml::Eng…

…ine when evalutating HAML template.

Options can be configured in two different ways:

* Application-wide, using set_option :haml
  e.g.: set_option :haml, :format      => :haml4,
                          :escape_html => true

* By passing options directly to the `haml` helper
  e.g.: haml '%strong Hello World', :options => {:format => :html4}

Note that if you use both way, options will be merged.
  • Loading branch information...
1 parent d2ff40a commit 23999054c6242357a5a2c982301b96ec36bf2a7b @sr sr committed Apr 19, 2008
Showing with 55 additions and 1 deletion.
  1. +3 −1 lib/sinatra.rb
  2. +52 −0 test/haml_test.rb
View
@@ -604,7 +604,8 @@ def haml(content, options={})
private
def render_haml(content, options = {}, &b)
- ::Haml::Engine.new(content).render(options[:scope] || self, options[:locals] || {}, &b)
+ haml_options = (options[:options] || {}).merge(Sinatra.options.haml)
+ ::Haml::Engine.new(content, haml_options).render(options[:scope] || self, options[:locals] || {}, &b)
end
end
@@ -837,6 +838,7 @@ def self.default_options
:public => Dir.pwd + '/public',
:sessions => false,
:logging => true,
+ :haml => {}
}
end
View
@@ -178,4 +178,56 @@
end
+ describe 'Options passed to the HAML interpreter' do
+ setup do
+ Sinatra.application = nil
+ end
+
+ specify 'are empty be default' do
+
+ get '/' do
+ haml 'foo'
+ end
+
+ Haml::Engine.expects(:new).with('foo', {}).returns(stub(:render => 'foo'))
+
+ get_it '/'
+ should.be.ok
+
+ end
+
+ specify 'can be configured by passing :options to haml' do
+
+ get '/' do
+ haml 'foo', :options => {:format => :html4}
+ end
+
+ Haml::Engine.expects(:new).with('foo', {:format => :html4}).returns(stub(:render => 'foo'))
+
+ get_it '/'
+ should.be.ok
+
+ end
+
+ specify 'can be configured using set_option :haml' do
+
+ configure do
+ set_option :haml, :format => :html4,
+ :escape_html => true
+ end
+
+ get '/' do
+ haml 'foo'
+ end
+
+ Haml::Engine.expects(:new).with('foo', {:format => :html4,
+ :escape_html => true}).returns(stub(:render => 'foo'))
+
+ get_it '/'
+ should.be.ok
+
+ end
+
+ end
+
end

0 comments on commit 2399905

Please sign in to comment.