actionmailer-text 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +11 -11
- data/lib/actionmailer-text/html_to_plain_text.rb +3 -0
- data/lib/actionmailer-text/version.rb +1 -1
- data/pkg/actionmailer-text-0.1.1.gem +0 -0
- data/spec/actionmailer-text/html_to_plain_text_spec.rb +183 -0
- metadata +11 -10
- data/pkg/actionmailer-text-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb51e8701b903d56ac693f378e34d38039b1cb09
|
4
|
+
data.tar.gz: 3a9f8751dc64409876f495f453f2af443d8cb096
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e31e763f210563c237399ea3dc4a4ef7d928c977111dbd27ff2dc1fa4cc48987f3ab1c1085320d6b550a940fe293f28e206ccd144917d1801cad345fa6304ad
|
7
|
+
data.tar.gz: 316873f7a5805e270ffc9bea597af3e60d54f62d04842947df66066b831dee11b5266ab113ea5899a925489ef5491aae44a0aee7ec98d3053b936d42b7f1212d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 0.1.1 (Next)
|
2
|
+
|
3
|
+
* Your contribution here.
|
4
|
+
* [#1](https://github.com/dblock/actionmailer-text/pull/1) Ignore elements outside the body - [@woahdae](https://github.com/woahdae).
|
5
|
+
|
1
6
|
### 0.1.0 (2015-04-07)
|
2
7
|
|
3
8
|
* Initial public release - [@dblock](https://github.com/dblock).
|
data/CONTRIBUTING.md
CHANGED
@@ -84,7 +84,7 @@ git push origin my-feature-branch
|
|
84
84
|
|
85
85
|
## Make a Pull Request
|
86
86
|
|
87
|
-
Go to https://github.com/contributor/
|
87
|
+
Go to https://github.com/contributor/actionmailer-text and select your feature branch.
|
88
88
|
Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
89
89
|
|
90
90
|
## Rebase
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
actionmailer-text (0.1.
|
4
|
+
actionmailer-text (0.1.1)
|
5
5
|
actionmailer
|
6
6
|
htmlentities
|
7
7
|
|
@@ -44,24 +44,24 @@ GEM
|
|
44
44
|
email-example-spec (0.1.0)
|
45
45
|
actionmailer
|
46
46
|
erubis (2.7.0)
|
47
|
-
globalid (0.3.
|
47
|
+
globalid (0.3.5)
|
48
48
|
activesupport (>= 4.1.0)
|
49
|
-
htmlentities (4.3.
|
49
|
+
htmlentities (4.3.3)
|
50
50
|
i18n (0.7.0)
|
51
51
|
json (1.8.2)
|
52
|
-
loofah (2.0.
|
52
|
+
loofah (2.0.2)
|
53
53
|
nokogiri (>= 1.5.9)
|
54
54
|
mail (2.6.3)
|
55
55
|
mime-types (>= 1.16, < 3)
|
56
|
-
mime-types (2.
|
56
|
+
mime-types (2.5)
|
57
57
|
mini_portile (0.6.2)
|
58
|
-
minitest (5.
|
58
|
+
minitest (5.6.1)
|
59
59
|
nokogiri (1.6.6.2)
|
60
60
|
mini_portile (~> 0.6.0)
|
61
|
-
parser (2.2.
|
61
|
+
parser (2.2.2.2)
|
62
62
|
ast (>= 1.1, < 3.0)
|
63
|
-
powerpack (0.1.
|
64
|
-
rack (1.6.
|
63
|
+
powerpack (0.1.1)
|
64
|
+
rack (1.6.1)
|
65
65
|
rack-test (0.6.3)
|
66
66
|
rack (>= 1.0)
|
67
67
|
rails-deprecated_sanitizer (1.0.3)
|
@@ -78,9 +78,9 @@ GEM
|
|
78
78
|
rspec-core (~> 3.2.0)
|
79
79
|
rspec-expectations (~> 3.2.0)
|
80
80
|
rspec-mocks (~> 3.2.0)
|
81
|
-
rspec-core (3.2.
|
81
|
+
rspec-core (3.2.3)
|
82
82
|
rspec-support (~> 3.2.0)
|
83
|
-
rspec-expectations (3.2.
|
83
|
+
rspec-expectations (3.2.1)
|
84
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
85
85
|
rspec-support (~> 3.2.0)
|
86
86
|
rspec-mocks (3.2.1)
|
@@ -24,6 +24,9 @@ module ActionMailer
|
|
24
24
|
he = HTMLEntities.new
|
25
25
|
txt = he.decode(txt)
|
26
26
|
|
27
|
+
# Ignore things that come outside the body
|
28
|
+
txt.gsub!(/.*?(<body.+?\/body>).*?/im, '\1')
|
29
|
+
|
27
30
|
# replace image by their alt attribute
|
28
31
|
txt.gsub!(/<img.+?alt=\"([^\"]*)\"[^>]*\/>/i, '\1')
|
29
32
|
txt.gsub!(/<img.+?alt='([^\']*)\'[^>]*\/>/i, '\1')
|
Binary file
|
@@ -0,0 +1,183 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ActionMailer::Text::HtmlToPlainText do
|
5
|
+
it 'converts a fragment' do
|
6
|
+
expect(subject.convert_to_text('<p>Test</p>')).to match(/Test/)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'converts a body' do
|
10
|
+
expect(subject.convert_to_text('
|
11
|
+
<html>
|
12
|
+
<title>Ignore me</title>
|
13
|
+
<body>
|
14
|
+
<p>Test</p>
|
15
|
+
</body>
|
16
|
+
</html>
|
17
|
+
')).to match(/Test/)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'ignores titles' do
|
21
|
+
expect(subject.convert_to_text('
|
22
|
+
<html>
|
23
|
+
<title>Ignore me</title>
|
24
|
+
<body>
|
25
|
+
<p>Test</p>
|
26
|
+
</body>
|
27
|
+
</html>
|
28
|
+
')).not_to match(/Ignore me/)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'ignores header links' do
|
32
|
+
expect(subject.convert_to_text('
|
33
|
+
<html>
|
34
|
+
<head>
|
35
|
+
<link href="http://example.com/should/be/ignored.css" rel="stylesheet" />
|
36
|
+
</head>
|
37
|
+
<body>
|
38
|
+
<p>Test</p>
|
39
|
+
</body>
|
40
|
+
</html>
|
41
|
+
')).not_to match(/\*/)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'ignores header titles' do
|
45
|
+
expect(subject.convert_to_text('
|
46
|
+
<html>
|
47
|
+
<head>
|
48
|
+
<title>Ignore me</title>
|
49
|
+
</head>
|
50
|
+
<body>
|
51
|
+
<p>Test</p>
|
52
|
+
</body>
|
53
|
+
</html>
|
54
|
+
')).not_to match(/Ignore me/)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'converts a malformed body' do
|
58
|
+
expect(subject.convert_to_text('
|
59
|
+
<html>
|
60
|
+
<title>Ignore me</title>
|
61
|
+
<body>
|
62
|
+
<p>Test
|
63
|
+
')).to match(/Test/)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'dencodes html entities' do
|
67
|
+
expect(subject.convert_to_text('
|
68
|
+
cédille garçon & à ñ
|
69
|
+
')).to eq('cédille garçon & à ñ')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'strips whitespace' do
|
73
|
+
expect(subject.convert_to_text(" \ttext\ntext\n")).to eq("text\ntext")
|
74
|
+
expect(subject.convert_to_text(" \na \n a \t")).to eq("a\na")
|
75
|
+
expect(subject.convert_to_text(" \na \n\t \n \n a \t")).to eq("a\n\na")
|
76
|
+
expect(subject.convert_to_text('test text ')).to eq('test text')
|
77
|
+
expect(subject.convert_to_text('test text')).to eq('test text')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'leaves spaces for spans' do
|
81
|
+
expect(subject.convert_to_text('
|
82
|
+
<html>
|
83
|
+
<body>
|
84
|
+
<p><span>Test</span>
|
85
|
+
<span>line 2</span>
|
86
|
+
</p>
|
87
|
+
')).to match(/Test line 2/)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'normalizes line breaks' do
|
91
|
+
expect(subject.convert_to_text("Test text\r\nTest text")).to eq("Test text\nTest text")
|
92
|
+
expect(subject.convert_to_text("Test text\nTest text")).to eq("Test text\nTest text")
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'formats lists' do
|
96
|
+
expect(subject.convert_to_text("<li class='123'>item 1</li> <li>item 2</li>\n")).to eq("* item 1\n* item 2")
|
97
|
+
expect(subject.convert_to_text("<li>item 1</li> \t\n <li>item 2</li> <li> item 3</li>\n")).to eq("* item 1\n* item 2\n* item 3")
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'strips html' do
|
101
|
+
expect(subject.convert_to_text("<p class=\"123'45 , att\" att=tester>test <span class='te\"st'>text</span>\n")).to eq('test text')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'creates line breaks for p and br tags' do
|
105
|
+
expect(subject.convert_to_text('<p>Test text</p><p>Test text</p>')).to eq("Test text\n\nTest text")
|
106
|
+
expect(subject.convert_to_text("\n<p>Test text</p>\n\n\n\t<p>Test text</p>\n")).to eq("Test text\n\nTest text")
|
107
|
+
expect(subject.convert_to_text("\n<p>Test text<br/>Test text</p>\n")).to eq("Test text\nTest text")
|
108
|
+
expect(subject.convert_to_text("\n<p>Test text<br> \tTest text<br></p>\n")).to eq("Test text\nTest text")
|
109
|
+
expect(subject.convert_to_text('Test text<br><BR />Test text')).to eq("Test text\n\nTest text")
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'converts headings' do
|
113
|
+
expect(subject.convert_to_text('<h1>Test</h1>')).to eq("****\nTest\n****")
|
114
|
+
expect(subject.convert_to_text("\t<h1>\nTest</h1> ")).to eq("****\nTest\n****")
|
115
|
+
expect(subject.convert_to_text("\t<h1>\nTest line 1<br>Test 2</h1> ")).to eq("***********\nTest line 1\nTest 2\n***********")
|
116
|
+
expect(subject.convert_to_text('<h1>Test</h1> <h1>Test</h1>')).to eq("****\nTest\n****\n\n****\nTest\n****")
|
117
|
+
expect(subject.convert_to_text('<h2>Test</h2>')).to eq("----\nTest\n----")
|
118
|
+
expect(subject.convert_to_text("<h3> <span class='a'>Test </span></h3>")).to eq("Test\n----")
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'wraps lines' do
|
122
|
+
raw = ''
|
123
|
+
100.times { raw += 'test ' }
|
124
|
+
|
125
|
+
txt = subject.convert_to_text(raw, 20)
|
126
|
+
|
127
|
+
lens = []
|
128
|
+
txt.each_line { |l| lens << l.length }
|
129
|
+
expect(lens.max).to be <= 20
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'converts links' do
|
133
|
+
# basic
|
134
|
+
expect(subject.convert_to_text('<a href="http://example.com/">Link</a>')).to eq('Link ( http://example.com/ )')
|
135
|
+
|
136
|
+
# nested html
|
137
|
+
expect(subject
|
138
|
+
.convert_to_text('<a href="http://example.com/"><span class="a">Link</span></a>'))
|
139
|
+
.to eq('Link ( http://example.com/ )')
|
140
|
+
|
141
|
+
# complex link
|
142
|
+
expect(subject
|
143
|
+
.convert_to_text('<a href="http://example.com:80/~user?aaa=bb&c=d,e,f#foo">Link</a>'))
|
144
|
+
.to eq('Link ( http://example.com:80/~user?aaa=bb&c=d,e,f#foo )')
|
145
|
+
|
146
|
+
# attributes
|
147
|
+
expect(subject
|
148
|
+
.convert_to_text('<a title=\'title\' href="http://example.com/">Link</a>'))
|
149
|
+
.to eq('Link ( http://example.com/ )')
|
150
|
+
|
151
|
+
# spacing
|
152
|
+
expect(subject
|
153
|
+
.convert_to_text('<a href=" http://example.com/ "> Link </a>'))
|
154
|
+
.to eq('Link ( http://example.com/ )')
|
155
|
+
|
156
|
+
# multiple
|
157
|
+
expect(subject
|
158
|
+
.convert_to_text('<a href="http://example.com/a/">Link A</a> <a href="http://example.com/b/">Link B</a>'))
|
159
|
+
.to eq('Link A ( http://example.com/a/ ) Link B ( http://example.com/b/ )')
|
160
|
+
|
161
|
+
# merge links
|
162
|
+
expect(subject.convert_to_text('<a href="%%LINK%%">Link</a>')).to eq('Link ( %%LINK%% )')
|
163
|
+
expect(subject.convert_to_text('<a href="[LINK]">Link</a>')).to eq('Link ( [LINK] )')
|
164
|
+
expect(subject.convert_to_text('<a href="{LINK}">Link</a>')).to eq('Link ( {LINK} )')
|
165
|
+
|
166
|
+
# unsubscribe
|
167
|
+
expect(subject.convert_to_text('<a href="[[!unsubscribe]]">Link</a>')).to eq('Link ( [[!unsubscribe]] )')
|
168
|
+
end
|
169
|
+
|
170
|
+
# see https://github.com/alexdunae/premailer/issues/72
|
171
|
+
it 'converts multiple links per line' do
|
172
|
+
expect(subject
|
173
|
+
.convert_to_text('<p>This is <a href="http://www.google.com" >link1</a> and <a href="http://www.google.com" >link2 </a> is next.</p>', nil, 10_000))
|
174
|
+
.to eq('This is link1 ( http://www.google.com ) and link2 ( http://www.google.com ) is next.')
|
175
|
+
end
|
176
|
+
|
177
|
+
# see https://github.com/alexdunae/premailer/issues/72
|
178
|
+
it 'converts links within headings' do
|
179
|
+
expect(subject
|
180
|
+
.convert_to_text("<h1><a href='http://example.com/'>Test</a></h1>"))
|
181
|
+
.to eq("****************************\nTest ( http://example.com/ )\n****************************")
|
182
|
+
end
|
183
|
+
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionmailer-text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: htmlentities
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description:
|
@@ -57,7 +57,8 @@ files:
|
|
57
57
|
- lib/actionmailer-text/text.rb
|
58
58
|
- lib/actionmailer-text/version.rb
|
59
59
|
- lib/actionmailer_text.rb
|
60
|
-
- pkg/actionmailer-text-0.1.
|
60
|
+
- pkg/actionmailer-text-0.1.1.gem
|
61
|
+
- spec/actionmailer-text/html_to_plain_text_spec.rb
|
61
62
|
- spec/actionmailer-text/multipart_spec.rb
|
62
63
|
- spec/actionmailer-text/version_spec.rb
|
63
64
|
- spec/spec_helper.rb
|
@@ -73,17 +74,17 @@ require_paths:
|
|
73
74
|
- lib
|
74
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
76
|
requirements:
|
76
|
-
- -
|
77
|
+
- - ">="
|
77
78
|
- !ruby/object:Gem::Version
|
78
79
|
version: '0'
|
79
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
81
|
requirements:
|
81
|
-
- -
|
82
|
+
- - ">="
|
82
83
|
- !ruby/object:Gem::Version
|
83
84
|
version: 1.3.6
|
84
85
|
requirements: []
|
85
86
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.2.2
|
87
88
|
signing_key:
|
88
89
|
specification_version: 4
|
89
90
|
summary: Automatically insert a text/plain part into your HTML multipart e-mails.
|
Binary file
|