Skip to content

Commit

Permalink
Properly fix missing template names in backtrace.
Browse files Browse the repository at this point in the history
The tilt signature only allows template content *or* a template
filename, not both. As a result, if you read the contents of a template
before it is passed to tilt (e.g. to get the metadata out) and there's
an error in the template it will only show up as '(__TEMPLATE__)' in the
backtrace (which is confusing and unnecessary).

With this patch the signature of the tilt method is changed to include
the content and/or the filename, allowing Tilt to include the filname in
a possible backtrace.

Without patch:

 - Creating 'output'
(__TEMPLATE__):5:in `evaluate_source': undefined local variable or method `example' for #<Object:0x8bd8410> (NameError)
  from /var/lib/gems/1.9.1/gems/tilt-0.9/lib/tilt.rb:254:in `instance_eval'
...

With patch:

 - Creating 'output'
/tmp/frank/dynamic/_top.haml:5:in `evaluate_source': undefined local variable or method `example' for #<Object:0x9564470> (NameError)
  from /var/lib/gems/1.9.1/gems/tilt-0.9/lib/tilt.rb:254:in `instance_eval'
...
  • Loading branch information
sce committed Dec 29, 2010
1 parent e6b924c commit 50e59b7
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lib/frank/base.rb
Expand Up @@ -105,14 +105,14 @@ def render(path, partial = false, local_vars = nil)
# let tilt determine the template handler
# and return some template markup
if layout.nil?
tilt(page, ext, template, locals)
tilt(page, ext, template, template_path, locals)
else
layout_path = File.join(Frank.root, Frank.layouts_folder, layout)
# add layout_path to locals
raise Frank::TemplateError, "Layout not found #{layout_path}" unless File.exist? layout_path

page_content = tilt(page, ext, template, locals)
tilt(page, File.extname(layout), layout_path, locals) do
page_content = tilt(page, ext, template, template_path, locals)
tilt(page, File.extname(layout), nil, layout_path, locals) do
page_content
end
end
Expand Down Expand Up @@ -184,14 +184,9 @@ def layout_ext_or_first(layout_exts, ext)
end

# render a page using tilt and get the result template markup back
def tilt(page, ext, source, locals={}, &block)
Tilt[ext].new do
source = source.to_str if source.respond_to?(:to_str)
if source.match(/^[^\n]+$/) && File.exist?(source)
File.read(source)
else
source
end
def tilt(page, ext, source, filename, locals={}, &block)
Tilt[ext].new(filename) do
source || File.read(filename)
end.render(page, locals=locals, &block)
end

Expand Down

0 comments on commit 50e59b7

Please sign in to comment.