aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vendor/plugins/action_mailer_layouts/CHANGELOG9
-rw-r--r--vendor/plugins/action_mailer_layouts/READ_ME30
-rw-r--r--vendor/plugins/action_mailer_layouts/init.rb7
-rw-r--r--vendor/plugins/action_mailer_layouts/plugin.rb32
4 files changed, 78 insertions, 0 deletions
diff --git a/vendor/plugins/action_mailer_layouts/CHANGELOG b/vendor/plugins/action_mailer_layouts/CHANGELOG
new file mode 100644
index 000000000..077d78f78
--- /dev/null
+++ b/vendor/plugins/action_mailer_layouts/CHANGELOG
@@ -0,0 +1,9 @@
+2007-11-27
+* Now supports helpers defined in the mailer class. Thanks to Marshall Roch.
+
+2007-24-07
+* Now requires actionmailer-1.3.3.
+
+2007-05-07
+* No longer have to specify a :layout. The layout name is now inferred from the mailer class name. Thanks to Peter Boctor.
+* Helper methods are now available to action mailer layouts. Thanks to Peter Boctor. \ No newline at end of file
diff --git a/vendor/plugins/action_mailer_layouts/READ_ME b/vendor/plugins/action_mailer_layouts/READ_ME
new file mode 100644
index 000000000..bb33c8bdf
--- /dev/null
+++ b/vendor/plugins/action_mailer_layouts/READ_ME
@@ -0,0 +1,30 @@
+A plugin to enable layouts for ActionMailer templates.
+
+Adds a new 'layout' property to the ActionMailer::Base class. Specify the name
+of the layout you want to use. The plugin will look in app/views/layouts for your
+layout. If no layout is specified, the plugin will look for a layout that matches
+the name of your mailer class.
+
+For example:
+
+If your mailer class is called UserNotifier and you are rendering the activation.rhtml
+template, then the plugin will attempt to load the user_notifier.rhtml layout. If you are
+rendering the activation.text.html.rhtml template, the plugin will look for the
+user_notifier.text.html.rhtml layout. In other words, the plugin attempts to load the
+layout named after the your ActionMailer class.
+
+You can overload this behavior by setting the layout property of your mailer:
+
+class UserNotfier < ActionMailer::Base
+ def activation(user)
+ @recipients = user.email
+ @from = 'you@domain.com'
+ @sent_on = Time.now
+ @subject = 'Activate your account!'
+ @layout = :email
+ end
+end
+
+This arrangement will cause the plugin to render the content in
+views/user_notifier/activation.text.html.rhtml in the views/layouts/email.text.html.rhtml
+layout. \ No newline at end of file
diff --git a/vendor/plugins/action_mailer_layouts/init.rb b/vendor/plugins/action_mailer_layouts/init.rb
new file mode 100644
index 000000000..00cfa8fe1
--- /dev/null
+++ b/vendor/plugins/action_mailer_layouts/init.rb
@@ -0,0 +1,7 @@
+begin
+ load(File.join(File.dirname(__FILE__), 'plugin.rb'))
+ ActionController::Base.logger.fatal '** Loaded layouts plugin for ActionMailer'
+rescue Exception => e
+ puts e.inspect
+ ActionController::Base.logger.fatal e if ActionController::Base.logger
+end \ No newline at end of file
diff --git a/vendor/plugins/action_mailer_layouts/plugin.rb b/vendor/plugins/action_mailer_layouts/plugin.rb
new file mode 100644
index 000000000..08ae0fafd
--- /dev/null
+++ b/vendor/plugins/action_mailer_layouts/plugin.rb
@@ -0,0 +1,32 @@
+module ActionMailer
+ class Base
+
+ # Specify the layout name
+ adv_attr_accessor :layout
+
+ alias_method :render_message_without_layouts, :render_message
+
+ def render_message(method_name, body)
+ layout = @layout ? @layout.to_s : self.class.to_s.underscore
+ md = /^([^\.]+)\.([^\.]+\.[^\.]+)\.(rhtml|rxml)$/.match(method_name)
+ layout << ".#{md.captures[1]}" if md && md.captures[1]
+ layout << ".rhtml"
+ if File.exists?(File.join(layouts_path, layout))
+ body[:content_for_layout] = render_message_without_layouts(method_name, body)
+ initialize_layout_template_class(body).render(:file => layout)
+ else
+ render_message_without_layouts(method_name, body)
+ end
+ end
+
+ def initialize_layout_template_class(assigns)
+ returning(template = ActionView::Base.new(layouts_path, assigns, self)) do
+ template.extend self.class.master_helper_module
+ end
+ end
+
+ def layouts_path
+ File.join(template_root, 'layouts')
+ end
+ end
+end \ No newline at end of file