lib/rabl/partials.rb in rabl-0.6.5 vs lib/rabl/partials.rb in rabl-0.6.6

- old
+ new

@@ -32,11 +32,12 @@ def fetch_source(file, options={}) Rabl.source_cache(file, options[:view_path]) do file_path = if defined? Padrino fetch_padrino_source(file, options) elsif defined?(Rails) && context_scope - fetch_rails_source(file, options) + view_path = Array(options[:view_path] || context_scope.view_paths.to_a) + fetch_rails_source(file, options) || fetch_manual_template(view_path, file) elsif defined? Sinatra fetch_sinatra_source(file, options) end raise "Cannot find rabl template '#{file}' within registered view paths!" unless File.exist?(file_path.to_s) @@ -57,19 +58,21 @@ # Returns the rabl template path for Rails, including special lookups for Rails 2 and 3 def fetch_rails_source(file, options={}) # use Rails template resolution mechanism if possible (find_template) source_format = request_format if defined?(request_format) - view_path = Array(options[:view_path] || context_scope.view_paths.to_a) if source_format && context_scope.respond_to?(:lookup_context) # Rails 3 - lookup_proc = lambda { |partial| context_scope.lookup_context.find_template(file, [], partial) } + lookup_proc = lambda { |partial| + if context_scope.lookup_context.method(:find).parameters.count < 5 + context_scope.lookup_context.find(file, [], partial) + else + context_scope.lookup_context.find(file, [], partial, [], {:formats => [:json]}) + end } template = lookup_proc.call(false) rescue lookup_proc.call(true) template.identifier if template elsif source_format && context_scope.respond_to?(:view_paths) # Rails 2 template = context_scope.view_paths.find_template(file, source_format, false) template.filename if template - else # manual file lookup - fetch_manual_template(view_path, file) end end # Returns the rabl template path for sinatra views using configured views def fetch_sinatra_source(file, options={})