diff --git a/lib/hamlbars/template.rb b/lib/hamlbars/template.rb index f5607d5..2154fd9 100644 --- a/lib/hamlbars/template.rb +++ b/lib/hamlbars/template.rb @@ -102,7 +102,7 @@ def make(expression, options) def express(demarcation,expression,options={},&block) if block.respond_to? :call content = capture_haml(&block) - output = "#{demarcation.first}##{make(expression, options)}#{demarcation.last}#{content.strip}#{demarcation.first}/#{expression.split(' ').first}#{demarcation.last}" + output = "#{demarcation.first}##{make(expression, options)}#{demarcation.last}\n#{content.strip.gsub(/^/, ' ')}\n#{demarcation.first}/#{expression.split(' ').first}#{demarcation.last}" else output = "#{demarcation.first}#{make(expression, options)}#{demarcation.last}" end diff --git a/spec/template_spec.rb b/spec/template_spec.rb index 5088bdb..fbe4737 100644 --- a/spec/template_spec.rb +++ b/spec/template_spec.rb @@ -58,10 +58,29 @@ def to_handlebars(s) it "should render block expressions" do expect(to_handlebars("= hb 'hello' do\n world.")).to eq( - "{{#hello}}world.{{/hello}}" + "{{#hello}}\n world.\n{{/hello}}" ) end + it "should keep newlines on block expressions" do + handlebars = to_handlebars < + One +
two
+ +{{/if}} +EOF + + expect(handlebars).to eq(expected.strip) + end + it "should render expression options" do expect(to_handlebars('= hb "hello",:whom => "world"')).to eq( "{{hello whom=\"world\"}}" @@ -76,7 +95,7 @@ def to_handlebars(s) it "should render tripple-stash block expressions" do expect(to_handlebars("= hb! 'hello' do\n world.")).to eq( - "{{{#hello}}}world.{{{/hello}}}" + "{{{#hello}}}\n world.\n{{{/hello}}}" ) end @@ -92,7 +111,7 @@ def to_handlebars(s) = hb 'hello' %a{:bind => {:href => 'aController'}} EOF - expect(handlebars).to eq("{{#if a_thing_is_true}}{{hello}}\n{{/if}}") + expect(handlebars).to eq("{{#if a_thing_is_true}}\n {{hello}}\n\n{{/if}}") end it "should not mark expressions as html_safe when XSS protection is disabled" do