lib/jeanine/renderer.rb in jeanine-0.2.0 vs lib/jeanine/renderer.rb in jeanine-0.3.0
- old
+ new
@@ -79,10 +79,20 @@
def cache
Thread.current[:tilt_cache] ||= Tilt::Cache.new
end
+ def find_template!(template)
+ Jeanine.view_paths.to_a.each do |path|
+ template_with_path = "#{path}/#{template}"
+ if File.exist?(template_with_path)
+ return template_with_path
+ end
+ end
+ raise "Template not found in view paths. Looking for #{template} in #{Jeanine.view_paths.to_a.join(', ')}"
+ end
+
def html(engine, template_name, options = {}, locals = {}, &block)
locals = options.delete(:locals) || locals || {}
layout = options[:layout]
scope = options.delete(:scope) || self
options.delete(:layout)
@@ -92,20 +102,22 @@
output = template.render(scope, locals, &block)
if layout
unless layout.include?("layouts/")
layout = "layouts/#{layout}"
end
+ layout = find_template!(layout)
options = options.merge(layout: false, scope: scope)
catch(:layout_missing) { return html(engine, layout, options, locals) { output } }
end
output
end
def compile_template(engine, template_name, options)
Tilt::Cache.new.fetch engine, template_name, options do
template = Tilt[engine]
raise "Template engine not found: #{engine}" if template.nil?
- template.new("views/#{template_name}", options)
+ template_name = find_template!(template_name)
+ template.new(template_name, options)
end
end
add :template do |template, options|
view = Jeanine::View.new