Skip to content

Commit 15818ce

Browse files
committed
Merge pull request #8 from chaslemley/master
Ignore trailing whitespace in templates
2 parents 1cf6edd + 13a7cf0 commit 15818ce

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/jsonify-rails/jsonify_builder.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class JsonifyBuilder < Template::Handler
1010
def compile(template)
1111
"json = ::Jsonify::Builder.new(:format => :#{jsonify_format});" +
1212
template.source +
13-
";json.compile!;"
13+
";\njson.compile!;"
1414
end
1515

1616
private
@@ -29,7 +29,7 @@ def default_format
2929
def self.call(template)
3030
"json = ::Jsonify::Builder.new(:format => :#{jsonify_format});" +
3131
template.source +
32-
";json.compile!;"
32+
";\njson.compile!;"
3333
end
3434

3535
private

spec/jsonify_builder_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
ViewTemplate.new("json.hello 'world'")
1212
end
1313

14+
let( :template_with_trailing_comment ) do
15+
ViewTemplate.new("json.hello 'world' #trailing comment")
16+
end
17+
1418
context "#{Rails.version}" do
1519
before do
1620
Rails.stub_chain(:application, :config, :jsonify_format).and_return( :plain )
@@ -25,6 +29,11 @@
2529
result.should == '{"hello":"world"}'
2630
end
2731

32+
it 'should ignore trailing comments' do
33+
result = eval( Handler.call template_with_trailing_comment )
34+
result.should == '{"hello":"world"}'
35+
end
36+
2837
describe 'when configured with ' do
2938
def expect_format(format)
3039
Jsonify::Builder.should_receive(:new).with({:format => format}).and_return( double("json").as_null_object )

0 commit comments

Comments
 (0)