forked from radiant/radiant-share-layouts-extension
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use radiant layouts in ActionMailer subclasses
- Loading branch information
Showing
11 changed files
with
151 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class MessagePage < Page | ||
display_name "Not really a page at all" | ||
|
||
def find_by_url(url, live=true, clean=true) | ||
self | ||
end | ||
|
||
def build_parts_from_hash!(content) | ||
content.each do |k,v| | ||
(part(k) || parts.build(:name => k.to_s, :filter_id => "")).content = v | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= radiant_mailer_layout %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module ShareLayouts::RadiantMailerLayouts | ||
def self.included(base) | ||
base.extend ClassMethods | ||
base.class_eval { | ||
include InstanceMethods | ||
alias_method_chain :initialize_defaults, :layout | ||
} | ||
end | ||
|
||
module ClassMethods | ||
def radiant_layout(name=nil, options={}, &block) | ||
raise ArgumentError, "A layout name or block is required!" unless name || block | ||
write_inheritable_attribute 'radiant_mailer_layout_name', name || block | ||
layout 'radiant_mailer', options | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def initialize_defaults_with_layout(method_name) | ||
set_mailer_layout | ||
initialize_defaults_without_layout(method_name) | ||
end | ||
|
||
def set_mailer_layout | ||
@radiant_mailer_layout = self.class.read_inheritable_attribute 'radiant_mailer_layout_name' | ||
@radiant_mailer_layout = @radiant_mailer_layout.call(self) if @radiant_mailer_layout.is_a? Proc | ||
end | ||
|
||
def layout_for(purpose = :email) | ||
if defined? Site && current_site && current_site.respond_to?(:layout_for) | ||
current_site.layout_for(purpose) | ||
elsif config_layout = Radiant::Config["#{purpose}.layout"] | ||
config_layout | ||
else | ||
'email' | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper' | ||
|
||
class NotifierWithRadiantLayout < ActionMailer::Base | ||
radiant_layout 'main' | ||
end | ||
|
||
class NotifierWithRadiantLayoutBlock < ActionMailer::Base | ||
radiant_layout {|c| c.action_name == "index" ? "main" : "utf8" } | ||
end | ||
|
||
class Notifier < ActionMailer::Base | ||
radiant_layout { |m| m.layout_for :test } | ||
|
||
def test(recipient="test@spanner.org") | ||
from "someone@spanner.org" | ||
subject "test" | ||
recipients recipient | ||
content_type "text/html" | ||
end | ||
end | ||
|
||
describe NotifierWithRadiantLayout do | ||
dataset :layouts | ||
|
||
it "should have radiant layout attribute" do | ||
NotifierWithRadiantLayout.read_inheritable_attribute('radiant_mailer_layout_name').should == 'main' | ||
end | ||
end | ||
|
||
describe NotifierWithRadiantLayoutBlock do | ||
dataset :layouts | ||
|
||
it "should have radiant layout block" do | ||
NotifierWithRadiantLayoutBlock.read_inheritable_attribute('radiant_mailer_layout_name').should be_kind_of(Proc) | ||
end | ||
end | ||
|
||
describe Notifier do | ||
dataset :layouts | ||
|
||
before(:each) do | ||
Radiant::Config['test.layout'] = 'utf8' | ||
end | ||
|
||
it "should apply the radiant layout" do | ||
message = Notifier.create_test("anyone@all.com") | ||
message.should_not be_nil | ||
message.body.should =~ /Rendered with the mailer_layout:/ | ||
message.body.should =~ /Test message template./ | ||
message.content_type.should == 'text/html' | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p>Rendered with the mailer_layout:</p> | ||
|
||
<%= radiant_mailer_layout %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test message template. |