aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-06-29 20:14:33 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-06-29 20:14:33 +0000
commitf3aa7c1e64b2f872215f860cecbe7feca3e793d7 (patch)
treedd0e14ac1300578d9a72f2fc6af28b06003c17c7
parent5fe64dd1a62eafc27b20b82b4b6c1139887046e3 (diff)
downloadrails-f3aa7c1e64b2f872215f860cecbe7feca3e793d7.tar.gz
rails-f3aa7c1e64b2f872215f860cecbe7feca3e793d7.tar.bz2
rails-f3aa7c1e64b2f872215f860cecbe7feca3e793d7.zip
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
-rw-r--r--actionmailer/CHANGELOG2
-rw-r--r--actionmailer/lib/action_mailer/base.rb6
-rw-r--r--actionmailer/test/mail_render_test.rb2
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/base.rb44
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