actionmailer-markdown 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +2 -2
- data/actionmailer-markdown.gemspec +1 -0
- data/lib/action_mailer/markdown.rb +7 -0
- data/lib/action_mailer/markdown/ext.rb +4 -13
- data/lib/action_mailer/markdown/renderer/text.rb +1 -1
- data/lib/action_mailer/markdown/resolver.rb +45 -0
- data/lib/action_mailer/markdown/template_handler.rb +33 -0
- data/lib/action_mailer/markdown/version.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 286269f0bc2b88e8598c2dfe0c3082b57664155d
|
4
|
+
data.tar.gz: 5ee1501c9776bf0027a19d4173712de98db8aa9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 577bb5245e8c6111a0b9758ac09dd7254ca8c1c764910b5f62d931530958ca703ae6644ebf990631f84993ca5ca596ee073389a4fc7d584df0c6f6701904229e
|
7
|
+
data.tar.gz: 1091e0b11499b8b098aa36bc5b8d58ce5d55a737d065caa6f4e4023a8ecab38ea7fc3b89193eb01a5e28b381a99511cccd1cb7468a1f7b5541629d5d777b1c44
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActionMailer::Markdown
|
2
2
|
|
3
|
-
![build status](https://travis-ci.org/fnando/actionmailer-markdown.svg)
|
3
|
+
[![build status](https://travis-ci.org/fnando/actionmailer-markdown.svg)](https://travis-ci.org/fnando/actionmailer-markdown)
|
4
4
|
|
5
5
|
A different take on using ActionMailer, Markdown and I18n.
|
6
6
|
|
@@ -194,7 +194,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
194
194
|
|
195
195
|
## Contributing
|
196
196
|
|
197
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
197
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/actionmailer-markdown. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
198
198
|
|
199
199
|
|
200
200
|
## License
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
21
21
|
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rails'
|
22
23
|
spec.add_development_dependency 'minitest'
|
23
24
|
spec.add_development_dependency 'minitest-utils'
|
24
25
|
spec.add_development_dependency 'pry-meta'
|
@@ -1,11 +1,18 @@
|
|
1
1
|
module ActionMailer
|
2
2
|
module Markdown
|
3
3
|
require 'action_mailer'
|
4
|
+
require 'action_view'
|
4
5
|
require 'redcarpet'
|
5
6
|
|
6
7
|
require 'action_mailer/markdown/version'
|
8
|
+
require 'action_mailer/markdown/resolver'
|
7
9
|
require 'action_mailer/markdown/ext'
|
8
10
|
require 'action_mailer/markdown/renderer'
|
9
11
|
require 'action_mailer/markdown/renderer/text'
|
12
|
+
require 'action_mailer/markdown/template_handler'
|
10
13
|
end
|
11
14
|
end
|
15
|
+
|
16
|
+
ActionMailer::Base.prepend_view_path(ActionMailer::Markdown::Resolver.new)
|
17
|
+
ActionView::Template.register_template_handler(:md, ActionMailer::Markdown::TemplateHandler::HTML)
|
18
|
+
ActionView::Template.register_template_handler(:mdt, ActionMailer::Markdown::TemplateHandler::Text)
|
@@ -3,24 +3,11 @@ ActionMailer::Base.class_eval do
|
|
3
3
|
|
4
4
|
define_method(:mail) do |headers = {}, &block|
|
5
5
|
options = variables_set_by_user
|
6
|
-
message = get_translation_for('body', options)
|
7
6
|
subject = get_translation_for('subject', options)
|
8
7
|
headers[:subject] ||= subject
|
9
|
-
|
10
|
-
if message
|
11
|
-
block = proc do |format|
|
12
|
-
format.text { render plain: ActionMailer::Markdown.text(message) }
|
13
|
-
format.html { render html: ActionMailer::Markdown.html(message).html_safe }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
8
|
mail_method.bind(self).call(headers, &block)
|
18
9
|
end
|
19
10
|
|
20
|
-
def mailer_scope
|
21
|
-
self.class.mailer_name.tr('/', '.')
|
22
|
-
end
|
23
|
-
|
24
11
|
def get_translation_for(key, options)
|
25
12
|
I18n.t(key, options.merge(scope: [mailer_scope, action_name], raise: true))
|
26
13
|
rescue I18n::MissingTranslationData
|
@@ -34,4 +21,8 @@ ActionMailer::Base.class_eval do
|
|
34
21
|
buffer[name.to_sym] = instance_variable_get("@#{name}")
|
35
22
|
end
|
36
23
|
end
|
24
|
+
|
25
|
+
def mailer_scope
|
26
|
+
self.class.mailer_name.tr('/', '.')
|
27
|
+
end
|
37
28
|
end
|
@@ -72,7 +72,7 @@ module ActionMailer
|
|
72
72
|
end
|
73
73
|
|
74
74
|
links_list = links.map.with_index(1) {|link, index| "[#{index}]: #{link}" }.join("\n")
|
75
|
-
node = Nokogiri::HTML.fragment "<pre
|
75
|
+
node = Nokogiri::HTML.fragment "<pre>\n#{links_list}\n</pre>"
|
76
76
|
|
77
77
|
root << node
|
78
78
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ActionMailer
|
2
|
+
module Markdown
|
3
|
+
class Resolver < ActionView::Resolver
|
4
|
+
FORMAT_TO_EXTENSION = {
|
5
|
+
text: :mdt,
|
6
|
+
html: :md
|
7
|
+
}
|
8
|
+
|
9
|
+
def find_templates(name, prefix, partial, details)
|
10
|
+
contents = find_contents(name, prefix, details)
|
11
|
+
return [] unless contents
|
12
|
+
|
13
|
+
%i[html text].map do |format|
|
14
|
+
identifier = "#{prefix}##{name} (#{format})"
|
15
|
+
path = virtual_path(name, prefix)
|
16
|
+
build_template(path, contents, identifier, format)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def build_template(path, contents, identifier, format)
|
21
|
+
ActionView::Template.new(contents, identifier, handler_for(format),
|
22
|
+
virtual_path: path,
|
23
|
+
format: format
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def handler_for(format)
|
28
|
+
ActionView::Template
|
29
|
+
.registered_template_handler(FORMAT_TO_EXTENSION.fetch(format))
|
30
|
+
end
|
31
|
+
|
32
|
+
def virtual_path(name, prefix)
|
33
|
+
"#{prefix}/#{name}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_contents(name, prefix, details)
|
37
|
+
key = [prefix, name, :body].join(I18n.default_separator)
|
38
|
+
|
39
|
+
I18n.with_locale(details[:locale].first || I18n.locale) do
|
40
|
+
I18n.t(key, raise: true) rescue nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ActionMailer
|
2
|
+
module Markdown
|
3
|
+
module TemplateHandler
|
4
|
+
UNDERSCORE = '_'.freeze
|
5
|
+
|
6
|
+
def self.render(template, context, format)
|
7
|
+
source = template.rstrip % extract_variables(context)
|
8
|
+
ActionMailer::Markdown.public_send(format, source)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.extract_variables(context)
|
12
|
+
context
|
13
|
+
.instance_variable_get(:@_assigns)
|
14
|
+
.each_with_object({}) do |(name, value), buffer|
|
15
|
+
next if name.start_with?(UNDERSCORE)
|
16
|
+
buffer[name.to_sym] = value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Text
|
21
|
+
def self.call(template)
|
22
|
+
%[ActionMailer::Markdown::TemplateHandler.render(#{template.source.inspect}, self, :text)]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class HTML
|
27
|
+
def self.call(template)
|
28
|
+
%[ActionMailer::Markdown::TemplateHandler.render(#{template.source.inspect}, self, :html)]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
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
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
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'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: minitest
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,6 +157,8 @@ files:
|
|
143
157
|
- lib/action_mailer/markdown/ext.rb
|
144
158
|
- lib/action_mailer/markdown/renderer.rb
|
145
159
|
- lib/action_mailer/markdown/renderer/text.rb
|
160
|
+
- lib/action_mailer/markdown/resolver.rb
|
161
|
+
- lib/action_mailer/markdown/template_handler.rb
|
146
162
|
- lib/action_mailer/markdown/version.rb
|
147
163
|
- lib/actionmailer-markdown.rb
|
148
164
|
homepage: https://github.com/fnando/actionmailer-markdown
|
@@ -165,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
181
|
version: '0'
|
166
182
|
requirements: []
|
167
183
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.4.
|
184
|
+
rubygems_version: 2.4.5.1
|
169
185
|
signing_key:
|
170
186
|
specification_version: 4
|
171
187
|
summary: A different take on using ActionMailer, Markdown and I18n.
|