aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-10-07 20:48:21 +0200
committerJosé Valim <jose.valim@gmail.com>2010-10-07 21:31:31 +0200
commitc563f10f3e8083bebe32200fa065748c8bcb65c9 (patch)
treef014b8ab578bc88d9ba5847d3695584d2da733ec /actionpack/lib/action_view
parent8f9e9118e402ea2fe1eec6fcb9a2d3f0c84b3b46 (diff)
downloadrails-c563f10f3e8083bebe32200fa065748c8bcb65c9.tar.gz
rails-c563f10f3e8083bebe32200fa065748c8bcb65c9.tar.bz2
rails-c563f10f3e8083bebe32200fa065748c8bcb65c9.zip
render :template => 'foo/bar.json' now works as it should.
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/render/partials.rb14
-rw-r--r--actionpack/lib/action_view/render/rendering.rb21
-rw-r--r--actionpack/lib/action_view/template.rb4
3 files changed, 28 insertions, 11 deletions
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb
index f7bdbd6917..24d9e9ffb5 100644
--- a/actionpack/lib/action_view/render/partials.rb
+++ b/actionpack/lib/action_view/render/partials.rb
@@ -371,13 +371,15 @@ module ActionView
end
def _render_partial(options, &block) #:nodoc:
- if defined?(@renderer)
- @renderer.setup(options, block)
- else
- @renderer = PartialRenderer.new(self, options, block)
- end
+ _wrap_formats(options[:partial]) do
+ if defined?(@renderer)
+ @renderer.setup(options, block)
+ else
+ @renderer = PartialRenderer.new(self, options, block)
+ end
- @renderer.render
+ @renderer.render
+ end
end
end
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index 0771b40c37..8e599c71df 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -21,9 +21,11 @@ module ActionView
elsif options.key?(:partial)
_render_partial(options)
else
- template = _determine_template(options)
- lookup_context.freeze_formats(template.formats, true)
- _render_template(template, options[:layout], options)
+ _wrap_formats(options[:template] || options[:file]) do
+ template = _determine_template(options)
+ lookup_context.freeze_formats(template.formats, true)
+ _render_template(template, options[:layout], options)
+ end
end
when :update
update_page(&block)
@@ -32,6 +34,19 @@ module ActionView
end
end
+ # Checks if the given path contains a format and if so, change
+ # the lookup context to take this new format into account.
+ def _wrap_formats(value)
+ return yield unless value.is_a?(String)
+ @@formats_regexp ||= /\.(#{Mime::SET.symbols.join('|')})$/
+
+ if value.sub!(@@formats_regexp, "")
+ update_details(:formats => [$1.to_sym]){ yield }
+ else
+ yield
+ end
+ end
+
# Determine the template to be rendered using the given options.
def _determine_template(options) #:nodoc:
keys = (options[:locals] ||= {}).keys
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index 7e65654d0b..c15a0eb568 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -121,7 +121,7 @@ module ActionView
@method_names = {}
@locals = details[:locals] || []
@formats = Array.wrap(details[:format] || :html).map(&:to_sym)
- @virtual_path = details[:virtual_path].try(:sub, ".#{@formats.first}", "")
+ @virtual_path = details[:virtual_path]
@compiled = false
end
@@ -286,7 +286,7 @@ module ActionView
pieces = @virtual_path.split("/")
name = pieces.pop
partial = name.sub!(/^_/, "")
- view.find_template(name, pieces.join, partial || false, @locals)
+ view.find_template(name, pieces.join, partial || false, ["unlikely_local_key"])
end
def method_name