diff options
Diffstat (limited to 'actionpack/lib/abstract_controller')
-rw-r--r-- | actionpack/lib/abstract_controller/localized_cache.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/abstract_controller/rendering.rb | 37 | ||||
-rw-r--r-- | actionpack/lib/abstract_controller/translation.rb | 13 |
3 files changed, 47 insertions, 5 deletions
diff --git a/actionpack/lib/abstract_controller/localized_cache.rb b/actionpack/lib/abstract_controller/localized_cache.rb index bf648af60a..5e3efa002c 100644 --- a/actionpack/lib/abstract_controller/localized_cache.rb +++ b/actionpack/lib/abstract_controller/localized_cache.rb @@ -34,7 +34,7 @@ module AbstractController end end - def render(options) + def render(*args) Thread.current[:format_locale_key] = HashKey.get(self.class, formats, I18n.locale) super end diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index d57136dbb8..a168b1b4c5 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -40,12 +40,13 @@ module AbstractController # Mostly abstracts the fact that calling render twice is a DoubleRenderError. # Delegates render_to_body and sticks the result in self.response_body. - def render(*args) + def render(*args, &block) if response_body - raise AbstractController::DoubleRenderError, "OMG" + raise AbstractController::DoubleRenderError end - self.response_body = render_to_body(*args) + options = _normalize_options(*args, &block) + self.response_body = render_to_body(options) end # Raw rendering of a template to a Rack-compatible body. @@ -69,7 +70,8 @@ module AbstractController # render_to_body into a String. # # :api: plugin - def render_to_string(options = {}) + def render_to_string(*args) + options = _normalize_options(*args) AbstractController::Rendering.body_to_s(render_to_body(options)) end @@ -96,6 +98,11 @@ module AbstractController _view_paths end + # The prefix used in render "foo" shortcuts. + def _prefix + controller_path + end + # Return a string representation of a Rack-compatible response body. def self.body_to_s(body) if body.respond_to?(:to_str) @@ -110,6 +117,28 @@ module AbstractController private + # Normalize options, by converting render "foo" to render :template => "prefix/foo" + # and render "/foo" to render :file => "/foo". + def _normalize_options(action=nil, options={}) + case action + when Hash + options, action = action, nil + when String, Symbol + action = action.to_s + case action.index("/") + when NilClass + options[:_prefix] = _prefix + options[:_template_name] = action + when 0 + options[:file] = action + else + options[:template] = action + end + end + + options + end + # Take in a set of options and determine the template to render # # ==== Options diff --git a/actionpack/lib/abstract_controller/translation.rb b/actionpack/lib/abstract_controller/translation.rb new file mode 100644 index 0000000000..6d68cf4944 --- /dev/null +++ b/actionpack/lib/abstract_controller/translation.rb @@ -0,0 +1,13 @@ +module AbstractController + module Translation + def translate(*args) + I18n.translate(*args) + end + alias :t :translate + + def localize(*args) + I18n.localize(*args) + end + alias :l :localize + end +end
\ No newline at end of file |