actionmailer-markdown 0.4.1 → 0.4.3
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 +47 -21
- data/Rakefile +1 -1
- data/actionmailer-markdown.gemspec +5 -0
- data/lib/action_mailer/markdown/ext.rb +3 -4
- 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: 3ebe1db37d8bd6b28e2831cb9d82b40588c8e941017b5f760bd2e2f05c8b89ce
|
4
|
+
data.tar.gz: 24f0b8c284ecbd0709914ad1b682fb2b24d5736f4e718a8bd9c4e1595faf47a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abb1f8588b16bcce4f51a63a51f24e91dc21d451e888791a1baa8c728c2a7ec0293359ac1c41731ce6aa0cef7eb618d73326252174ed0194f6285d26e833fdd5
|
7
|
+
data.tar.gz: 3a9a020648059ef34ac7be7f5add29efd8d9b4a95484ca6b8ffdbc868e37251850ebc4b58c141958e0f4eca441709436a01652642394e2f26c305f2f48677049
|
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,8 +1,5 @@
|
|
1
1
|
# ActionMailer::Markdown
|
2
2
|
|
3
|
-
[![Travis-CI](https://travis-ci.org/fnando/actionmailer-markdown.png)](https://travis-ci.org/fnando/actionmailer-markdown)
|
4
|
-
[![Code Climate](https://codeclimate.com/github/fnando/actionmailer-markdown/badges/gpa.svg)](https://codeclimate.com/github/fnando/actionmailer-markdown)
|
5
|
-
[![Test Coverage](https://codeclimate.com/github/fnando/actionmailer-markdown/badges/coverage.svg)](https://codeclimate.com/github/fnando/actionmailer-markdown/coverage)
|
6
3
|
[![Gem](https://img.shields.io/gem/v/actionmailer-markdown.svg)](https://rubygems.org/gems/actionmailer-markdown)
|
7
4
|
[![Gem](https://img.shields.io/gem/dt/actionmailer-markdown.svg)](https://rubygems.org/gems/actionmailer-markdown)
|
8
5
|
|
@@ -26,7 +23,9 @@ Or install it yourself as:
|
|
26
23
|
|
27
24
|
## Usage
|
28
25
|
|
29
|
-
Imagine that you have a mail named `UserMailer#welcome`. Instead of manually
|
26
|
+
Imagine that you have a mail named `UserMailer#welcome`. Instead of manually
|
27
|
+
defining your subjects like the following, you can create the subject by
|
28
|
+
defining the `user_mailer.welcome.subject` translation.
|
30
29
|
|
31
30
|
```ruby
|
32
31
|
# app/mailers/user_mailer.rb
|
@@ -45,7 +44,9 @@ en:
|
|
45
44
|
subject: Welcome to my app
|
46
45
|
```
|
47
46
|
|
48
|
-
Since I really like defining everything I can in I18n files, I always extend
|
47
|
+
Since I really like defining everything I can in I18n files, I always extend
|
48
|
+
this behavior to the message's body, through the `user_mailer.welcome.body`
|
49
|
+
translation.
|
49
50
|
|
50
51
|
```yaml
|
51
52
|
# config/locales/en.yml
|
@@ -60,7 +61,8 @@ en:
|
|
60
61
|
Myapp team
|
61
62
|
```
|
62
63
|
|
63
|
-
Did you notice that `|`? That allows YAML strings to be multiline. And on your
|
64
|
+
Did you notice that `|`? That allows YAML strings to be multiline. And on your
|
65
|
+
e-mail class you can do something like this:
|
64
66
|
|
65
67
|
```ruby
|
66
68
|
# app/mailers/user_mailer.rb
|
@@ -71,7 +73,8 @@ class UserMailer < ApplicationMailer
|
|
71
73
|
end
|
72
74
|
```
|
73
75
|
|
74
|
-
And if you want to render HTML and text-plain from this string, you may have to
|
76
|
+
And if you want to render HTML and text-plain from this string, you may have to
|
77
|
+
do something like this (Markdown class not shown).
|
75
78
|
|
76
79
|
```ruby
|
77
80
|
# app/mailers/user_mailer.rb
|
@@ -87,7 +90,8 @@ class UserMailer < ApplicationMailer
|
|
87
90
|
end
|
88
91
|
```
|
89
92
|
|
90
|
-
This idea is really nice, but you have too much things to deal with. Not
|
93
|
+
This idea is really nice, but you have too much things to deal with. Not
|
94
|
+
anymore!
|
91
95
|
|
92
96
|
With ActionMailer::Markdown you can just define your mailer action like this:
|
93
97
|
|
@@ -100,17 +104,20 @@ class UserMailer < ApplicationMailer
|
|
100
104
|
end
|
101
105
|
```
|
102
106
|
|
103
|
-
That's right! This gem automatically uses `user_mailer.welcome.{subject,body}`
|
107
|
+
That's right! This gem automatically uses `user_mailer.welcome.{subject,body}`
|
108
|
+
from your translation files. And the best part: it evens supports Markdown.
|
104
109
|
|
105
110
|
### Passing variables
|
106
111
|
|
107
|
-
You're likely to pass in variables to your messages. To do this, just define
|
112
|
+
You're likely to pass in variables to your messages. To do this, just define
|
113
|
+
instance variables. Imagine you want to parse the user's name on your subject
|
114
|
+
and message. Let's suppose you have your translation file defined like this:
|
108
115
|
|
109
116
|
```yaml
|
110
117
|
en:
|
111
118
|
user_mailer:
|
112
119
|
welcome:
|
113
|
-
subject:
|
120
|
+
subject: "Welcome to Myapp, %{name}"
|
114
121
|
body: |
|
115
122
|
Hello, %{name}. And welcome to Myapp.
|
116
123
|
```
|
@@ -156,7 +163,8 @@ en:
|
|
156
163
|
Myapp team
|
157
164
|
```
|
158
165
|
|
159
|
-
You may be wondering what happens with the mail's text part. Don't worry!
|
166
|
+
You may be wondering what happens with the mail's text part. Don't worry!
|
167
|
+
ActionMailer::Markdown will take care of that. That message will be rendered as:
|
160
168
|
|
161
169
|
```text
|
162
170
|
Hello, John!
|
@@ -172,11 +180,16 @@ Myapp team
|
|
172
180
|
|
173
181
|
Lists and other elements are also exported to a more friendly text version.
|
174
182
|
|
175
|
-
**PROTIP:** Use [i18n-dot_lookup](https://github.com/fnando/i18n-dot_lookup) if
|
183
|
+
**PROTIP:** Use [i18n-dot_lookup](https://github.com/fnando/i18n-dot_lookup) if
|
184
|
+
you want to access properties from an object, like `%{user.name}`
|
176
185
|
|
177
186
|
### Replacing the Markdown engine
|
178
187
|
|
179
|
-
[redcarpet](https://github.com/vmg/redcarpet) is the default Markdown parser.
|
188
|
+
[redcarpet](https://github.com/vmg/redcarpet) is the default Markdown parser.
|
189
|
+
You may want to specify different options or even switch out to a different
|
190
|
+
Markdown library. All you have to do is defining a processor that responds to
|
191
|
+
`.call`. Let's say you want to use [kramdown](http://kramdown.gettalong.org/) as
|
192
|
+
your Markdown engine.
|
180
193
|
|
181
194
|
```ruby
|
182
195
|
ActionMailer::Markdown.processor = -> text { Kramdown::Document.new(text).to_html }
|
@@ -184,23 +197,36 @@ ActionMailer::Markdown.processor = -> text { Kramdown::Document.new(text).to_htm
|
|
184
197
|
|
185
198
|
### Falling back to ActionMailer's default behavior
|
186
199
|
|
187
|
-
You can use templates if you want. Just don't define the `.body` part of your
|
200
|
+
You can use templates if you want. Just don't define the `.body` part of your
|
201
|
+
translation. Also, if you pass a block to the `mail()` method, it will skip this
|
202
|
+
functionally completely.
|
188
203
|
|
189
204
|
### Using markdown files
|
190
205
|
|
191
|
-
If you want to use Markdown files instead of I18n translations, this gem is not
|
206
|
+
If you want to use Markdown files instead of I18n translations, this gem is not
|
207
|
+
for you. Consider using [maildown](https://github.com/schneems/maildown) or
|
208
|
+
[markerb](https://github.com/plataformatec/markerb).
|
192
209
|
|
193
210
|
## Development
|
194
211
|
|
195
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
212
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
213
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
214
|
+
prompt that will allow you to experiment.
|
196
215
|
|
197
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
216
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
217
|
+
release a new version, update the version number in `version.rb`, and then run
|
218
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
219
|
+
git commits and tags, and push the `.gem` file to
|
220
|
+
[rubygems.org](https://rubygems.org).
|
198
221
|
|
199
222
|
## Contributing
|
200
223
|
|
201
|
-
Bug reports and pull requests are welcome on GitHub at
|
202
|
-
|
224
|
+
Bug reports and pull requests are welcome on GitHub at
|
225
|
+
https://github.com/fnando/actionmailer-markdown. This project is intended to be
|
226
|
+
a safe, welcoming space for collaboration, and contributors are expected to
|
227
|
+
adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
203
228
|
|
204
229
|
## License
|
205
230
|
|
206
|
-
The gem is available as open source under the terms of the
|
231
|
+
The gem is available as open source under the terms of the
|
232
|
+
[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
|
@@ -7,19 +7,18 @@ ActionMailer::Base.class_eval do
|
|
7
7
|
options = variables_set_by_user
|
8
8
|
subject = get_translation_for("subject", options)
|
9
9
|
headers[:subject] ||= subject
|
10
|
-
headers
|
11
|
-
mail_method.bind(self).call(headers, &block)
|
10
|
+
mail_method.bind_call(self, headers, &block)
|
12
11
|
end
|
13
12
|
|
14
13
|
def get_translation_for(key, options)
|
15
|
-
I18n.t(key, options.merge(scope: [mailer_scope, action_name], raise: true))
|
14
|
+
I18n.t(key, **options.merge(scope: [mailer_scope, action_name], raise: true))
|
16
15
|
rescue I18n::MissingTranslationData
|
17
16
|
nil
|
18
17
|
end
|
19
18
|
|
20
19
|
def variables_set_by_user
|
21
20
|
instance_variables.each_with_object({}) do |name, buffer|
|
22
|
-
next if
|
21
|
+
next if /^@_/.match?(name)
|
23
22
|
|
24
23
|
name = name.to_s[/^@(.*?)$/, 1]
|
25
24
|
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.3
|
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: 2023-01-09 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.4.1
|
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=
|