actionmailer-html2text 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +20 -0
- data/lib/actionmailer-html2text.rb +26 -0
- data/lib/actionmailer-html2text/version.rb +5 -0
- data/spec/html2text_spec.rb +95 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/test_mailer.rb +19 -0
- data/spec/views/layouts/mailer.html.erb +8 -0
- data/spec/views/templates/multipart_email.html.erb +7 -0
- data/spec/views/templates/multipart_email.text.erb +3 -0
- data/spec/views/templates/test_email.html.erb +7 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: beb931e5db7e9bd0501ba2ddee4d78cd7ca920df
|
4
|
+
data.tar.gz: c574ecdb40d77779a9f9b0c16ba5602805e8c790
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d0d1202fcc88b8e3ad55e359cb2d7c54b40b1cd29424536239bf5e474546f6730c35fe9c91f796b5f9c23d8ea20d2cbb6495f408315e97510f6e47e26fb21dc5
|
7
|
+
data.tar.gz: d44e06517e580abd37a726192da8fa911557e5792dd6ed6e189b02262e07b98f1b518ca7399386a33e60d08861862105c08177f47b9ff73bbc28b5bee2660b52
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Jevon Wright
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "html2text"
|
2
|
+
|
3
|
+
module ActionMailer
|
4
|
+
module Html2Text
|
5
|
+
TEXT_PLAIN = "text/plain"
|
6
|
+
TEXT_HTML = "text/html"
|
7
|
+
|
8
|
+
def collect_responses(headers)
|
9
|
+
add_plain_text(super(headers))
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_plain_text(responses)
|
13
|
+
html_part = responses.detect { |response| response[:content_type] == TEXT_HTML }
|
14
|
+
text_part = responses.detect { |response| response[:content_type] == TEXT_PLAIN }
|
15
|
+
|
16
|
+
if html_part && !text_part
|
17
|
+
responses.insert 0, {
|
18
|
+
content_type: TEXT_PLAIN,
|
19
|
+
body: ::Html2Text.convert(html_part[:body])
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
responses
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require_relative "test_mailer"
|
3
|
+
|
4
|
+
describe ActionMailer::Html2Text do
|
5
|
+
let(:mailer) { Class.new(TestMailer) }
|
6
|
+
|
7
|
+
let(:to_address) { "test@example.com" }
|
8
|
+
let(:mail) { mailer.test_email(to_address) }
|
9
|
+
let(:text) { mail.parts.first.body }
|
10
|
+
|
11
|
+
context "by default" do
|
12
|
+
it "is not a multipart email" do
|
13
|
+
expect(mail).to_not be_multipart
|
14
|
+
expect(mail.parts).to be_empty
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when including our html2text module" do
|
19
|
+
let(:mailer) do
|
20
|
+
Class.new(TestMailer) do
|
21
|
+
include ActionMailer::Html2Text
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "is a multipart email" do
|
26
|
+
expect(mail).to be_multipart
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has two parts" do
|
30
|
+
expect(mail.parts.size).to eq(2)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "has text first" do
|
34
|
+
expect(mail.parts.first.content_type).to match("text/plain")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has html second" do
|
38
|
+
expect(mail.parts.second.content_type).to match("text/html")
|
39
|
+
end
|
40
|
+
|
41
|
+
context "the text part" do
|
42
|
+
it "does not have any HTML" do
|
43
|
+
expect(text).to_not include("<")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "includes a markdown-style link" do
|
47
|
+
expect(text).to include("[your website](http://example.com)")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "includes the to: address" do
|
51
|
+
expect(text).to include(to_address)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when defining our own multipart templates without Html2Text" do
|
57
|
+
let(:mailer) do
|
58
|
+
Class.new(TestMailer) do
|
59
|
+
def template_name
|
60
|
+
"multipart_email"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "is a multipart email" do
|
66
|
+
expect(mail).to be_multipart
|
67
|
+
end
|
68
|
+
|
69
|
+
it "has two parts" do
|
70
|
+
expect(mail.parts.size).to eq(2)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "has text first" do
|
74
|
+
expect(mail.parts.first.content_type).to match("text/plain")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "has html second" do
|
78
|
+
expect(mail.parts.second.content_type).to match("text/html")
|
79
|
+
end
|
80
|
+
|
81
|
+
context "the text part" do
|
82
|
+
it "does not have any HTML" do
|
83
|
+
expect(text).to_not include("<")
|
84
|
+
end
|
85
|
+
|
86
|
+
it "includes a markdown-style link" do
|
87
|
+
expect(text).to include("[your website](http://example.com)")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "includes the to: address" do
|
91
|
+
expect(text).to include(to_address)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/test_mailer.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class TestMailer < ActionMailer::Base
|
2
|
+
default from: "from@example.com"
|
3
|
+
layout "mailer"
|
4
|
+
|
5
|
+
def template_name
|
6
|
+
"test_email"
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_email(to)
|
10
|
+
@to = to
|
11
|
+
|
12
|
+
mail({
|
13
|
+
to: to,
|
14
|
+
subject: "Test email",
|
15
|
+
template_path: "templates",
|
16
|
+
template_name: template_name
|
17
|
+
})
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionmailer-html2text
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jevon Wright
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: html2text
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionmailer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-collection_matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colorize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Automatically add plain text parts into HTML emails sent by ActionMailer.
|
98
|
+
email:
|
99
|
+
- jevon@powershop.co.nz
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- LICENSE.md
|
105
|
+
- lib/actionmailer-html2text.rb
|
106
|
+
- lib/actionmailer-html2text/version.rb
|
107
|
+
- spec/html2text_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- spec/test_mailer.rb
|
110
|
+
- spec/views/layouts/mailer.html.erb
|
111
|
+
- spec/views/templates/multipart_email.html.erb
|
112
|
+
- spec/views/templates/multipart_email.text.erb
|
113
|
+
- spec/views/templates/test_email.html.erb
|
114
|
+
homepage: https://github.com/soundasleep/actionmailer-html2text
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.4.5
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Add plain text automatically to HTML emails.
|
138
|
+
test_files:
|
139
|
+
- spec/html2text_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/test_mailer.rb
|
142
|
+
- spec/views/layouts/mailer.html.erb
|
143
|
+
- spec/views/templates/multipart_email.html.erb
|
144
|
+
- spec/views/templates/multipart_email.text.erb
|
145
|
+
- spec/views/templates/test_email.html.erb
|