actionmailer-textgiri 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/CHANGELOG.md +12 -0
- data/CONTRIBUTING.md +125 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +115 -0
- data/LICENSE.md +22 -0
- data/README.md +46 -0
- data/Rakefile +16 -0
- data/actionmailer-textgiri.gemspec +18 -0
- data/lib/actionmailer-text.rb +4 -0
- data/lib/actionmailer-text/html_to_plain_text.rb +19 -0
- data/lib/actionmailer-text/text.rb +20 -0
- data/lib/actionmailer-text/version.rb +5 -0
- data/lib/actionmailer_text.rb +1 -0
- data/spec/actionmailer-text/html_to_plain_text_spec.rb +189 -0
- data/spec/actionmailer-text/multipart_spec.rb +33 -0
- data/spec/actionmailer-text/version_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/fixtures/welcome_email.multipart +32 -0
- data/spec/support/templates/welcome_email.html.erb +5 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 971e172d5a2915165f210f86c8a2e699e04e7345
|
4
|
+
data.tar.gz: 0112853482c9a489eeacf62d4b4bae9a360a30be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38c3e6504d7e1ecdb52dce6de242fa8f0a5ccbac4decacb28cd0d597ff3ad831de839059ea361143da99b47bfb7a44eac317d759f4639043ac29fd775cad690c
|
7
|
+
data.tar.gz: e2cc90b0a9a0ef76d0fc0eab9140163a3cb9bf9ba1c9c89a27c7311dc4337098c61070029d25cf452b8bdf9421379a5ececaa7cefff746755fb74afe0da78457
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
### 0.1.2 (Next)
|
2
|
+
|
3
|
+
* [#4](https://github.com/dblock/actionmailer-text/pull/4): Ignore empty links - [@apalancat](https://github.com/apalancat).
|
4
|
+
* Your contribution here.
|
5
|
+
|
6
|
+
### 0.1.1 (2015-04-25)
|
7
|
+
|
8
|
+
* [#1](https://github.com/dblock/actionmailer-text/pull/1): Ignore elements outside the body - [@woahdae](https://github.com/woahdae).
|
9
|
+
|
10
|
+
### 0.1.0 (2015-04-07)
|
11
|
+
|
12
|
+
* Initial public release - [@dblock](https://github.com/dblock).
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# Contributing to ActionMailer::Text
|
2
|
+
|
3
|
+
This project is work of [many contributors](https://github.com/dblock/actionmailer-text/graphs/contributors).
|
4
|
+
|
5
|
+
You're encouraged to submit [pull requests](https://github.com/dblock/actionmailer-text/pulls), [propose features and discuss issues](https://github.com/dblock/actionmailer-text/issues).
|
6
|
+
|
7
|
+
In the examples below, substitute your Github username for `contributor` in URLs.
|
8
|
+
|
9
|
+
## Fork the Project
|
10
|
+
|
11
|
+
Fork the [project on Github](https://github.com/dblock/actionmailer-text) and check out your copy.
|
12
|
+
|
13
|
+
```
|
14
|
+
git clone https://github.com/contributor/actionmailer-text.git
|
15
|
+
cd actionmailer-text
|
16
|
+
git remote add upstream https://github.com/dblock/actionmailer-text.git
|
17
|
+
```
|
18
|
+
|
19
|
+
## Create a Topic Branch
|
20
|
+
|
21
|
+
Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
|
22
|
+
|
23
|
+
```
|
24
|
+
git checkout master
|
25
|
+
git pull upstream master
|
26
|
+
git checkout -b my-feature-branch
|
27
|
+
```
|
28
|
+
|
29
|
+
## Bundle Install and Test
|
30
|
+
|
31
|
+
Ensure that you can build the project and run tests.
|
32
|
+
|
33
|
+
```
|
34
|
+
bundle install
|
35
|
+
bundle exec rake
|
36
|
+
```
|
37
|
+
|
38
|
+
## Write Tests
|
39
|
+
|
40
|
+
Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build.
|
41
|
+
Add to [spec](spec).
|
42
|
+
|
43
|
+
We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
|
44
|
+
|
45
|
+
## Write Code
|
46
|
+
|
47
|
+
Implement your feature or bug fix.
|
48
|
+
|
49
|
+
Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop).
|
50
|
+
Run `bundle exec rubocop` and fix any style issues highlighted.
|
51
|
+
|
52
|
+
Make sure that `bundle exec rake` completes without errors.
|
53
|
+
|
54
|
+
## Write Documentation
|
55
|
+
|
56
|
+
Document any external behavior in the [README](README.md).
|
57
|
+
|
58
|
+
## Update Changelog
|
59
|
+
|
60
|
+
Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*.
|
61
|
+
Make it look like every other line, including your name and link to your Github account.
|
62
|
+
|
63
|
+
## Commit Changes
|
64
|
+
|
65
|
+
Make sure git knows your name and email address:
|
66
|
+
|
67
|
+
```
|
68
|
+
git config --global user.name "Your Name"
|
69
|
+
git config --global user.email "contributor@example.com"
|
70
|
+
```
|
71
|
+
|
72
|
+
Writing good commit logs is important. A commit log should describe what changed and why.
|
73
|
+
|
74
|
+
```
|
75
|
+
git add ...
|
76
|
+
git commit
|
77
|
+
```
|
78
|
+
|
79
|
+
## Push
|
80
|
+
|
81
|
+
```
|
82
|
+
git push origin my-feature-branch
|
83
|
+
```
|
84
|
+
|
85
|
+
## Make a Pull Request
|
86
|
+
|
87
|
+
Go to https://github.com/contributor/actionmailer-text and select your feature branch.
|
88
|
+
Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
89
|
+
|
90
|
+
## Rebase
|
91
|
+
|
92
|
+
If you've been working on a change for a while, rebase with upstream/master.
|
93
|
+
|
94
|
+
```
|
95
|
+
git fetch upstream
|
96
|
+
git rebase upstream/master
|
97
|
+
git push origin my-feature-branch -f
|
98
|
+
```
|
99
|
+
|
100
|
+
## Update CHANGELOG Again
|
101
|
+
|
102
|
+
Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
|
103
|
+
|
104
|
+
```
|
105
|
+
* [#123](https://github.com/dblock/actionmailer-text/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
|
106
|
+
```
|
107
|
+
|
108
|
+
Amend your previous commit and force push the changes.
|
109
|
+
|
110
|
+
```
|
111
|
+
git commit --amend
|
112
|
+
git push origin my-feature-branch -f
|
113
|
+
```
|
114
|
+
|
115
|
+
## Check on Your Pull Request
|
116
|
+
|
117
|
+
Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
|
118
|
+
|
119
|
+
## Be Patient
|
120
|
+
|
121
|
+
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
|
122
|
+
|
123
|
+
## Thank You
|
124
|
+
|
125
|
+
Please do know that we really appreciate and value your time and work. We love you, really.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
actionmailer-textgiri (0.1.2)
|
5
|
+
actionmailer
|
6
|
+
htmlentities
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (4.2.6)
|
12
|
+
actionpack (= 4.2.6)
|
13
|
+
actionview (= 4.2.6)
|
14
|
+
activejob (= 4.2.6)
|
15
|
+
mail (~> 2.5, >= 2.5.4)
|
16
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
17
|
+
actionpack (4.2.6)
|
18
|
+
actionview (= 4.2.6)
|
19
|
+
activesupport (= 4.2.6)
|
20
|
+
rack (~> 1.6)
|
21
|
+
rack-test (~> 0.6.2)
|
22
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
24
|
+
actionview (4.2.6)
|
25
|
+
activesupport (= 4.2.6)
|
26
|
+
builder (~> 3.1)
|
27
|
+
erubis (~> 2.7.0)
|
28
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
29
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
30
|
+
activejob (4.2.6)
|
31
|
+
activesupport (= 4.2.6)
|
32
|
+
globalid (>= 0.3.0)
|
33
|
+
activesupport (4.2.6)
|
34
|
+
i18n (~> 0.7)
|
35
|
+
json (~> 1.7, >= 1.7.7)
|
36
|
+
minitest (~> 5.1)
|
37
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
38
|
+
tzinfo (~> 1.1)
|
39
|
+
ast (2.2.0)
|
40
|
+
astrolabe (1.3.1)
|
41
|
+
parser (~> 2.2)
|
42
|
+
builder (3.2.2)
|
43
|
+
diff-lcs (1.2.5)
|
44
|
+
email-example-spec (0.1.0)
|
45
|
+
actionmailer
|
46
|
+
erubis (2.7.0)
|
47
|
+
globalid (0.3.6)
|
48
|
+
activesupport (>= 4.1.0)
|
49
|
+
htmlentities (4.3.4)
|
50
|
+
i18n (0.7.0)
|
51
|
+
json (1.8.3)
|
52
|
+
loofah (2.0.3)
|
53
|
+
nokogiri (>= 1.5.9)
|
54
|
+
mail (2.6.4)
|
55
|
+
mime-types (>= 1.16, < 4)
|
56
|
+
mime-types (3.0)
|
57
|
+
mime-types-data (~> 3.2015)
|
58
|
+
mime-types-data (3.2016.0221)
|
59
|
+
mini_portile2 (2.0.0)
|
60
|
+
minitest (5.8.4)
|
61
|
+
nokogiri (1.6.7.2)
|
62
|
+
mini_portile2 (~> 2.0.0.rc2)
|
63
|
+
parser (2.3.1.0)
|
64
|
+
ast (~> 2.2)
|
65
|
+
powerpack (0.1.1)
|
66
|
+
rack (1.6.4)
|
67
|
+
rack-test (0.6.3)
|
68
|
+
rack (>= 1.0)
|
69
|
+
rails-deprecated_sanitizer (1.0.3)
|
70
|
+
activesupport (>= 4.2.0.alpha)
|
71
|
+
rails-dom-testing (1.0.7)
|
72
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
73
|
+
nokogiri (~> 1.6.0)
|
74
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
75
|
+
rails-html-sanitizer (1.0.3)
|
76
|
+
loofah (~> 2.0)
|
77
|
+
rainbow (2.1.0)
|
78
|
+
rake (10.5.0)
|
79
|
+
rspec (3.4.0)
|
80
|
+
rspec-core (~> 3.4.0)
|
81
|
+
rspec-expectations (~> 3.4.0)
|
82
|
+
rspec-mocks (~> 3.4.0)
|
83
|
+
rspec-core (3.4.4)
|
84
|
+
rspec-support (~> 3.4.0)
|
85
|
+
rspec-expectations (3.4.0)
|
86
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
87
|
+
rspec-support (~> 3.4.0)
|
88
|
+
rspec-mocks (3.4.1)
|
89
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
90
|
+
rspec-support (~> 3.4.0)
|
91
|
+
rspec-support (3.4.1)
|
92
|
+
rubocop (0.30.0)
|
93
|
+
astrolabe (~> 1.3)
|
94
|
+
parser (>= 2.2.0.1, < 3.0)
|
95
|
+
powerpack (~> 0.1)
|
96
|
+
rainbow (>= 1.99.1, < 3.0)
|
97
|
+
ruby-progressbar (~> 1.4)
|
98
|
+
ruby-progressbar (1.8.0)
|
99
|
+
thread_safe (0.3.5)
|
100
|
+
tzinfo (1.2.2)
|
101
|
+
thread_safe (~> 0.1)
|
102
|
+
|
103
|
+
PLATFORMS
|
104
|
+
ruby
|
105
|
+
|
106
|
+
DEPENDENCIES
|
107
|
+
actionmailer-textgiri!
|
108
|
+
email-example-spec (~> 0.1.0)
|
109
|
+
nokogiri
|
110
|
+
rake (~> 10.4)
|
111
|
+
rspec (~> 3.2)
|
112
|
+
rubocop (= 0.30.0)
|
113
|
+
|
114
|
+
BUNDLED WITH
|
115
|
+
1.12.2
|
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2015 Daniel Doubrovkine, Artsy and Contributors
|
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,46 @@
|
|
1
|
+
ActionMailer::Text
|
2
|
+
==================
|
3
|
+
|
4
|
+
Automatically insert a text/plain part into your HTML multipart e-mails.
|
5
|
+
|
6
|
+
### This version of actionmailer-text uses Nokogiri to parse html, to use the original version go [here](https://github.com/dblock/actionmailer-text)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'actionmailer-textgiri'
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
class WelcomeMailer < ActionMailer::Base
|
18
|
+
include ActionMailer::Text
|
19
|
+
|
20
|
+
default from: 'welcome@example.org'
|
21
|
+
|
22
|
+
def welcome(user)
|
23
|
+
@user = user
|
24
|
+
mail(to: @user.email, subject: 'Welcome!') do |format|
|
25
|
+
format.html { render 'welcome' }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
```
|
31
|
+
|
32
|
+
## Details
|
33
|
+
|
34
|
+
The MIME standard allows systems to send e-mail with multiple parts: plain/text for business-efficient devices such as the Blackberry, and text/html for web-based e-mail readers, such as GMail. Furthermore, ActionMailer supports multiple template formats: create an .html.haml template along with a .txt.haml template to generate both. We also know that text/plain email helps deliverability, but we believe a disproportionately small amount of text e-mails are actually read - the vast majority of devices are capable of parsing some HTML. This gem lets you get the text/plain part for free.
|
35
|
+
|
36
|
+
See [this blog post](http://artsy.github.io/blog/2012/05/16/generating-automatic-plain-text-mime-parts-with-rails-actionmailer) for details.
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
See [CONTRIBUTING](CONTRIBUTING.md).
|
41
|
+
|
42
|
+
## Copyright and License
|
43
|
+
|
44
|
+
Copyright (c) 2015, Daniel Doubrovkine, Artsy and [Contributors](CHANGELOG.md).
|
45
|
+
|
46
|
+
This project is licensed under the [MIT License](LICENSE.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
Bundler.setup :default, :development
|
5
|
+
|
6
|
+
require 'rspec/core'
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
10
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rubocop/rake_task'
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: [:rubocop, :spec]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'actionmailer-text/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'actionmailer-textgiri'
|
6
|
+
s.version = ActionMailer::Text::VERSION
|
7
|
+
s.authors = ['Daniel Doubrovkine', 'Cameron Craig', 'Simplybuilt']
|
8
|
+
s.email = 'sentrathis96@gmail.com'
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.required_rubygems_version = '>= 1.3.6'
|
11
|
+
s.files = Dir['**/*']
|
12
|
+
s.require_paths = ['lib']
|
13
|
+
s.homepage = 'http://github.com/SimplyBuilt/actionmailer-textgiri'
|
14
|
+
s.licenses = ['MIT']
|
15
|
+
s.summary = 'Automatically insert a text/plain part into your HTML multipart e-mails using Nokogiri to parse pre-exisiting html emails'
|
16
|
+
s.add_dependency 'actionmailer'
|
17
|
+
s.add_dependency 'htmlentities'
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module ActionMailer
|
4
|
+
module Text
|
5
|
+
module HtmlToPlainText
|
6
|
+
def convert_to_text(html_body)
|
7
|
+
body_parts = []
|
8
|
+
Nokogiri::HTML(html_body).traverse do |node|
|
9
|
+
if node.text? and !(content = node.content ? node.content.strip : nil).empty?
|
10
|
+
body_parts << content
|
11
|
+
elsif node.name == "a" && (href = node.attr("href")) && href.match(/^https?:/)
|
12
|
+
body_parts << href
|
13
|
+
end
|
14
|
+
end
|
15
|
+
body_parts.uniq.join("\n")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ActionMailer
|
2
|
+
module Text
|
3
|
+
def self.included(klass)
|
4
|
+
klass.class_eval do
|
5
|
+
include ActionMailer::Text::HtmlToPlainText
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def collect_responses(headers)
|
10
|
+
responses = super headers
|
11
|
+
html_part = responses.detect { |response| response[:content_type] == 'text/html' }
|
12
|
+
text_part = responses.detect { |response| response[:content_type] == 'text/plain' }
|
13
|
+
if html_part && !text_part
|
14
|
+
responses.insert 0, content_type: 'text/plain', body: convert_to_text(html_part[:body])
|
15
|
+
headers[:parts_order] = ['text/plain'] + headers[:parts_order] unless headers[:parts_order].include?('text/plain')
|
16
|
+
end
|
17
|
+
responses
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'email-example-spec'
|
@@ -0,0 +1,189 @@
|
|
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
|
+
it 'ignores empty links' do
|
171
|
+
expect(subject
|
172
|
+
.convert_to_text('<a href="http://example.com/a/">Link A</a> <a href="http://example.com/b/"></a> <a href="http://example.com/c/">Link C</a>', nil))
|
173
|
+
.to eq('Link A ( http://example.com/a/ ) Link C ( http://example.com/c/ )')
|
174
|
+
end
|
175
|
+
|
176
|
+
# see https://github.com/alexdunae/premailer/issues/72
|
177
|
+
it 'converts multiple links per line' do
|
178
|
+
expect(subject
|
179
|
+
.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))
|
180
|
+
.to eq('This is link1 ( http://www.google.com ) and link2 ( http://www.google.com ) is next.')
|
181
|
+
end
|
182
|
+
|
183
|
+
# see https://github.com/alexdunae/premailer/issues/72
|
184
|
+
it 'converts links within headings' do
|
185
|
+
expect(subject
|
186
|
+
.convert_to_text("<h1><a href='http://example.com/'>Test</a></h1>"))
|
187
|
+
.to eq("****************************\nTest ( http://example.com/ )\n****************************")
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActionMailer::Text do
|
4
|
+
let(:mailer) do
|
5
|
+
Class.new(ActionMailer::Base) do
|
6
|
+
include ActionMailer::Text
|
7
|
+
|
8
|
+
default from: 'Joe User <joe@example.org>'
|
9
|
+
|
10
|
+
def welcome_mail(username)
|
11
|
+
@username = username
|
12
|
+
mail to: 'user@example.org', subject: 'Welcome!' do |format|
|
13
|
+
format.html { render 'templates/welcome_email' }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
subject do
|
19
|
+
mailer.welcome_mail('username')
|
20
|
+
end
|
21
|
+
it 'generates a text part' do
|
22
|
+
expect(subject.parts.size).to eq 2
|
23
|
+
end
|
24
|
+
it 'inserts text part first' do
|
25
|
+
expect(subject.parts.first.content_type).to eq 'text/plain; charset=UTF-8'
|
26
|
+
end
|
27
|
+
it 'inserts html part last' do
|
28
|
+
expect(subject.parts.last.content_type).to eq 'text/html; charset=UTF-8'
|
29
|
+
end
|
30
|
+
it 'matches output' do
|
31
|
+
expect(subject).to match_email_example_in 'welcome_email.multipart'
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rspec'
|
5
|
+
require 'actionmailer-text'
|
6
|
+
require 'email-example-spec'
|
7
|
+
|
8
|
+
ActionMailer::Base.view_paths = File.join(File.dirname(__FILE__), 'support')
|
9
|
+
|
10
|
+
EmailExampleSpec.configure do |config|
|
11
|
+
config.fixture_path = File.join(File.dirname(__FILE__), 'support/fixtures')
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Date: Thu, 01 Jan 1970 00:00:00 +0000
|
2
|
+
From: Joe User <joe@example.org>
|
3
|
+
To: user@example.org
|
4
|
+
Message-ID: 1
|
5
|
+
Subject: Welcome!
|
6
|
+
Mime-Version: 1.0
|
7
|
+
Content-Type: multipart/alternative;
|
8
|
+
boundary=boundary;
|
9
|
+
charset=UTF-8
|
10
|
+
Content-Transfer-Encoding: 7bit
|
11
|
+
|
12
|
+
|
13
|
+
--boundary
|
14
|
+
Content-Type: text/plain;
|
15
|
+
charset=UTF-8
|
16
|
+
Content-Transfer-Encoding: 7bit
|
17
|
+
|
18
|
+
Hi username,
|
19
|
+
|
20
|
+
Thanks for joining our service! Please check back often.
|
21
|
+
--boundary
|
22
|
+
Content-Type: text/html;
|
23
|
+
charset=UTF-8
|
24
|
+
Content-Transfer-Encoding: 7bit
|
25
|
+
|
26
|
+
<body>
|
27
|
+
<p>Hi username,</p>
|
28
|
+
<p>Thanks for joining our service! Please check back often.</p>
|
29
|
+
</body>
|
30
|
+
|
31
|
+
|
32
|
+
--boundary--
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionmailer-textgiri
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Doubrovkine
|
8
|
+
- Cameron Craig
|
9
|
+
- Simplybuilt
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: actionmailer
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: htmlentities
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
description:
|
44
|
+
email: sentrathis96@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- CHANGELOG.md
|
50
|
+
- CONTRIBUTING.md
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE.md
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- actionmailer-textgiri.gemspec
|
57
|
+
- lib/actionmailer-text.rb
|
58
|
+
- lib/actionmailer-text/html_to_plain_text.rb
|
59
|
+
- lib/actionmailer-text/text.rb
|
60
|
+
- lib/actionmailer-text/version.rb
|
61
|
+
- lib/actionmailer_text.rb
|
62
|
+
- spec/actionmailer-text/html_to_plain_text_spec.rb
|
63
|
+
- spec/actionmailer-text/multipart_spec.rb
|
64
|
+
- spec/actionmailer-text/version_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
- spec/support/fixtures/welcome_email.multipart
|
67
|
+
- spec/support/templates/welcome_email.html.erb
|
68
|
+
homepage: http://github.com/SimplyBuilt/actionmailer-textgiri
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.3.6
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.5.1
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Automatically insert a text/plain part into your HTML multipart e-mails using
|
92
|
+
Nokogiri to parse pre-exisiting html emails
|
93
|
+
test_files: []
|