Skip to content

Commit

Permalink
Fix vocabulary, find_view_xxx instead of find_template_xxx
Browse files Browse the repository at this point in the history
  • Loading branch information
blambeau committed Jun 14, 2012
1 parent 963c145 commit 38de911
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/sinatra/base.rb
Expand Up @@ -664,25 +664,27 @@ def find_template(views, name, engine)
end
end

# Infers the Tilt engine to use for `template`, either a Symbol denoting a
# view name or a String denoting a file path or extension. Returns engine
# as a Tilt template class. Raises a runtime error if no engine can be
# found.
def find_template_engine(template, greedy)
if Symbol===template
# Infers the Tilt engine to use for `view`, either a Symbol denoting a
# view name or a String denoting a file path or file extension. Returns
# the engine as a Tilt template class. Raises a runtime error if no engine
# can be found.
def find_view_engine(view, greedy)
if Symbol===view
raise NotImplementedError
else
engine = Tilt[template.to_s]
raise "Template engine not found: #{template}" if engine.nil?
engine = Tilt[view.to_s]
raise "Template engine not found: #{view}" if engine.nil?
engine
end
end

# Infers `template`'s location as a `[path, line]` pair.
def find_template_location(template, greedy)
# Infers the location of `view` location as a `[path, line]` pair. `view` is
# always a Symbol denoting a view name. `greedy` contains what we already know
# about the view and is guaranteed to contain the infered engine.
def find_view_location(view, greedy)
engine, views, eat_errors = greedy.values_at(:engine, :views, :eat_errors)
found, path, @preferred_extension = false, nil, engine.to_s
find_template(views, template, engine) do |file|
find_template(views, view, engine) do |file|
path ||= file # keep the initial path rather than the last one
if found = File.exists?(file)
path = file
Expand Down Expand Up @@ -762,17 +764,17 @@ def tilt_compile(view, greedy={})
body = view[:body]
engine.new(path, line, options, &body)
when Array
greedy[:engine] = find_template_engine(view.first.to_s, greedy)
greedy[:engine] = find_view_engine(view.first.to_s, greedy)
tilt_compile(view.last, greedy)
when Symbol
greedy[:engine] ||= find_template_engine(view, greedy)
greedy[:engine] ||= find_view_engine(view, greedy)
body, path, line = settings.templates[view]
if body
body = body.call if body.respond_to?(:call)
greedy[:body] = Proc.new{ body }
greedy[:location] = [path, line]
else
greedy[:location] = find_template_location(view, greedy)
greedy[:location] = find_view_location(view, greedy)
end
tilt_compile(greedy)
when Proc
Expand All @@ -781,7 +783,7 @@ def tilt_compile(view, greedy={})
when String
tilt_compile(Proc.new{ view }, greedy)
when Path
greedy[:engine] ||= find_template_engine(view.to_s, greedy)
greedy[:engine] ||= find_view_engine(view.to_s, greedy)
greedy[:location] = [view.to_s, 1]
tilt_compile(greedy)
else
Expand Down

0 comments on commit 38de911

Please sign in to comment.