From 61a459616abbd839e4c214659c5e0977253a740d Mon Sep 17 00:00:00 2001 From: Caio Chassot Date: Mon, 8 Sep 2008 00:17:12 -0300 Subject: [PATCH] implement inheritable templates for actionpack. rails ticket #948 --- actionmailer/lib/action_mailer/base.rb | 5 +++++ actionpack/lib/action_controller/base.rb | 21 ++++++++++++++------- actionpack/lib/action_view/partials.rb | 12 ++++-------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 96e514e..1b8f59f 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -569,6 +569,11 @@ module ActionMailer #:nodoc: !@template.send(:_exempt_from_layout?, default_template_name) end + # for ActionView compatibility. Inheritable templates currently not supported in ActionMailer + def find_inherited_template(template_basename) + "#{self.class.mailer_name}/#{template_basename}" + end + def template_root self.class.template_root end diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 670a049..5bc545b 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -1238,13 +1238,20 @@ module ActionController #:nodoc: end def default_template_name(action_name = self.action_name) - if action_name - action_name = action_name.to_s - if action_name.include?('/') && template_path_includes_controller?(action_name) - action_name = strip_out_controller(action_name) - end - end - "#{self.class.controller_path}/#{action_name}" + return "" unless action_name + action_name = action_name.to_s + action_name = strip_out_controller(action_name) if action_name.include?('/') && template_path_includes_controller?(action_name) + find_inherited_template(action_name) + end + + def find_inherited_template(template_basename) + k = self.class + begin + template_name = "#{k.controller_path}/#{template_basename}" + first_template_name ||= template_name + return template_name if template_exists? template_name + end while (k = k.superclass) < ActionController::Base + first_template_name end def strip_out_controller(path) diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index 373bb92..42c3439 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -188,15 +188,11 @@ module ActionView end def _pick_partial_template(partial_path) #:nodoc: - if partial_path.include?('/') - path = File.join(File.dirname(partial_path), "_#{File.basename(partial_path)}") - elsif controller - path = "#{controller.class.controller_path}/_#{partial_path}" - else - path = "_#{partial_path}" + _pick_template case + when partial_path.include?('/') then File.join(File.dirname(partial_path), "_#{File.basename(partial_path)}") + when respond_to?(:controller) then controller.send(:find_inherited_template, "_#{partial_path}") + else "_#{partial_path}" end - - _pick_template(path) end memoize :_pick_partial_template end -- 1.6.0.1