radiant-mailer_layouts-extension 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ # Mailer Layouts
2
+
3
+ This is equivalent the the `share_layouts` extension but for email messages: it extends ActionMailer to support the rendering of email messages within a radiant layout. It is deliberately minimal and does not include any notification or mailmerge functionality. Its purpose is to make that functionality possible without any assumption as to how it will be used.
4
+
5
+ You can use radius tags and `content_for` blocks in your message templates and they will work as usual provided they don't expect a request or response object.
6
+
7
+ `Share_layouts` is not required, but can be used alongside this extension.
8
+
9
+ ## Status
10
+
11
+ Newly extracted from our fork of `share_layouts`. This code has been in use for a couple of years but it's slightly revised here so bugs are possible.
12
+
13
+ ActionMailer is nasty inside and relies heavily on instance variables that we have to set from the outside, so if there are bugs they tend to be a bit obscure.
14
+
15
+ ## Installation
16
+
17
+
18
+
19
+ ## Usage
20
+
21
+ Set the layout name in your notifier class:
22
+
23
+ class UserNotifier < ActionMailer::Base
24
+ radiant_layout 'email'
25
+
26
+ or pass a proc to decide later:
27
+
28
+ radiant_layout {|m| m.choose_layout_at_runtime}
29
+
30
+ def choose_layout_at_runtime
31
+ Radiant::Config['mailer.layout'] || 'email'
32
+ end
33
+
34
+ You can also set layout for each message by calling the message_layout setter directly:
35
+
36
+ radiant_layout :default_email
37
+
38
+ def admonish(user)
39
+ subject "bad user! bad!"
40
+ recipients user.email
41
+ message_layout "angry"
42
+ ...
43
+ end
44
+
45
+ Note that the instance method will overrule the default layout name set by the class method, but it requires that class declaration has been used first to bring in the necessary machinery.
46
+
47
+ ## Copyright
48
+
49
+ William Ross for spanner, 2008-2010
50
+
51
+ Released under the same terms as radiant and/or rails.
@@ -0,0 +1,136 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "radiant-mailer_layouts-extension"
5
+ gem.summary = %Q{Mailer Layouts Extension for Radiant CMS}
6
+ gem.description = %Q{Allows the use of radiant layouts in email messages}
7
+ gem.email = "will@spanner.org"
8
+ gem.homepage = "http://github.com/spanner/radiant-mailer_layouts-extension"
9
+ gem.authors = ["spanner"]
10
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
11
+ end
12
+ rescue LoadError
13
+ puts "Jeweler (or a dependency) not available. This is only required if you plan to package mailer_layouts as a gem."
14
+ end
15
+
16
+ # In rails 1.2, plugins aren't available in the path until they're loaded.
17
+ # Check to see if the rspec plugin is installed first and require
18
+ # it if it is. If not, use the gem version.
19
+
20
+ # Determine where the RSpec plugin is by loading the boot
21
+ unless defined? RADIANT_ROOT
22
+ ENV["RAILS_ENV"] = "test"
23
+ case
24
+ when ENV["RADIANT_ENV_FILE"]
25
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
26
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
27
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
28
+ else
29
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
30
+ end
31
+ end
32
+
33
+ require 'rake'
34
+ require 'rake/rdoctask'
35
+ require 'rake/testtask'
36
+
37
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
38
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
39
+ require 'spec/rake/spectask'
40
+ require 'cucumber'
41
+ require 'cucumber/rake/task'
42
+
43
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
44
+ Object.send(:remove_const, :RADIANT_ROOT)
45
+
46
+ extension_root = File.expand_path(File.dirname(__FILE__))
47
+
48
+ task :default => :spec
49
+ task :stats => "spec:statsetup"
50
+
51
+ desc "Run all specs in spec directory"
52
+ Spec::Rake::SpecTask.new(:spec) do |t|
53
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
54
+ t.spec_files = FileList['spec/**/*_spec.rb']
55
+ end
56
+
57
+ task :features => 'spec:integration'
58
+
59
+ namespace :spec do
60
+ desc "Run all specs in spec directory with RCov"
61
+ Spec::Rake::SpecTask.new(:rcov) do |t|
62
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
63
+ t.spec_files = FileList['spec/**/*_spec.rb']
64
+ t.rcov = true
65
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
66
+ end
67
+
68
+ desc "Print Specdoc for all specs"
69
+ Spec::Rake::SpecTask.new(:doc) do |t|
70
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
71
+ t.spec_files = FileList['spec/**/*_spec.rb']
72
+ end
73
+
74
+ [:models, :controllers, :views, :helpers].each do |sub|
75
+ desc "Run the specs under spec/#{sub}"
76
+ Spec::Rake::SpecTask.new(sub) do |t|
77
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
78
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
79
+ end
80
+ end
81
+
82
+ desc "Run the Cucumber features"
83
+ Cucumber::Rake::Task.new(:integration) do |t|
84
+ t.fork = true
85
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
86
+ # t.feature_pattern = "#{extension_root}/features/**/*.feature"
87
+ t.profile = "default"
88
+ end
89
+
90
+ # Setup specs for stats
91
+ task :statsetup do
92
+ require 'code_statistics'
93
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
94
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
95
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
96
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
97
+ ::CodeStatistics::TEST_TYPES << "Model specs"
98
+ ::CodeStatistics::TEST_TYPES << "View specs"
99
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
100
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
101
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
102
+ end
103
+
104
+ namespace :db do
105
+ namespace :fixtures do
106
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
107
+ task :load => :environment do
108
+ require 'active_record/fixtures'
109
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
110
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
111
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ desc 'Generate documentation for the mailer_layouts extension.'
119
+ Rake::RDocTask.new(:rdoc) do |rdoc|
120
+ rdoc.rdoc_dir = 'rdoc'
121
+ rdoc.title = 'MailerLayoutsExtension'
122
+ rdoc.options << '--line-numbers' << '--inline-source'
123
+ rdoc.rdoc_files.include('README')
124
+ rdoc.rdoc_files.include('lib/**/*.rb')
125
+ end
126
+
127
+ # For extensions that are in transition
128
+ desc 'Test the mailer_layouts extension.'
129
+ Rake::TestTask.new(:test) do |t|
130
+ t.libs << 'lib'
131
+ t.pattern = 'test/**/*_test.rb'
132
+ t.verbose = true
133
+ end
134
+
135
+ # Load any custom rakefiles for extension
136
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,15 @@
1
+ class MessagePage < Page
2
+ display_name "Email message"
3
+ attr_accessor :mailer_vars
4
+
5
+ def find_by_url(url, live=true, clean=true)
6
+ self
7
+ end
8
+
9
+ def build_parts_from_hash!(content)
10
+ content.each do |k,v|
11
+ (part(k) || parts.build(:name => k.to_s, :filter_id => "")).content = v
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,3 @@
1
+ - ivars = {}
2
+ - instance_variables.map {|iv| ivars[iv.intern] = instance_variable_get(iv)} # stores view @variables in a hash that will later populate mailer @variables
3
+ = apply_radiant_layout( ivars ) # with the exception of @radiant_layout, which is extracted by apply_radiant_layout and not passed on
@@ -0,0 +1,3 @@
1
+ ---
2
+ en:
3
+ mailer layouts: Mailer Layouts
@@ -0,0 +1,5 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ # map.namespace :admin, :member => { :remove => :get } do |admin|
3
+ # admin.resources :mailer_layouts
4
+ # end
5
+ end
@@ -0,0 +1 @@
1
+ default: --format progress features --tags ~@proposed,~@in_progress
@@ -0,0 +1,16 @@
1
+ # Sets up the Rails environment for Cucumber
2
+ ENV["RAILS_ENV"] = "test"
3
+ # Extension root
4
+ extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
5
+ require extension_env+'.rb'
6
+
7
+ Dir.glob(File.join(RADIANT_ROOT, "features", "**", "*.rb")).each {|step| require step}
8
+
9
+ Cucumber::Rails::World.class_eval do
10
+ include Dataset
11
+ datasets_directory "#{RADIANT_ROOT}/spec/datasets"
12
+ Dataset::Resolver.default = Dataset::DirectoryResolver.new("#{RADIANT_ROOT}/spec/datasets", File.dirname(__FILE__) + '/../../spec/datasets', File.dirname(__FILE__) + '/../datasets')
13
+ self.datasets_database_dump_path = "#{Rails.root}/tmp/dataset"
14
+
15
+ # dataset :mailer_layouts
16
+ end
@@ -0,0 +1,14 @@
1
+ def path_to(page_name)
2
+ case page_name
3
+
4
+ when /the homepage/i
5
+ root_path
6
+
7
+ when /login/i
8
+ login_path
9
+ # Add more page name => path mappings here
10
+
11
+ else
12
+ raise "Can't find mapping from \"#{page_name}\" to a path."
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ module MailerHelper
2
+
3
+ def apply_radiant_layout(mailer_ivars = {})
4
+ message = MessagePage.new(:class_name => "MessagePage")
5
+ layout = mailer_ivars[:@message_layout]
6
+ layout = Layout.find_by_name(layout) unless layout.is_a? Layout
7
+ message.layout = layout
8
+ message.title = @title || @content_for_title || message.title || ''
9
+ message.build_parts_from_hash!(extract_captures)
10
+ message.mailer_vars = mailer_ivars
11
+ message.render
12
+ end
13
+
14
+ def extract_captures
15
+ variables = instance_variables.grep(/@content_for_/)
16
+ variables.inject({}) do |h, var|
17
+ var =~ /^@content_for_(.*)$/
18
+ key = $1.intern
19
+ key = :body if key == :layout
20
+ h[key] = instance_variable_get(var) unless key == :title
21
+ h
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,37 @@
1
+ module MailerLayouts
2
+ def self.included(base)
3
+ base.extend ClassMethods
4
+ base.class_eval {
5
+ adv_attr_accessor :message_layout # instance method to set individual message layout
6
+
7
+ # the radiant_layout class method will store a default in :mailer_layout_name
8
+ # during ActionMailer initialization we instantiate that and store that in an instance variable
9
+ # (having called it, if it's a proc)
10
+ # Note that individual messages you can override this by calling the instance method
11
+ # radiant_layout(Layout object)
12
+ # during message instantiation (alongside subject, recipients, etc)
13
+
14
+ def initialize_defaults_with_layout(method_name)
15
+ initialize_defaults_without_layout(method_name)
16
+ default_layout = self.class.read_inheritable_attribute :default_layout
17
+ default_layout = default_layout.call(self) if default_layout.is_a? Proc
18
+ @message_layout = Layout.find_by_name(default_layout)
19
+ end
20
+ alias_method_chain :initialize_defaults, :layout
21
+ }
22
+ end
23
+
24
+ module ClassMethods
25
+ def radiant_layout(name=nil, options={}, &block) # class method to set default radiant layout
26
+ raise ArgumentError, "A layout name or block is required!" unless name || block
27
+ write_inheritable_attribute :default_layout, name || block
28
+
29
+ # radiant_mailer is an actual layout file in app/layouts/radiant_mailer.html.haml
30
+ # but all it does is call the mailer_layout method defined in MailerHelper
31
+ # and pass to it the necessary instance variables.
32
+ layout 'radiant_mailer', options
33
+ end
34
+ end
35
+ end
36
+
37
+ ActionMailer::Base.send :include, MailerLayouts
@@ -0,0 +1,55 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :mailer_layouts do
4
+
5
+ desc "Runs the migration of the Mailer Layouts extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ MailerLayoutsExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ Rake::Task['db:schema:dump'].invoke
11
+ else
12
+ MailerLayoutsExtension.migrator.migrate
13
+ Rake::Task['db:schema:dump'].invoke
14
+ end
15
+ end
16
+
17
+ desc "Copies public assets of the Mailer Layouts to the instance public/ directory."
18
+ task :update => :environment do
19
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
20
+ puts "Copying assets from MailerLayoutsExtension"
21
+ Dir[MailerLayoutsExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
22
+ path = file.sub(MailerLayoutsExtension.root, '')
23
+ directory = File.dirname(path)
24
+ mkdir_p RAILS_ROOT + directory, :verbose => false
25
+ cp file, RAILS_ROOT + path, :verbose => false
26
+ end
27
+ unless MailerLayoutsExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
28
+ puts "Copying rake tasks from MailerLayoutsExtension"
29
+ local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
30
+ mkdir_p local_tasks_path, :verbose => false
31
+ Dir[File.join MailerLayoutsExtension.root, %w(lib tasks *.rake)].each do |file|
32
+ cp file, local_tasks_path, :verbose => false
33
+ end
34
+ end
35
+ end
36
+
37
+ desc "Syncs all available translations for this ext to the English ext master"
38
+ task :sync => :environment do
39
+ # The main translation root, basically where English is kept
40
+ language_root = MailerLayoutsExtension.root + "/config/locales"
41
+ words = TranslationSupport.get_translation_keys(language_root)
42
+
43
+ Dir["#{language_root}/*.yml"].each do |filename|
44
+ next if filename.match('_available_tags')
45
+ basename = File.basename(filename, '.yml')
46
+ puts "Syncing #{basename}"
47
+ (comments, other) = TranslationSupport.read_file(filename, basename)
48
+ words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
49
+ other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
50
+ TranslationSupport.write_file(filename, basename, comments, other)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,14 @@
1
+ # Uncomment this if you reference any of your controllers in activate
2
+ # require_dependency 'application_controller'
3
+
4
+ class MailerLayoutsExtension < Radiant::Extension
5
+ version "1.0"
6
+ description "Allows the use of radiant layouts in email messages"
7
+ url "http://github.com/spanner/radiant-mailer_layouts-extension"
8
+
9
+ def activate
10
+ require 'mailer_layouts'
11
+ MessagePage
12
+ ActionView::Base.send :include, MailerHelper
13
+ end
14
+ end
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{radiant-mailer_layouts-extension}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["spanner"]
12
+ s.date = %q{2010-09-22}
13
+ s.description = %q{Allows the use of radiant layouts in email messages}
14
+ s.email = %q{will@spanner.org}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "README.md",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "app/models/message_page.rb",
23
+ "app/views/layouts/radiant_mailer.html.haml",
24
+ "config/locales/en.yml",
25
+ "config/routes.rb",
26
+ "cucumber.yml",
27
+ "features/support/env.rb",
28
+ "features/support/paths.rb",
29
+ "lib/mailer_helper.rb",
30
+ "lib/mailer_layouts.rb",
31
+ "lib/tasks/mailer_layouts_extension_tasks.rake",
32
+ "mailer_layouts_extension.rb",
33
+ "pkg/radiant-mailer_layouts-extension-0.1.0.gem",
34
+ "radiant-mailer_layouts-extension.gemspec",
35
+ "spec/datasets/mailer_layouts_dataset.rb",
36
+ "spec/lib/mailer_layouts_extension_spec.rb",
37
+ "spec/models/notifier_spec.rb",
38
+ "spec/spec.opts",
39
+ "spec/spec_helper.rb",
40
+ "spec/templates/layouts/radiant_mailer.html.haml",
41
+ "spec/templates/notifier/custom.html.haml",
42
+ "spec/templates/notifier/normal.html.haml"
43
+ ]
44
+ s.homepage = %q{http://github.com/spanner/radiant-mailer_layouts-extension}
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.3.7}
48
+ s.summary = %q{Mailer Layouts Extension for Radiant CMS}
49
+ s.test_files = [
50
+ "spec/datasets/mailer_layouts_dataset.rb",
51
+ "spec/lib/mailer_layouts_extension_spec.rb",
52
+ "spec/models/notifier_spec.rb",
53
+ "spec/spec_helper.rb"
54
+ ]
55
+
56
+ if s.respond_to? :specification_version then
57
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
+ s.specification_version = 3
59
+
60
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
+ else
62
+ end
63
+ else
64
+ end
65
+ end
66
+
@@ -0,0 +1,19 @@
1
+ class MailerLayoutsDataset < Dataset::Base
2
+ uses :layouts
3
+
4
+ def load
5
+ create_layout "email", :content_type => "text/html", :content => %{
6
+ Normal email layout:
7
+ <r:content />
8
+ }
9
+ create_layout "custom", :content_type => "text/html", :content => %{
10
+ Custom email layout:
11
+ <r:content />
12
+ }
13
+ create_layout "plain", :content_type => "text/plain", :content => %{
14
+ Plain text email layout:
15
+ <r:content />
16
+ }
17
+
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe MailerLayoutsExtension do
4
+
5
+ it "should initialize" do
6
+ MailerLayoutsExtension.root.should == File.join(File.expand_path(RAILS_ROOT), 'vendor', 'extensions', 'mailer_layouts')
7
+ MailerLayoutsExtension.extension_name.should == 'Mailer Layouts'
8
+ end
9
+
10
+ it "should add mailer hooks" do
11
+ ActionMailer::Base.should respond_to(:radiant_layout)
12
+ ActionMailer::Base.instance_methods.include?('initialize_defaults_with_layout').should be_true
13
+ end
14
+
15
+ it "should add helper" do
16
+ ActionView::Base.included_modules.include?(MailerHelper).should be_true
17
+ end
18
+ end
@@ -0,0 +1,88 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ class NotifierWithRadiantLayout < ActionMailer::Base
4
+ radiant_layout 'email'
5
+ end
6
+
7
+ class NotifierWithRadiantLayoutBlock < ActionMailer::Base
8
+ radiant_layout {|c| c.action_name == "index" ? "main" : "utf8" }
9
+ end
10
+
11
+ class Notifier < ActionMailer::Base
12
+ radiant_layout "email"
13
+
14
+ def normal(recipient)
15
+ from "someone@spanner.org"
16
+ subject "normal"
17
+ recipients recipient
18
+ content_type "text/html"
19
+ body({
20
+ :message => "This is a test"
21
+ })
22
+ end
23
+
24
+ def custom(recipient, layout)
25
+ from "someone@spanner.org"
26
+ subject "custom"
27
+ recipients recipient
28
+ message_layout layout
29
+ content_type layout.content_type
30
+ body({
31
+ :message => "This is also a test"
32
+ })
33
+
34
+ end
35
+ end
36
+
37
+ describe NotifierWithRadiantLayout do
38
+ dataset :mailer_layouts
39
+
40
+ it "should have a default_layout attribute" do
41
+ NotifierWithRadiantLayout.read_inheritable_attribute(:default_layout).should == 'email'
42
+ end
43
+ end
44
+
45
+ describe NotifierWithRadiantLayoutBlock do
46
+ dataset :mailer_layouts
47
+
48
+ it "should have default_layout block" do
49
+ NotifierWithRadiantLayoutBlock.read_inheritable_attribute(:default_layout).should be_kind_of(Proc)
50
+ end
51
+ end
52
+
53
+ describe Notifier do
54
+ dataset :mailer_layouts
55
+
56
+ describe "sending a normal message" do
57
+ it "should apply the default layout" do
58
+ message = Notifier.create_normal("anyone@all.com")
59
+ message.should_not be_nil
60
+ message.body.should =~ /Rendered via mailer_layout:/ # test that radiant_layout has been applied at all
61
+ message.body.should =~ /Normal email layout/ # test that the right radiant layout has been applied
62
+ message.body.should =~ /Normal message template./ # test that the right message template has been used
63
+ message.body.should =~ /This is a test/ # test that the @message variable has made it through
64
+ message.content_type.should == 'text/html'
65
+ end
66
+ end
67
+
68
+ describe "sending a custom message" do
69
+ it "should apply its own layout" do
70
+ message = Notifier.create_custom("anyone@all.com", layouts(:custom))
71
+ message.should_not be_nil
72
+ message.body.should =~ /Rendered via mailer_layout:/
73
+ message.body.should =~ /Custom email layout/
74
+ message.body.should =~ /Custom message template./
75
+ message.body.should =~ /This is also a test/
76
+ message.content_type.should == 'text/html'
77
+ end
78
+ end
79
+
80
+ describe "using a plain text layout" do
81
+ it "should set the right content-type" do
82
+ message = Notifier.create_custom("anyone@all.com", layouts(:plain))
83
+ message.content_type.should == 'text/plain'
84
+ end
85
+ end
86
+
87
+ end
88
+
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,38 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require ENV["RADIANT_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{RADIANT_ROOT}/spec/spec_helper"
13
+
14
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
15
+
16
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
17
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
18
+ end
19
+
20
+ Spec::Runner.configure do |config|
21
+ # config.use_transactional_fixtures = true
22
+ # config.use_instantiated_fixtures = false
23
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
24
+
25
+ # You can declare fixtures for each behaviour like this:
26
+ # describe "...." do
27
+ # fixtures :table_a, :table_b
28
+ #
29
+ # Alternatively, if you prefer to declare them only once, you can
30
+ # do so here, like so ...
31
+ #
32
+ # config.global_fixtures = :table_a, :table_b
33
+ #
34
+ # If you declare global fixtures, be aware that they will be declared
35
+ # for all of your examples, even those that don't use them.
36
+ end
37
+
38
+ ActionMailer::Base.template_root = File.dirname(__FILE__) + '/templates/' # there must be a way to stub the mailer templates
@@ -0,0 +1,7 @@
1
+ %p
2
+ Rendered via mailer_layout:
3
+
4
+ - ivars = {}
5
+ - instance_variables.map {|iv| ivars[iv.intern] = instance_variable_get(iv)} # stores view @variables into a hash that will later populate mailer @variables
6
+ = apply_radiant_layout( ivars ) # with the exception of @radiant_layout, which is extracted by apply_radiant_layout and not passed on
7
+
@@ -0,0 +1,2 @@
1
+ Custom message template.
2
+ = @message
@@ -0,0 +1,2 @@
1
+ Normal message template.
2
+ = @message
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-mailer_layouts-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - spanner
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-22 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Allows the use of radiant layouts in email messages
23
+ email: will@spanner.org
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.md
30
+ files:
31
+ - README.md
32
+ - Rakefile
33
+ - VERSION
34
+ - app/models/message_page.rb
35
+ - app/views/layouts/radiant_mailer.html.haml
36
+ - config/locales/en.yml
37
+ - config/routes.rb
38
+ - cucumber.yml
39
+ - features/support/env.rb
40
+ - features/support/paths.rb
41
+ - lib/mailer_helper.rb
42
+ - lib/mailer_layouts.rb
43
+ - lib/tasks/mailer_layouts_extension_tasks.rake
44
+ - mailer_layouts_extension.rb
45
+ - pkg/radiant-mailer_layouts-extension-0.1.0.gem
46
+ - radiant-mailer_layouts-extension.gemspec
47
+ - spec/datasets/mailer_layouts_dataset.rb
48
+ - spec/lib/mailer_layouts_extension_spec.rb
49
+ - spec/models/notifier_spec.rb
50
+ - spec/spec.opts
51
+ - spec/spec_helper.rb
52
+ - spec/templates/layouts/radiant_mailer.html.haml
53
+ - spec/templates/notifier/custom.html.haml
54
+ - spec/templates/notifier/normal.html.haml
55
+ has_rdoc: true
56
+ homepage: http://github.com/spanner/radiant-mailer_layouts-extension
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Mailer Layouts Extension for Radiant CMS
89
+ test_files:
90
+ - spec/datasets/mailer_layouts_dataset.rb
91
+ - spec/lib/mailer_layouts_extension_spec.rb
92
+ - spec/models/notifier_spec.rb
93
+ - spec/spec_helper.rb