Skip to content

Commit

Permalink
Merge pull request anthonator#12 from cervinka/debug_info_to_eval
Browse files Browse the repository at this point in the history
add source filename info whe evaluating .jbuilder files
  • Loading branch information
anthonator committed Aug 26, 2014
2 parents 62f3671 + 1ac17e9 commit 50a996e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tilt/jbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def evaluate(scope, locals, &block)
if data.kind_of?(Proc)
return data.call(::Tilt::Jbuilder.new(scope))
else
eval(data, context)
file.is_a?(String) ? eval(data, context, file) : eval(data, context)
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/support/views/invalid.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.author "Anthony"
json.trigger_error_on_this_line nil.name
9 changes: 9 additions & 0 deletions spec/tilt-jbuilder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
Tilt::JbuilderTemplate.should == Tilt['test.jbuilder']
end

it "contains information about source file when error in .jbuilder file" do
template = Tilt::JbuilderTemplate.new(File.join('spec', 'support', 'views', 'invalid.jbuilder'))
begin
template.render
rescue => e
expect(e.backtrace.join).to include 'invalid.jbuilder:2' # we should see error on line 2 in file invalid.jbuilder in stacktrace
end
end

it "should evaluate the template on #render" do
template = Tilt::JbuilderTemplate.new { "json.author 'Anthony'" }
"{\"author\":\"Anthony\"}".should == template.render
Expand Down

0 comments on commit 50a996e

Please sign in to comment.