email_boilerplate 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/email_boilerplate.gemspec +24 -0
- data/lib/email_boilerplate.rb +10 -0
- data/lib/email_boilerplate/action_mailer/helper.rb +47 -0
- data/lib/email_boilerplate/action_mailer/mailer.rb +32 -0
- data/lib/email_boilerplate/rails/railtie.rb +8 -0
- data/lib/email_boilerplate/version.rb +3 -0
- data/lib/email_boilerplate/views/boilerplate.html.erb +13 -0
- data/lib/email_boilerplate/views/boilerplate.text.erb +3 -0
- data/test/helper_test.rb +29 -0
- data/test/mailer_test.rb +44 -0
- data/test/test_helper.rb +24 -0
- data/test/views/mock_mailer/example_email.html.erb +4 -0
- data/test/views/mock_mailer/example_email.text.erb +1 -0
- metadata +118 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Earlydoc
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Email Boilerplate
|
2
|
+
|
3
|
+
This Gem provides email templates and view helpers for normalizing HTML emails in common clients based on the work of the HTML Email Boilerplate:
|
4
|
+
|
5
|
+
http://htmlemailboilerplate.com/
|
6
|
+
|
7
|
+
Mailer Class
|
8
|
+
=============
|
9
|
+
|
10
|
+
Inherit from the mailer class to use the boilerplate layout and give your mailer views access to additional helpers.
|
11
|
+
|
12
|
+
class SomeMailer < ActionMailer::EmailBoilerplate
|
13
|
+
...
|
14
|
+
end
|
15
|
+
|
16
|
+
Mailer Layout
|
17
|
+
=============
|
18
|
+
|
19
|
+
The boilerplate providers an html email template that will be used as the default layout whenever a mailer inherits from `ActionMailer::EmailBoilerplate`.
|
20
|
+
|
21
|
+
This template also exposes an optional pattern for nesting an application's secondary email layout. To nest a custom layout, (1) set the layout in the mailer class, and (2) wrap the layout's content and `yield` statement in a `content_for` key for `:body`.
|
22
|
+
|
23
|
+
**some_mailer.rb
|
24
|
+
class SomeMailer < ActionMailer::EmailBoilerplate
|
25
|
+
layout 'some/custom/layout'
|
26
|
+
end
|
27
|
+
|
28
|
+
**some/custom/layout.html.erb
|
29
|
+
<% content_for :body do %>
|
30
|
+
<h1>title</h1>
|
31
|
+
<p>email body</p>
|
32
|
+
<%= yield %>
|
33
|
+
<% end %>
|
34
|
+
<%= render :template => 'boilerplate' %>
|
35
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'email_boilerplate/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "email_boilerplate"
|
8
|
+
spec.version = EmailBoilerplate::VERSION
|
9
|
+
spec.summary = "Earlydoc Email Boilerplate"
|
10
|
+
spec.description = "Email templates and view helpers for normalizing HTML emails in common clients"
|
11
|
+
spec.authors = ['Earlydoc', 'Travis Dunn']
|
12
|
+
spec.email = 'developer@earlydoc.com'
|
13
|
+
spec.homepage = 'https://www.earlydoc.com'
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
|
23
|
+
spec.add_dependency 'activesupport', '~> 4.0.0.rc1'
|
24
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "action_mailer"
|
2
|
+
|
3
|
+
module EmailBoilerplate
|
4
|
+
end
|
5
|
+
|
6
|
+
ActionMailer::Base.append_view_path(File.expand_path("../views", __FILE__))
|
7
|
+
|
8
|
+
require_relative "email_boilerplate/action_mailer/helper"
|
9
|
+
require_relative "email_boilerplate/action_mailer/mailer"
|
10
|
+
require_relative "email_boilerplate/rails/railtie"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module ActionMailer
|
2
|
+
module EmailBoilerplate
|
3
|
+
module Helper
|
4
|
+
def mail_table_tag(options={}, &block)
|
5
|
+
content_tag :table, options.merge(normal_table_options), &block
|
6
|
+
end
|
7
|
+
|
8
|
+
def mail_table_cell_tag(options={}, &block)
|
9
|
+
content_tag :td, normal_table_cell_options, &block
|
10
|
+
end
|
11
|
+
|
12
|
+
def mail_image_tag(source, options = {})
|
13
|
+
image_tag source, options.merge(normal_image_options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def mail_link_to(body, url, options = {})
|
17
|
+
link_to body, url, options.merge(normal_link_options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def mail_paragraph(&block)
|
21
|
+
content_tag :p, normal_paragraph_options, &block
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def normal_paragraph_options
|
27
|
+
{:style => { :margin => '1em 0'} }
|
28
|
+
end
|
29
|
+
|
30
|
+
def normal_table_options
|
31
|
+
{:cellpadding => 0, :cellspacing => 0, :border => 0, :width => '100%'}
|
32
|
+
end
|
33
|
+
|
34
|
+
def normal_table_cell_options
|
35
|
+
{:style => { 'border-collapse' => 'collapse'} }
|
36
|
+
end
|
37
|
+
|
38
|
+
def normal_image_options
|
39
|
+
{:border => 0}
|
40
|
+
end
|
41
|
+
|
42
|
+
def normal_link_options
|
43
|
+
{:style => 'color:inherit'}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ActionMailer
|
2
|
+
module EmailBoilerplate
|
3
|
+
class Mailer < ActionMailer::Base
|
4
|
+
helper ActionMailer::EmailBoilerplate::Helper
|
5
|
+
|
6
|
+
self.append_view_path File.join(__FILE__, '../../views')
|
7
|
+
|
8
|
+
def default_sender(email=nil)
|
9
|
+
from = config.email_from_address
|
10
|
+
"#{email || from} <#{from}>"
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_recipient
|
14
|
+
config.email_to_address
|
15
|
+
end
|
16
|
+
|
17
|
+
def mail(locale, opts)
|
18
|
+
ActionMailer::Base.default_url_options[:locale] = locale
|
19
|
+
|
20
|
+
I18n.with_locale(locale) do
|
21
|
+
super opts
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def config
|
28
|
+
@config ||= Rails.application.config
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
|
6
|
+
<title><%= content_for :title %></title>
|
7
|
+
</head>
|
8
|
+
<body style='margin:0;padding:0'>
|
9
|
+
<div style='width:100% !important; min-height:1000px; font-size:13px; line-height:1.4;'>
|
10
|
+
<%= content_for?(:body) ? yield(:body) : yield %>
|
11
|
+
</div>
|
12
|
+
</body>
|
13
|
+
</html>
|
data/test/helper_test.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class HelperTest < MiniTest::Unit::TestCase
|
4
|
+
include ActionMailer::EmailBoilerplate::Helper
|
5
|
+
|
6
|
+
def test_normal_link_options
|
7
|
+
assert normal_link_options.has_key? :style
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_normal_image_options
|
11
|
+
assert normal_image_options.has_key? :border
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_normal_table_cell_options
|
15
|
+
assert normal_table_cell_options.has_key? :style
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_normal_table_options
|
19
|
+
assert normal_table_options.has_key? :cellpadding
|
20
|
+
assert normal_table_options.has_key? :cellspacing
|
21
|
+
assert normal_table_options.has_key? :border
|
22
|
+
assert normal_table_options.has_key? :width
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_normal_paragraph_options
|
26
|
+
assert normal_paragraph_options.has_key? :style
|
27
|
+
assert normal_paragraph_options[:style].has_key? :margin
|
28
|
+
end
|
29
|
+
end
|
data/test/mailer_test.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class MailerTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@mailer = MockMailer.send :new
|
6
|
+
|
7
|
+
@config ||= OpenStruct.new :email_from_address => 'from@example.com',
|
8
|
+
:email_to_address => 'to@example.com'
|
9
|
+
@mailer.instance_variable_set('@config', @config)
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
ActionMailer::Base.deliveries.clear
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_default_recipient
|
17
|
+
assert_equal @config.email_to_address, @mailer.default_recipient
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_default_sender
|
21
|
+
from = @config.email_from_address
|
22
|
+
assert_equal "#{from} <#{from}>", @mailer.default_sender
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_default_sender_with_email_address
|
26
|
+
email = 'test@example.com'
|
27
|
+
from = @config.email_from_address
|
28
|
+
assert_equal "#{email} <#{from}>", @mailer.default_sender(email)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_that_mail_is_sent
|
32
|
+
mail = MockMailer.example_email 'en', @config
|
33
|
+
mail.deliver
|
34
|
+
assert !ActionMailer::Base.deliveries.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_that_boilerplate_layout_is_used
|
38
|
+
mail = MockMailer.example_email 'en', @config
|
39
|
+
delivery = mail.deliver
|
40
|
+
|
41
|
+
assert_match /<h1>test<\/h1>/, delivery.encoded
|
42
|
+
assert_match /<body style='margin:0;padding:0'>/, delivery.encoded
|
43
|
+
end
|
44
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ansi/code'
|
2
|
+
require 'turn'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'ostruct'
|
5
|
+
require_relative '../lib/email_boilerplate'
|
6
|
+
|
7
|
+
class MockMailer < ActionMailer::EmailBoilerplate::Mailer
|
8
|
+
def example_email(locale, config)
|
9
|
+
@config = config
|
10
|
+
|
11
|
+
mail locale, :to => default_recipient,
|
12
|
+
:from => default_sender,
|
13
|
+
:subject => 'test',
|
14
|
+
:template_name => 'example_email'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
MockMailer.append_view_path(File.expand_path("../views", __FILE__))
|
18
|
+
|
19
|
+
module ActionMailer
|
20
|
+
class Base
|
21
|
+
def default_url_options; {}; end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
ActionMailer::Base.delivery_method = :test
|
@@ -0,0 +1 @@
|
|
1
|
+
test
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: email_boilerplate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Earlydoc
|
9
|
+
- Travis Dunn
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.3'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.3'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rake
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: activesupport
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.0.rc1
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 4.0.0.rc1
|
63
|
+
description: Email templates and view helpers for normalizing HTML emails in common
|
64
|
+
clients
|
65
|
+
email: developer@earlydoc.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- email_boilerplate.gemspec
|
76
|
+
- lib/email_boilerplate.rb
|
77
|
+
- lib/email_boilerplate/action_mailer/helper.rb
|
78
|
+
- lib/email_boilerplate/action_mailer/mailer.rb
|
79
|
+
- lib/email_boilerplate/rails/railtie.rb
|
80
|
+
- lib/email_boilerplate/version.rb
|
81
|
+
- lib/email_boilerplate/views/boilerplate.html.erb
|
82
|
+
- lib/email_boilerplate/views/boilerplate.text.erb
|
83
|
+
- test/helper_test.rb
|
84
|
+
- test/mailer_test.rb
|
85
|
+
- test/test_helper.rb
|
86
|
+
- test/views/mock_mailer/example_email.html.erb
|
87
|
+
- test/views/mock_mailer/example_email.text.erb
|
88
|
+
homepage: https://www.earlydoc.com
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.8.24
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: Earlydoc Email Boilerplate
|
113
|
+
test_files:
|
114
|
+
- test/helper_test.rb
|
115
|
+
- test/mailer_test.rb
|
116
|
+
- test/test_helper.rb
|
117
|
+
- test/views/mock_mailer/example_email.html.erb
|
118
|
+
- test/views/mock_mailer/example_email.text.erb
|