1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make string-keys locals assigns optional

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2665 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Nicholas Seckar 2005-10-17 15:51:07 +00:00
parent 2c64b9d127
commit cb8bb70aa7
3 changed files with 18 additions and 6 deletions

View file

@ -1,5 +1,7 @@
*1.10.0* (October 16th, 2005)
* Make string-keys locals assigns optional. Add documentation describing depreciated state [skaes@web.de]
* Improve line number detection for template errors [Nicholas Seckar]
* Update/clean up documentation (rdoc)

View file

@ -133,6 +133,12 @@ module ActionView #:nodoc:
@@cache_template_loading = false
cattr_accessor :cache_template_loading
# Specify whether local_assigns should be able to use string keys.
# Defaults to +true+. String keys are depreciated and will be removed
# shortly.
@@local_assigns_support_string_keys = true
cattr_accessor :local_assigns_support_string_keys
@@template_handlers = {}
module CompiledTemplates #:nodoc:
@ -258,6 +264,8 @@ module ActionView #:nodoc:
method_name = @@method_names[file_path || template]
evaluate_assigns
local_assigns = local_assigns.symbolize_keys if @@local_assigns_support_string_keys
send(method_name, local_assigns) do |*name|
instance_variable_get "@content_for_#{name.first || 'layout'}"
end
@ -365,10 +373,8 @@ module ActionView #:nodoc:
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
locals_code = ""
unless locals_keys.empty?
locals_code << locals_keys.inject("local_assigns = local_assigns.symbolize_keys\n") do |code, key|
code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n"
end
locals_keys.each do |key|
locals_code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n"
end
"def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"

View file

@ -77,12 +77,16 @@ class TestController < ActionController::Base
def accessing_local_assigns_in_inline_template
name = params[:local_name]
render :inline => "<%= 'Goodbye, ' + local_name %>", :locals => { :local_name => name }
render :inline => "<%= 'Goodbye, ' + local_name %>",
:locals => { :local_name => name }
end
def accessing_local_assigns_in_inline_template_with_string_keys
name = params[:local_name]
render :inline => "<%= 'Goodbye, ' + local_name %>", :locals => { "local_name" => name }
ActionView::Base.local_assigns_support_string_keys = true
render :inline => "<%= 'Goodbye, ' + local_name %>",
:locals => { "local_name" => name }
ActionView::Base.local_assigns_support_string_keys = false
end
def rescue_action(e) raise end