actionmailer-markdown 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.rubocop.yml +11 -82
- data/README.md +48 -19
- data/Rakefile +1 -1
- data/actionmailer-markdown.gemspec +5 -0
- data/lib/action_mailer/markdown/ext.rb +3 -3
- data/lib/action_mailer/markdown/resolver.rb +7 -1
- data/lib/action_mailer/markdown/version.rb +1 -1
- metadata +24 -9
- data/.travis.yml +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a044ca81f7b847e07a7f2287837a5ee6fb7b077a7ea4b3c91fa06234380b1188
|
4
|
+
data.tar.gz: fcedeba702d82d424fd45a23c0c7cc8a83efe4df13f93238968fb277e393fae3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc09a724f76c74741e55d43247491d61dcf7738564c58d6b939ca815935bb75057adb9560b3b74b018734ed8d099f546111c6369ace5cf74b1ecf5faa6d06a6d
|
7
|
+
data.tar.gz: 97bd392bca74d202d65cab66260704ba18206adb880d637ba20998cda0093d16ade2d0a1b604756f53a2423fe1b657bb33adabe9369b4b1d393c8e5d36fcfeda
|
data/.github/FUNDING.yml
ADDED
data/.rubocop.yml
CHANGED
@@ -1,92 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Exclude:
|
5
|
-
- db/schema.rb
|
6
|
-
- db/seeds.rb
|
7
|
-
- config/environments/**/*.rb
|
8
|
-
- bin/**/*
|
9
|
-
- vendor/**/*
|
10
|
-
|
11
|
-
Style/Documentation:
|
12
|
-
Enabled: false
|
13
|
-
|
14
|
-
Style/StringLiterals:
|
15
|
-
EnforcedStyle: double_quotes
|
16
|
-
|
17
|
-
Layout/SpaceInsideBlockBraces:
|
18
|
-
EnforcedStyle: space
|
19
|
-
EnforcedStyleForEmptyBraces: space
|
20
|
-
SpaceBeforeBlockParameters: false
|
21
|
-
|
22
|
-
Layout/SpaceInsideHashLiteralBraces:
|
23
|
-
EnforcedStyle: no_space
|
24
|
-
EnforcedStyleForEmptyBraces: no_space
|
25
|
-
|
26
|
-
Layout/FirstArrayElementLineBreak:
|
27
|
-
Enabled: true
|
28
|
-
|
29
|
-
Layout/FirstHashElementLineBreak:
|
30
|
-
Enabled: true
|
31
|
-
|
32
|
-
Style/PercentLiteralDelimiters:
|
33
|
-
PreferredDelimiters:
|
34
|
-
"%": "[]"
|
35
|
-
"%i": "[]"
|
36
|
-
"%q": "[]"
|
37
|
-
"%Q": "[]"
|
38
|
-
"%r": "{}"
|
39
|
-
"%s": "[]"
|
40
|
-
"%w": "[]"
|
41
|
-
"%W": "[]"
|
42
|
-
"%x": "[]"
|
43
|
-
|
44
|
-
Metrics/LineLength:
|
45
|
-
Enabled: false
|
46
|
-
|
47
|
-
Metrics/MethodLength:
|
48
|
-
Enabled: false
|
49
|
-
|
50
|
-
Style/EmptyMethod:
|
51
|
-
EnforcedStyle: expanded
|
1
|
+
---
|
2
|
+
inherit_gem:
|
3
|
+
rubocop-fnando: .rubocop.yml
|
52
4
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
Style/AccessModifierDeclarations:
|
57
|
-
EnforcedStyle: inline
|
58
|
-
|
59
|
-
Naming/UncommunicativeMethodParamName:
|
60
|
-
Enabled: false
|
61
|
-
|
62
|
-
Style/Alias:
|
63
|
-
EnforcedStyle: prefer_alias_method
|
64
|
-
|
65
|
-
Metrics/CyclomaticComplexity:
|
66
|
-
Enabled: false
|
67
|
-
|
68
|
-
Metrics/AbcSize:
|
69
|
-
Enabled: false
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 2.7
|
7
|
+
NewCops: enable
|
70
8
|
|
71
|
-
|
9
|
+
Layout/LineLength:
|
72
10
|
Enabled: false
|
73
11
|
|
74
|
-
|
12
|
+
Metrics:
|
75
13
|
Enabled: false
|
76
14
|
|
77
|
-
Style/HashSyntax:
|
78
|
-
Exclude:
|
79
|
-
- Rakefile
|
80
|
-
- "**/*.rake"
|
81
|
-
|
82
|
-
Style/SymbolArray:
|
83
|
-
Exclude:
|
84
|
-
- Rakefile
|
85
|
-
- "**/*.rake"
|
86
|
-
|
87
15
|
Naming/FileName:
|
88
16
|
Exclude:
|
89
17
|
- lib/actionmailer-markdown.rb
|
90
18
|
|
91
|
-
|
92
|
-
|
19
|
+
Style/OpenStructUse:
|
20
|
+
Exclude:
|
21
|
+
- test/**/*.rb
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActionMailer::Markdown
|
2
2
|
|
3
|
-
[![Travis-CI](https://travis-ci.org/fnando/actionmailer-markdown.
|
3
|
+
[![Travis-CI](https://travis-ci.org/fnando/actionmailer-markdown.svg)](https://travis-ci.org/fnando/actionmailer-markdown)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/fnando/actionmailer-markdown/badges/gpa.svg)](https://codeclimate.com/github/fnando/actionmailer-markdown)
|
5
5
|
[![Test Coverage](https://codeclimate.com/github/fnando/actionmailer-markdown/badges/coverage.svg)](https://codeclimate.com/github/fnando/actionmailer-markdown/coverage)
|
6
6
|
[![Gem](https://img.shields.io/gem/v/actionmailer-markdown.svg)](https://rubygems.org/gems/actionmailer-markdown)
|
@@ -26,7 +26,9 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
Imagine that you have a mail named `UserMailer#welcome`. Instead of manually
|
29
|
+
Imagine that you have a mail named `UserMailer#welcome`. Instead of manually
|
30
|
+
defining your subjects like the following, you can create the subject by
|
31
|
+
defining the `user_mailer.welcome.subject` translation.
|
30
32
|
|
31
33
|
```ruby
|
32
34
|
# app/mailers/user_mailer.rb
|
@@ -45,7 +47,9 @@ en:
|
|
45
47
|
subject: Welcome to my app
|
46
48
|
```
|
47
49
|
|
48
|
-
Since I really like defining everything I can in I18n files, I always extend
|
50
|
+
Since I really like defining everything I can in I18n files, I always extend
|
51
|
+
this behavior to the message's body, through the `user_mailer.welcome.body`
|
52
|
+
translation.
|
49
53
|
|
50
54
|
```yaml
|
51
55
|
# config/locales/en.yml
|
@@ -60,7 +64,8 @@ en:
|
|
60
64
|
Myapp team
|
61
65
|
```
|
62
66
|
|
63
|
-
Did you notice that `|`? That allows YAML strings to be multiline. And on your
|
67
|
+
Did you notice that `|`? That allows YAML strings to be multiline. And on your
|
68
|
+
e-mail class you can do something like this:
|
64
69
|
|
65
70
|
```ruby
|
66
71
|
# app/mailers/user_mailer.rb
|
@@ -71,7 +76,8 @@ class UserMailer < ApplicationMailer
|
|
71
76
|
end
|
72
77
|
```
|
73
78
|
|
74
|
-
And if you want to render HTML and text-plain from this string, you may have to
|
79
|
+
And if you want to render HTML and text-plain from this string, you may have to
|
80
|
+
do something like this (Markdown class not shown).
|
75
81
|
|
76
82
|
```ruby
|
77
83
|
# app/mailers/user_mailer.rb
|
@@ -87,7 +93,8 @@ class UserMailer < ApplicationMailer
|
|
87
93
|
end
|
88
94
|
```
|
89
95
|
|
90
|
-
This idea is really nice, but you have too much things to deal with. Not
|
96
|
+
This idea is really nice, but you have too much things to deal with. Not
|
97
|
+
anymore!
|
91
98
|
|
92
99
|
With ActionMailer::Markdown you can just define your mailer action like this:
|
93
100
|
|
@@ -100,17 +107,20 @@ class UserMailer < ApplicationMailer
|
|
100
107
|
end
|
101
108
|
```
|
102
109
|
|
103
|
-
That's right! This gem automatically uses `user_mailer.welcome.{subject,body}`
|
110
|
+
That's right! This gem automatically uses `user_mailer.welcome.{subject,body}`
|
111
|
+
from your translation files. And the best part: it evens supports Markdown.
|
104
112
|
|
105
113
|
### Passing variables
|
106
114
|
|
107
|
-
You're likely to pass in variables to your messages. To do this, just define
|
115
|
+
You're likely to pass in variables to your messages. To do this, just define
|
116
|
+
instance variables. Imagine you want to parse the user's name on your subject
|
117
|
+
and message. Let's suppose you have your translation file defined like this:
|
108
118
|
|
109
119
|
```yaml
|
110
120
|
en:
|
111
121
|
user_mailer:
|
112
122
|
welcome:
|
113
|
-
subject:
|
123
|
+
subject: "Welcome to Myapp, %{name}"
|
114
124
|
body: |
|
115
125
|
Hello, %{name}. And welcome to Myapp.
|
116
126
|
```
|
@@ -156,7 +166,8 @@ en:
|
|
156
166
|
Myapp team
|
157
167
|
```
|
158
168
|
|
159
|
-
You may be wondering what happens with the mail's text part. Don't worry!
|
169
|
+
You may be wondering what happens with the mail's text part. Don't worry!
|
170
|
+
ActionMailer::Markdown will take care of that. That message will be rendered as:
|
160
171
|
|
161
172
|
```text
|
162
173
|
Hello, John!
|
@@ -172,11 +183,16 @@ Myapp team
|
|
172
183
|
|
173
184
|
Lists and other elements are also exported to a more friendly text version.
|
174
185
|
|
175
|
-
**PROTIP:** Use [i18n-dot_lookup](https://github.com/fnando/i18n-dot_lookup) if
|
186
|
+
**PROTIP:** Use [i18n-dot_lookup](https://github.com/fnando/i18n-dot_lookup) if
|
187
|
+
you want to access properties from an object, like `%{user.name}`
|
176
188
|
|
177
189
|
### Replacing the Markdown engine
|
178
190
|
|
179
|
-
[redcarpet](https://github.com/vmg/redcarpet) is the default Markdown parser.
|
191
|
+
[redcarpet](https://github.com/vmg/redcarpet) is the default Markdown parser.
|
192
|
+
You may want to specify different options or even switch out to a different
|
193
|
+
Markdown library. All you have to do is defining a processor that responds to
|
194
|
+
`.call`. Let's say you want to use [kramdown](http://kramdown.gettalong.org/) as
|
195
|
+
your Markdown engine.
|
180
196
|
|
181
197
|
```ruby
|
182
198
|
ActionMailer::Markdown.processor = -> text { Kramdown::Document.new(text).to_html }
|
@@ -184,23 +200,36 @@ ActionMailer::Markdown.processor = -> text { Kramdown::Document.new(text).to_htm
|
|
184
200
|
|
185
201
|
### Falling back to ActionMailer's default behavior
|
186
202
|
|
187
|
-
You can use templates if you want. Just don't define the `.body` part of your
|
203
|
+
You can use templates if you want. Just don't define the `.body` part of your
|
204
|
+
translation. Also, if you pass a block to the `mail()` method, it will skip this
|
205
|
+
functionally completely.
|
188
206
|
|
189
207
|
### Using markdown files
|
190
208
|
|
191
|
-
If you want to use Markdown files instead of I18n translations, this gem is not
|
209
|
+
If you want to use Markdown files instead of I18n translations, this gem is not
|
210
|
+
for you. Consider using [maildown](https://github.com/schneems/maildown) or
|
211
|
+
[markerb](https://github.com/plataformatec/markerb).
|
192
212
|
|
193
213
|
## Development
|
194
214
|
|
195
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
215
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
216
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
217
|
+
prompt that will allow you to experiment.
|
196
218
|
|
197
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
219
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
220
|
+
release a new version, update the version number in `version.rb`, and then run
|
221
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
222
|
+
git commits and tags, and push the `.gem` file to
|
223
|
+
[rubygems.org](https://rubygems.org).
|
198
224
|
|
199
225
|
## Contributing
|
200
226
|
|
201
|
-
Bug reports and pull requests are welcome on GitHub at
|
202
|
-
|
227
|
+
Bug reports and pull requests are welcome on GitHub at
|
228
|
+
https://github.com/fnando/actionmailer-markdown. This project is intended to be
|
229
|
+
a safe, welcoming space for collaboration, and contributors are expected to
|
230
|
+
adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
203
231
|
|
204
232
|
## License
|
205
233
|
|
206
|
-
The gem is available as open source under the terms of the
|
234
|
+
The gem is available as open source under the terms of the
|
235
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.description = spec.summary
|
12
12
|
spec.homepage = "https://github.com/fnando/actionmailer-markdown"
|
13
13
|
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
14
15
|
|
15
16
|
spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
|
16
17
|
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
@@ -27,6 +28,10 @@ Gem::Specification.new do |spec|
|
|
27
28
|
spec.add_development_dependency "rails"
|
28
29
|
spec.add_development_dependency "rake"
|
29
30
|
spec.add_development_dependency "rubocop"
|
31
|
+
spec.add_development_dependency "rubocop-fnando"
|
30
32
|
spec.add_development_dependency "simplecov"
|
31
33
|
spec.add_development_dependency "simplecov-console"
|
34
|
+
spec.metadata = {
|
35
|
+
"rubygems_mfa_required" => "true"
|
36
|
+
}
|
32
37
|
end
|
@@ -8,18 +8,18 @@ ActionMailer::Base.class_eval do
|
|
8
8
|
subject = get_translation_for("subject", options)
|
9
9
|
headers[:subject] ||= subject
|
10
10
|
headers[:locals] = {a: 1}
|
11
|
-
mail_method.
|
11
|
+
mail_method.bind_call(self, headers, &block)
|
12
12
|
end
|
13
13
|
|
14
14
|
def get_translation_for(key, options)
|
15
|
-
I18n.t(key, options.merge(scope: [mailer_scope, action_name], raise: true))
|
15
|
+
I18n.t(key, **options.merge(scope: [mailer_scope, action_name], raise: true))
|
16
16
|
rescue I18n::MissingTranslationData
|
17
17
|
nil
|
18
18
|
end
|
19
19
|
|
20
20
|
def variables_set_by_user
|
21
21
|
instance_variables.each_with_object({}) do |name, buffer|
|
22
|
-
next if
|
22
|
+
next if /^@_/.match?(name)
|
23
23
|
|
24
24
|
name = name.to_s[/^@(.*?)$/, 1]
|
25
25
|
buffer[name.to_sym] = instance_variable_get("@#{name}")
|
@@ -8,7 +8,13 @@ module ActionMailer
|
|
8
8
|
html: :md
|
9
9
|
}.freeze
|
10
10
|
|
11
|
-
def find_templates(
|
11
|
+
def find_templates(
|
12
|
+
name,
|
13
|
+
prefix,
|
14
|
+
_partial,
|
15
|
+
details,
|
16
|
+
_outside_app_allowed = false # rubocop:disable Style/OptionalBooleanParameter
|
17
|
+
)
|
12
18
|
contents = find_contents(name, prefix, details)
|
13
19
|
return [] unless contents
|
14
20
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionmailer-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop-fnando
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: simplecov
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,9 +199,9 @@ executables: []
|
|
185
199
|
extensions: []
|
186
200
|
extra_rdoc_files: []
|
187
201
|
files:
|
202
|
+
- ".github/FUNDING.yml"
|
188
203
|
- ".gitignore"
|
189
204
|
- ".rubocop.yml"
|
190
|
-
- ".travis.yml"
|
191
205
|
- CODE_OF_CONDUCT.md
|
192
206
|
- Gemfile
|
193
207
|
- LICENSE.txt
|
@@ -207,8 +221,9 @@ files:
|
|
207
221
|
homepage: https://github.com/fnando/actionmailer-markdown
|
208
222
|
licenses:
|
209
223
|
- MIT
|
210
|
-
metadata:
|
211
|
-
|
224
|
+
metadata:
|
225
|
+
rubygems_mfa_required: 'true'
|
226
|
+
post_install_message:
|
212
227
|
rdoc_options: []
|
213
228
|
require_paths:
|
214
229
|
- lib
|
@@ -216,15 +231,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
216
231
|
requirements:
|
217
232
|
- - ">="
|
218
233
|
- !ruby/object:Gem::Version
|
219
|
-
version:
|
234
|
+
version: 2.7.0
|
220
235
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
221
236
|
requirements:
|
222
237
|
- - ">="
|
223
238
|
- !ruby/object:Gem::Version
|
224
239
|
version: '0'
|
225
240
|
requirements: []
|
226
|
-
rubygems_version: 3.
|
227
|
-
signing_key:
|
241
|
+
rubygems_version: 3.2.32
|
242
|
+
signing_key:
|
228
243
|
specification_version: 4
|
229
244
|
summary: A different take on using ActionMailer, Markdown and I18n.
|
230
245
|
test_files: []
|
data/.travis.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
sudo: false
|
4
|
-
rvm:
|
5
|
-
- 2.6.1
|
6
|
-
- 2.5.3
|
7
|
-
- 2.4.1
|
8
|
-
script: bundle exec rake
|
9
|
-
before_script:
|
10
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
11
|
-
- chmod +x ./cc-test-reporter
|
12
|
-
- "./cc-test-reporter before-build"
|
13
|
-
after_script:
|
14
|
-
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
15
|
-
notifications:
|
16
|
-
email: false
|
17
|
-
env:
|
18
|
-
global:
|
19
|
-
secure: pSJLckgoZMZ67Le7TgjbX1ptaeRtPW+IhORZvxoiAR1nVmLCFHOq1ZHSJiw3J0t1A2GMdsTbXH/JDBcrbUzuKgJ3+XIyoAuUa1Hz1UjDkXh4RjwZrG/71hU3x0fVU1JXWDjFkGlqYJqwBYXkX1RK8K30NMnRGi7cr9wOLi0OI7fQ4ImrjIrh7m2hx1mZ97jeZt2HewomPO5OVK4hEDCxKFEzcThE8qOjr1eJRM9yYkwUGvO4Lw7louT95RKbJgjmndKEzbgJ4ggt2wGMvMarOqkM3QNCenp7JaaeaeQNt/szGNYH7bwjDEBNi8bSIIx+jFFpaCoIr/lp12XLDYPgw9dzSeQKLWwXHRDl6GmLNYldXaFfF4OnCaOq68L+0PNz0vD808W3SoTosE7jb5cS3ufRJUMujLRI1Kk2EuG2V0wFpmtCXtBV/LVkhUSqotvjI+ymO1zqyGcPbxVGO6WpIxMhiFC7+ZGsdOm0aliAMd6dAZ/6UPWGTSdMR6MECaCDtqBFv8JCnybWr5xxG3gnR9vqanA3sgrGjWxEIJrtF59vcPgrI6SUM7d4a7FBWHMU0AZSRvVX2umiTZVy/DOJEL/j0COunbcogCbTuAN1/gSNWTUTmF6kIV4BYUYEYx4HnpegIKcYKHKv74nbV4bhaSNuj+M/xOVPb2+Ms5kuG8E=
|