Permalink
Browse files

Make string-keys locals assigns optional

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2665 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2c64b9d commit cb8bb70aa7fa100ea04b8de39fa5fcb99271758d @seckar seckar committed Oct 17, 2005
Showing with 18 additions and 6 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +10 −4 actionpack/lib/action_view/base.rb
  3. +6 −2 actionpack/test/controller/render_test.rb
@@ -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)
@@ -133,6 +133,12 @@ class Base
@@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 @@ def compile_and_render_template(extension, template = nil, file_path = nil, loca
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 @@ def create_template_source(extension, template, render_symbol, locals)
@@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"
@@ -77,12 +77,16 @@ def accessing_params_in_template
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

0 comments on commit cb8bb70

Please sign in to comment.