locale_mailer 0.2.2 → 0.2.3
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/lib/locale_mailer/concern.rb +52 -59
- data/lib/locale_mailer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 991fd4e039b610e59c3a7931e3ac33152c91cb14
|
|
4
|
+
data.tar.gz: e896a44e5623e26fd90da6ea88941ce587f660cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a60553225e034aa5af897f3c68d1af9d0c8abadf0abf477edb977ee909d663bda8b915c4dfdc855e3c7fffbfcd02e7c83219b460d0f3735d7efea51e780c3302
|
|
7
|
+
data.tar.gz: 61aba9f059b18ec8d5d85f15a3f63c911f3af38a72cecd758c496c928723bec07f2ab1d0615505d93be4cb3dcf751b4e15e313821a29a8e0398128427cc9032b
|
|
@@ -20,84 +20,77 @@ module LocaleMailer
|
|
|
20
20
|
included do
|
|
21
21
|
alias_method_chain :mail, :localized_templates
|
|
22
22
|
private :mail, :mail_with_localized_templates, :mail_without_localized_templates
|
|
23
|
+
helper_method :action_i18n_options, :action_i18n_path
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
private
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
mail_without_localized_templates options do |format|
|
|
44
|
-
html_body = body_from_locale i18n_path(options), locale_options, options
|
|
45
|
-
format.html {
|
|
46
|
-
html_body
|
|
47
|
-
}
|
|
48
|
-
format.text {
|
|
49
|
-
Loofah.scrub_fragment(html_body, LocaleMailer::A2HREF).to_text
|
|
50
|
-
}
|
|
51
|
-
end
|
|
52
|
-
else
|
|
53
|
-
raise e
|
|
28
|
+
def mail_with_localized_templates(options = {}, &block)
|
|
29
|
+
begin
|
|
30
|
+
mail_without_localized_templates(options, &block)
|
|
31
|
+
rescue ActionView::MissingTemplate => e
|
|
32
|
+
options.symbolize_keys!
|
|
33
|
+
|
|
34
|
+
if I18n.exists? action_i18n_path(options), I18n.locale
|
|
35
|
+
options[:subject] = subject_from_locale(options) unless options.key?(:subject)
|
|
36
|
+
mail_without_localized_templates options do |format|
|
|
37
|
+
html_body = body_from_locale options
|
|
38
|
+
format.html {
|
|
39
|
+
html_body
|
|
40
|
+
}
|
|
41
|
+
format.text {
|
|
42
|
+
Loofah.scrub_fragment(html_body, LocaleMailer::A2HREF).to_text
|
|
43
|
+
}
|
|
54
44
|
end
|
|
45
|
+
else
|
|
46
|
+
raise e
|
|
55
47
|
end
|
|
56
48
|
end
|
|
49
|
+
end
|
|
57
50
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
def action_i18n_path options = {}
|
|
52
|
+
@action_i18n_path ||= [
|
|
53
|
+
Rails.configuration.locale_mailer_path_prefix,
|
|
54
|
+
(options[:template_path] || mailer_name.gsub('/','.').underscore),
|
|
55
|
+
(options[:template_name] || action_name)
|
|
56
|
+
].compact.join('.')
|
|
57
|
+
end
|
|
65
58
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
end
|
|
73
|
-
else
|
|
74
|
-
memo[name.to_s.gsub(/\A@/,'').to_sym] = instance_variable_get(name)
|
|
59
|
+
def action_i18n_options
|
|
60
|
+
@action_i18n_options ||= instance_variables.inject({}) do |memo, name|
|
|
61
|
+
if name.to_s.match(/\A@(?!_).*/) and not name.to_s.match(/\A@action_i18n_/)
|
|
62
|
+
if instance_variable_get(name).try(:as_json).is_a? Hash
|
|
63
|
+
flatten_hash(instance_variable_get(name).as_json).each do |(k,v)|
|
|
64
|
+
memo["#{name.to_s.gsub(/\A@/,'')}_#{k}".to_sym] = v
|
|
75
65
|
end
|
|
66
|
+
else
|
|
67
|
+
memo[name.to_s.gsub(/\A@/,'').to_sym] = instance_variable_get(name)
|
|
76
68
|
end
|
|
77
|
-
memo
|
|
78
69
|
end
|
|
70
|
+
memo
|
|
79
71
|
end
|
|
72
|
+
end
|
|
80
73
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
end
|
|
87
|
-
else
|
|
88
|
-
h[k] = v
|
|
74
|
+
def flatten_hash(hash)
|
|
75
|
+
hash.each_with_object({}) do |(k, v), h|
|
|
76
|
+
if v.is_a? Hash
|
|
77
|
+
flatten_hash(v).map do |h_k, h_v|
|
|
78
|
+
h["#{k}_#{h_k}".to_sym] = h_v
|
|
89
79
|
end
|
|
80
|
+
else
|
|
81
|
+
h[k] = v
|
|
90
82
|
end
|
|
91
83
|
end
|
|
84
|
+
end
|
|
92
85
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
def subject_from_locale options
|
|
87
|
+
view_context.t([action_i18n_path(options), :subject].join('.'), action_i18n_options)
|
|
88
|
+
end
|
|
96
89
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
90
|
+
def body_from_locale options
|
|
91
|
+
render inline: view_context.text([action_i18n_path(options), :body].join('.'), action_i18n_options),
|
|
92
|
+
layout: options[:layout] || _layout
|
|
93
|
+
end
|
|
101
94
|
|
|
102
95
|
end
|
|
103
96
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: locale_mailer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- itkin
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-05-
|
|
11
|
+
date: 2016-05-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionmailer
|