From f3aa7c1e64b2f872215f860cecbe7feca3e793d7 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 29 Jun 2006 20:14:33 +0000 Subject: r4730@asus: jeremy | 2006-06-29 13:13:38 -0700 Avoid naming collision among compiled view methods. Back out AM workaround. References #5520. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4512 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionmailer/CHANGELOG | 2 +- actionmailer/lib/action_mailer/base.rb | 6 ++--- actionmailer/test/mail_render_test.rb | 2 +- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/base.rb | 44 ++++++++++++---------------------- 5 files changed, 22 insertions(+), 34 deletions(-) diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index f22880299a..cbf3628950 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -1,6 +1,6 @@ *SVN* -* Resolve conflict among mailer actions with the same name. #5520 [ssinghi@kreeti.com] +* Resolve action naming collision. #5520 [ssinghi@kreeti.com] * ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Marcel Molina Jr.] diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index a84da1866d..81f240e035 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -353,7 +353,7 @@ module ActionMailer #:nodoc: content_type = md.captures[1].gsub('.', '/') @parts << Part.new(:content_type => content_type, :disposition => "inline", :charset => charset, - :body => render_message("#{mailer_name}/#{template_name}", @body)) + :body => render_message(template_name, @body)) end unless @parts.empty? @content_type = "multipart/alternative" @@ -367,7 +367,7 @@ module ActionMailer #:nodoc: # it. template_exists = @parts.empty? template_exists ||= Dir.glob("#{template_path}/#{@template}.*").any? { |i| File.basename(i).split(".").length == 2 } - @body = render_message("#{mailer_name}/#{@template}", @body) if template_exists + @body = render_message(@template, @body) if template_exists # Finally, if there are other message parts and a textual body exists, # we shift it onto the front of the parts and set the body to nil (so @@ -432,7 +432,7 @@ module ActionMailer #:nodoc: end def initialize_template_class(assigns) - ActionView::Base.new(template_root, assigns, self) + ActionView::Base.new(template_path, assigns, self) end def sort_parts(parts, order = []) diff --git a/actionmailer/test/mail_render_test.rb b/actionmailer/test/mail_render_test.rb index 642e15fe60..11ac4d1ed8 100644 --- a/actionmailer/test/mail_render_test.rb +++ b/actionmailer/test/mail_render_test.rb @@ -15,7 +15,7 @@ class RenderMailer < ActionMailer::Base recipients recipient subject "using helpers" from "tester@example.com" - body render(:file => "#{mailer_name}/signed_up", :body => { :recipient => recipient }) + body render(:file => "signed_up", :body => { :recipient => recipient }) end def initialize_defaults(method_name) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 4a1f42d72f..dfae63ee79 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Avoid naming collision among compiled view methods. [Jeremy Kemper] + * Fix CGI extensions when they expect string but get nil in Windows. Closes #5276 [mislav@nippur.irb.hr] * Determine the correct template_root for deeply nested components. #2841 [s.brink@web.de] diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 2ee4227a6f..1aba054e6d 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -307,7 +307,7 @@ module ActionView #:nodoc: # Get the method name for this template and run it method_name = @@method_names[file_path || template] - evaluate_assigns + evaluate_assigns local_assigns = local_assigns.symbolize_keys if @@local_assigns_support_string_keys @@ -335,14 +335,14 @@ module ActionView #:nodoc: def builder_template_exists?(template_path)#:nodoc: template_exists?(template_path, :rxml) end - + def javascript_template_exists?(template_path)#:nodoc: template_exists?(template_path, :rjs) end def file_exists?(template_path)#:nodoc: template_file_name, template_file_extension = path_and_extension(template_path) - + if template_file_extension template_exists?(template_file_name, template_file_extension) else @@ -372,11 +372,11 @@ module ActionView #:nodoc: template_path_without_extension = template_path.sub(/\.(\w+)$/, '') [ template_path_without_extension, $1 ] end - + def cached_template_extension(template_path) @@cache_template_extensions && @@cached_template_extension[template_path] - end - + end + def find_template_extension_for(template_path) if match = delegate_template_exists?(template_path) match.first.to_sym @@ -384,7 +384,7 @@ module ActionView #:nodoc: elsif builder_template_exists?(template_path): :rxml elsif javascript_template_exists?(template_path): :rjs else - raise ActionViewError, "No rhtml, rxml, rjs or delegate template found for #{template_path}" + raise ActionViewError, "No rhtml, rxml, rjs or delegate template found for #{template_path} in #{@base_path}" end end @@ -414,7 +414,7 @@ module ActionView #:nodoc: local_assigns.empty? || ((args = @@template_args[render_symbol]) && local_assigns.all? { |k,_| args.has_key?(k) }) end - + # Check whether compilation is necessary. # Compile if the inline template or file has not been compiled yet. # Or if local_assigns has a new key, which isn't supported by the compiled code yet. @@ -468,35 +468,21 @@ module ActionView #:nodoc: %w(rxml rjs) end - def assign_method_name(extension, template, file_name) - method_name = '_run_' - method_name << "#{extension}_" if extension + def compiled_method_name(extension, template, file_name) + ['_run', extension, compiled_method_name_file_path_segment(file_name)].compact.join('_') + end + def compiled_method_name_file_path_segment(file_name) if file_name - file_path = File.expand_path(file_name) - base_path = File.expand_path(@base_path) - - i = file_path.index(base_path) - l = base_path.length - - method_name_file_part = i ? file_path[i+l+1,file_path.length-l-1] : file_path.clone - method_name_file_part.sub!(/\.r(html|xml|js)$/,'') - method_name_file_part.tr!('/:-', '_') - method_name_file_part.gsub!(/[^a-zA-Z0-9_]/){|s| s[0].to_s} - - method_name += method_name_file_part + File.expand_path(file_name).gsub(/[^a-zA-Z0-9_]/, '_') else - @@inline_template_count += 1 - method_name << @@inline_template_count.to_s + (@@inline_template_count += 1).to_s end - - @@method_names[file_name || template] = method_name.intern end def compile_template(extension, template, file_name, local_assigns) method_key = file_name || template - - render_symbol = @@method_names[method_key] || assign_method_name(extension, template, file_name) + render_symbol = @@method_names[method_key] ||= compiled_method_name(extension, template, file_name) render_source = create_template_source(extension, template, render_symbol, local_assigns.keys) line_offset = @@template_args[render_symbol].size -- cgit v1.2.3