Skip to content
This repository
Browse code

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...
commit cb8bb70aa7fa100ea04b8de39fa5fcb99271758d 1 parent 2c64b9d
Nicholas Seckar seckar authored
2  actionpack/CHANGELOG
... ... @@ -1,5 +1,7 @@
1 1 *1.10.0* (October 16th, 2005)
2 2
  3 +* Make string-keys locals assigns optional. Add documentation describing depreciated state [skaes@web.de]
  4 +
3 5 * Improve line number detection for template errors [Nicholas Seckar]
4 6
5 7 * Update/clean up documentation (rdoc)
14 actionpack/lib/action_view/base.rb
@@ -133,6 +133,12 @@ class Base
133 133 @@cache_template_loading = false
134 134 cattr_accessor :cache_template_loading
135 135
  136 + # Specify whether local_assigns should be able to use string keys.
  137 + # Defaults to +true+. String keys are depreciated and will be removed
  138 + # shortly.
  139 + @@local_assigns_support_string_keys = true
  140 + cattr_accessor :local_assigns_support_string_keys
  141 +
136 142 @@template_handlers = {}
137 143
138 144 module CompiledTemplates #:nodoc:
@@ -258,6 +264,8 @@ def compile_and_render_template(extension, template = nil, file_path = nil, loca
258 264 method_name = @@method_names[file_path || template]
259 265 evaluate_assigns
260 266
  267 + local_assigns = local_assigns.symbolize_keys if @@local_assigns_support_string_keys
  268 +
261 269 send(method_name, local_assigns) do |*name|
262 270 instance_variable_get "@content_for_#{name.first || 'layout'}"
263 271 end
@@ -365,10 +373,8 @@ def create_template_source(extension, template, render_symbol, locals)
365 373 @@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
366 374
367 375 locals_code = ""
368   - unless locals_keys.empty?
369   - locals_code << locals_keys.inject("local_assigns = local_assigns.symbolize_keys\n") do |code, key|
370   - code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n"
371   - end
  376 + locals_keys.each do |key|
  377 + locals_code << "#{key} = local_assigns[:#{key}] if local_assigns.has_key?(:#{key})\n"
372 378 end
373 379
374 380 "def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
8 actionpack/test/controller/render_test.rb
@@ -77,12 +77,16 @@ def accessing_params_in_template
77 77
78 78 def accessing_local_assigns_in_inline_template
79 79 name = params[:local_name]
80   - render :inline => "<%= 'Goodbye, ' + local_name %>", :locals => { :local_name => name }
  80 + render :inline => "<%= 'Goodbye, ' + local_name %>",
  81 + :locals => { :local_name => name }
81 82 end
82 83
83 84 def accessing_local_assigns_in_inline_template_with_string_keys
84 85 name = params[:local_name]
85   - render :inline => "<%= 'Goodbye, ' + local_name %>", :locals => { "local_name" => name }
  86 + ActionView::Base.local_assigns_support_string_keys = true
  87 + render :inline => "<%= 'Goodbye, ' + local_name %>",
  88 + :locals => { "local_name" => name }
  89 + ActionView::Base.local_assigns_support_string_keys = false
86 90 end
87 91
88 92 def rescue_action(e) raise end

0 comments on commit cb8bb70

Please sign in to comment.
Something went wrong with that request. Please try again.