maily 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/MIT-LICENSE +1 -1
- data/README.md +52 -14
- data/app/controllers/maily/application_controller.rb +11 -0
- data/app/controllers/maily/emails_controller.rb +3 -3
- data/app/helpers/maily/application_helper.rb +7 -3
- data/app/helpers/maily/emails_helper.rb +10 -3
- data/app/views/maily/emails/edit.html.erb +2 -2
- data/app/views/maily/emails/show.html.erb +15 -4
- data/app/views/maily/shared/_sidebar.html.erb +10 -3
- data/app/views/maily/shared/_stylesheet.html.erb +49 -37
- data/lib/generators/templates/initializer.rb +4 -4
- data/lib/maily.rb +3 -3
- data/lib/maily/email.rb +31 -9
- data/lib/maily/mailer.rb +17 -6
- data/lib/maily/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 721693235607563d7fda7fe34ed96eff26e86fcabceb019a32184e5506126e1b
|
4
|
+
data.tar.gz: 201cd2af6c1ca7ada68fd48dca697a94a7d8e958a80c19c7c2593f63700d62ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e410e43169c4a770d6a2269884bad4b6a4256092ffbbcf5958ef97316cb50e1a505fac6743a3243654f7b2c2fbbd956c5a07e8f51959cb43dd6890e09c59c09f
|
7
|
+
data.tar.gz: a582fb52e7648b19779b202588405365c165a92dc92fd9f83b6190b50a65f38bee647247ea7bc86158be2b239342fda8ebaa7aca68ddb5b13009d1c34ed700f7
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [2.0.0]
|
6
|
+
|
7
|
+
- Email versions (#49)
|
8
|
+
- Drop official support for EOL Rails versions: 5.1, 5.0 and 4.2
|
9
|
+
- Drop official support for EOL Rubies: 2.4
|
10
|
+
|
5
11
|
## [1.0.0]
|
6
12
|
|
7
13
|
- Avoid the dependency on Sprockets (#48)
|
@@ -143,6 +149,7 @@ All notable changes to this project will be documented in this file.
|
|
143
149
|
|
144
150
|
- First real usable release :tada:
|
145
151
|
|
152
|
+
[2.0.0]: https://github.com/markets/maily/compare/v1.0.0...v2.0.0
|
146
153
|
[1.0.0]: https://github.com/markets/maily/compare/v0.12.3...v1.0.0
|
147
154
|
[0.12.3]: https://github.com/markets/maily/compare/v0.12.2...v0.12.3
|
148
155
|
[0.12.2]: https://github.com/markets/maily/compare/v0.12.1...v0.12.2
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -50,27 +50,20 @@ This generator runs some tasks for you:
|
|
50
50
|
|
51
51
|
## Initialization and configuration
|
52
52
|
|
53
|
-
You should
|
54
|
-
|
55
|
-
```ruby
|
56
|
-
Maily.enabled = ENV['MAILY_ENABLED']
|
57
|
-
|
58
|
-
Maily.enabled = Rails.env.production? ? false : true
|
59
|
-
```
|
60
|
-
|
61
|
-
Initializer sample (full options list):
|
53
|
+
You should use the `setup` method to configure and customize `Maily` settings:
|
62
54
|
|
63
55
|
```ruby
|
64
56
|
# config/initializers/maily.rb
|
57
|
+
|
65
58
|
Maily.setup do |config|
|
66
59
|
# On/off engine
|
67
|
-
# config.enabled = Rails.env.production?
|
60
|
+
# config.enabled = !Rails.env.production?
|
68
61
|
|
69
62
|
# Allow templates edition
|
70
|
-
# config.allow_edition = Rails.env.production?
|
63
|
+
# config.allow_edition = !Rails.env.production?
|
71
64
|
|
72
65
|
# Allow deliveries
|
73
|
-
# config.allow_delivery = Rails.env.production?
|
66
|
+
# config.allow_delivery = !Rails.env.production?
|
74
67
|
|
75
68
|
# Your application available_locales (or I18n.available_locales) by default
|
76
69
|
# config.available_locales = [:en, :es, :pt, :fr]
|
@@ -89,6 +82,13 @@ Maily.setup do |config|
|
|
89
82
|
end
|
90
83
|
```
|
91
84
|
|
85
|
+
You can use the following format too:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
Maily.enabled = ENV['MAILY_ENABLED']
|
89
|
+
Maily.allow_edition = false
|
90
|
+
```
|
91
|
+
|
92
92
|
### Templates edition (`allow_edition` option)
|
93
93
|
|
94
94
|
This feature was designed for the `development` environment. Since it's based on just a file edition, and while running in `production` mode, code is not reloaded between requests, Rails doesn't take into account your changes (without restarting the server). Actually, allowing arbitrary Ruby code evaluation is potentially dangerous, and that's not a good idea in `production`.
|
@@ -101,6 +101,7 @@ Most of emails need to populate some data to consume it and do interesting thing
|
|
101
101
|
|
102
102
|
```ruby
|
103
103
|
# lib/maily_hooks.rb
|
104
|
+
|
104
105
|
user = User.new(email: 'user@example.com')
|
105
106
|
lazy_user = -> { User.with_comments.first } # callable object, lazy evaluation
|
106
107
|
comment = Struct.new(:body).new('Lorem ipsum') # stub way
|
@@ -125,6 +126,20 @@ Maily.hooks_for('YourMailerClass') do |mailer|
|
|
125
126
|
end
|
126
127
|
```
|
127
128
|
|
129
|
+
### Email versions
|
130
|
+
|
131
|
+
You can add versions for special emails. This is useful in some cases where template content depends on the parameters you provide, for instance, a welcome message for trial accounts and gold accounts.
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
free_trial_account = -> { Account.free_trial.first }
|
135
|
+
gold_account = -> { Account.gold.first }
|
136
|
+
|
137
|
+
Maily.hooks_for('Notifier') do |mailer|
|
138
|
+
mailer.register_hook(:welcome, free_trial_account, version: 'Free trial account')
|
139
|
+
mailer.register_hook(:welcome, gold_account, version: 'Gold account')
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
128
143
|
### Email description
|
129
144
|
|
130
145
|
You can add a description to any email and it will be displayed along with its preview. This is useful in some cases like: someone from another team, for example, a marketing specialist, visiting Maily to review some texts and images; they can easily understand when this email is sent by the system.
|
@@ -209,7 +224,7 @@ Maily.http_authorization = { username: 'admin', password: 'secret' }
|
|
209
224
|
|
210
225
|
Rails 4.1 introduced a built-in mechanism to preview the application emails. It is in fact, a port of [basecamp/mail_view](https://github.com/basecamp/mail_view) gem to the core.
|
211
226
|
|
212
|
-
Alternatively, there are
|
227
|
+
Alternatively, there are more gems out there to get a similar functionality, but with different approaches and features. Like for example: [ryanb/letter_opener](https://github.com/ryanb/letter_opener), [sj26/mailcatcher](https://github.com/sj26/mailcatcher) or [glebm/rails_email_preview](https://github.com/glebm/rails_email_preview).
|
213
228
|
|
214
229
|
## Development
|
215
230
|
|
@@ -217,7 +232,30 @@ Any kind of feedback, bug report, idea or enhancement are really appreciated :ta
|
|
217
232
|
|
218
233
|
To contribute, just fork the repo, hack on it and send a pull request. Don't forget to add tests for behaviour changes and run the test suite:
|
219
234
|
|
220
|
-
|
235
|
+
```
|
236
|
+
> bundle exec rake
|
237
|
+
```
|
238
|
+
|
239
|
+
Run the test suite against all supported versions:
|
240
|
+
|
241
|
+
```
|
242
|
+
> bundle exec appraisal install
|
243
|
+
> bundle exec appraisal rake
|
244
|
+
```
|
245
|
+
|
246
|
+
Run specs against specific version:
|
247
|
+
|
248
|
+
```
|
249
|
+
> bundle exec appraisal rails-6.0 rake
|
250
|
+
```
|
251
|
+
|
252
|
+
### Demo
|
253
|
+
|
254
|
+
Start a sample Rails app ([source code](spec/dummy)) with `Maily` integrated:
|
255
|
+
|
256
|
+
```
|
257
|
+
> bundle exec rake web # PORT=4000 (default: 3000)
|
258
|
+
```
|
221
259
|
|
222
260
|
## License
|
223
261
|
|
@@ -4,6 +4,17 @@ module Maily
|
|
4
4
|
|
5
5
|
layout 'maily/application'
|
6
6
|
|
7
|
+
def maily_params
|
8
|
+
_params = {}
|
9
|
+
|
10
|
+
[:mailer, :email, :version, :part, :locale, :version].each do |key|
|
11
|
+
_params[key] = params[key] if params[key].present?
|
12
|
+
end
|
13
|
+
|
14
|
+
_params
|
15
|
+
end
|
16
|
+
helper_method :maily_params
|
17
|
+
|
7
18
|
private
|
8
19
|
|
9
20
|
def maily_enabled?
|
@@ -43,7 +43,7 @@ module Maily
|
|
43
43
|
def update
|
44
44
|
@maily_email.update_template(params[:body], params[:part])
|
45
45
|
|
46
|
-
redirect_to maily_email_path(
|
46
|
+
redirect_to maily_email_path(maily_params), notice: 'Template updated!'
|
47
47
|
end
|
48
48
|
|
49
49
|
def deliver
|
@@ -51,7 +51,7 @@ module Maily
|
|
51
51
|
|
52
52
|
@email.deliver
|
53
53
|
|
54
|
-
redirect_to maily_email_path(
|
54
|
+
redirect_to maily_email_path(maily_params), notice: "Email sent to <b>#{params[:to]}</b>!"
|
55
55
|
end
|
56
56
|
|
57
57
|
private
|
@@ -66,7 +66,7 @@ module Maily
|
|
66
66
|
|
67
67
|
def load_mailer_and_email
|
68
68
|
mailer = Maily::Mailer.find(params[:mailer])
|
69
|
-
@maily_email = mailer.find_email(params[:email])
|
69
|
+
@maily_email = mailer.find_email(params[:email], params[:version])
|
70
70
|
|
71
71
|
if @maily_email
|
72
72
|
@email = @maily_email.call
|
@@ -14,18 +14,22 @@ module Maily
|
|
14
14
|
'selected_mail' if mailer.name == params[:mailer] && email.name == params[:email]
|
15
15
|
end
|
16
16
|
|
17
|
+
def version_list_class(email)
|
18
|
+
'selected_mail' if email.name == params[:email] && email.version == params[:version]
|
19
|
+
end
|
20
|
+
|
17
21
|
def logo
|
18
|
-
image_tag(file_to_base64('
|
22
|
+
image_tag(file_to_base64('logo.png', 'image/png'))
|
19
23
|
end
|
20
24
|
|
21
25
|
def icon(name)
|
22
|
-
image_tag(file_to_base64("
|
26
|
+
image_tag(file_to_base64("icons/#{name}.svg", 'image/svg+xml'), class: :icon)
|
23
27
|
end
|
24
28
|
|
25
29
|
private
|
26
30
|
|
27
31
|
def file_to_base64(path, mime_type)
|
28
|
-
file = Maily::Engine.root.join('app/assets/images').join(path)
|
32
|
+
file = Maily::Engine.root.join('app/assets/images/maily').join(path)
|
29
33
|
base64_contents = Base64.strict_encode64(file.read)
|
30
34
|
|
31
35
|
"data:#{mime_type};base64,#{base64_contents}"
|
@@ -7,14 +7,21 @@ module Maily
|
|
7
7
|
def email_description(email)
|
8
8
|
return unless email.description
|
9
9
|
|
10
|
-
|
11
|
-
concat
|
10
|
+
tag.div(class: 'mail_description') do
|
11
|
+
concat tag.strong('Description ')
|
12
12
|
concat email.description
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def part_class(part)
|
17
|
-
'format_selected' if
|
17
|
+
'format_selected' if part == params[:part] || (part == 'html' && !params[:part])
|
18
|
+
end
|
19
|
+
|
20
|
+
def uniq_emails(email_list)
|
21
|
+
email_list.inject([]) do |memo, email|
|
22
|
+
memo << email unless memo.map(&:name).include?(email.name)
|
23
|
+
memo
|
24
|
+
end
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<%= email_description(@maily_email) %>
|
2
2
|
|
3
|
-
<%= form_tag(update_maily_email_path(
|
3
|
+
<%= form_tag(update_maily_email_path(maily_params), method: :put) do %>
|
4
4
|
<ul class="action_bar">
|
5
5
|
<li>
|
6
|
-
<%= link_to 'Show', maily_email_path(
|
6
|
+
<%= link_to 'Show', maily_email_path(maily_params) %>
|
7
7
|
</li>
|
8
8
|
|
9
9
|
<li class="splitter">|</li>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
<ul class="action_bar">
|
4
4
|
<li>
|
5
|
-
<%= link_to 'Edit', edit_maily_email_path(
|
5
|
+
<%= link_to 'Edit', edit_maily_email_path(maily_params) %>
|
6
6
|
</li>
|
7
7
|
|
8
8
|
<li class="languages">
|
@@ -21,7 +21,7 @@
|
|
21
21
|
<li class="splitter">|</li>
|
22
22
|
|
23
23
|
<li>
|
24
|
-
<%= form_tag(deliver_maily_email_path(
|
24
|
+
<%= form_tag(deliver_maily_email_path(maily_params), method: :post, class: 'mail_deliver') do %>
|
25
25
|
<ul>
|
26
26
|
<li>Send to</li>
|
27
27
|
<li><%= email_field_tag :to, nil, placeholder: "Enter email", required: true %></li>
|
@@ -31,6 +31,17 @@
|
|
31
31
|
</li>
|
32
32
|
</ul>
|
33
33
|
|
34
|
+
<% if @maily_email.has_versions? %>
|
35
|
+
<fieldset class="version_list_wrapper">
|
36
|
+
<legend>Versions</legend>
|
37
|
+
<ul class="version_list">
|
38
|
+
<% @maily_email.versions.each do |_version_key, version_email| %>
|
39
|
+
<li><%= link_to version_email.version.humanize, maily_email_path(maily_params.merge(version: version_email.version)), class: version_list_class(version_email) %></li>
|
40
|
+
<% end %>
|
41
|
+
</ul>
|
42
|
+
</fieldset>
|
43
|
+
<% end %>
|
44
|
+
|
34
45
|
<div class="mail_preview">
|
35
46
|
<ul class="mail_details">
|
36
47
|
<% if @email.subject %><li><b>Subject</b> <%= @email.subject %></li><% end %>
|
@@ -49,7 +60,7 @@
|
|
49
60
|
<% end %>
|
50
61
|
|
51
62
|
<% if @email.html_part || @email.text_part || @email.body.present? %>
|
52
|
-
<iframe class="mail_iframe" onload='resizeIframe(this)' src="<%= raw_maily_email_path(
|
63
|
+
<iframe class="mail_iframe" onload='resizeIframe(this)' src="<%= raw_maily_email_path(maily_params) %>" frameborder="1" width="100%"></iframe>
|
53
64
|
<% end %>
|
54
65
|
|
55
66
|
<% if @email.has_attachments? %>
|
@@ -60,7 +71,7 @@
|
|
60
71
|
<% @email.attachments.each do |attachment| %>
|
61
72
|
<li>
|
62
73
|
<%= icon 'paperclip' %>
|
63
|
-
<%= link_to attachment.filename, attachment_maily_email_path(
|
74
|
+
<%= link_to attachment.filename, attachment_maily_email_path(maily_params.merge(attachment: attachment.filename)) %>
|
64
75
|
</li>
|
65
76
|
<% end %>
|
66
77
|
</ul>
|
@@ -3,10 +3,17 @@
|
|
3
3
|
<section class="nav_list">
|
4
4
|
<h3 class="nav_title"><%= "#{mailer.name.humanize} (#{mailer.total_emails})" %></h3>
|
5
5
|
<ul>
|
6
|
-
<% mailer.emails_list.each do |email| %>
|
7
|
-
<li
|
6
|
+
<% uniq_emails(mailer.emails_list).each do |email| %>
|
7
|
+
<li>
|
8
|
+
<%= link_to maily_email_path(mailer: mailer.name, email: email.name, version: email.version), class: sidebar_class(mailer, email) do %>
|
9
|
+
<%= email.name.humanize %>
|
10
|
+
<% if email.has_versions? %>
|
11
|
+
<%= "(#{email.versions.count} #{'version'.pluralize(email.versions.count)})" %>
|
12
|
+
<% end %>
|
13
|
+
<% end %>
|
14
|
+
</li>
|
8
15
|
<% end %>
|
9
16
|
</ul>
|
10
17
|
</section>
|
11
18
|
<% end %>
|
12
|
-
</aside>
|
19
|
+
</aside>
|
@@ -1,28 +1,29 @@
|
|
1
1
|
<%
|
2
|
-
blue
|
3
|
-
grey
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
blue = "#59abc6"
|
3
|
+
grey = "#cccccc"
|
4
|
+
dark_blue = "#2f738a"
|
5
|
+
dark_grey = "#666666"
|
6
|
+
text_color = "#333333"
|
7
|
+
link_color = blue
|
8
|
+
hover_color = dark_blue
|
9
|
+
border_radius = "3px"
|
9
10
|
%>
|
10
11
|
|
11
12
|
<style>
|
12
13
|
/* Body */
|
13
14
|
body {
|
14
|
-
color: <%=
|
15
|
+
color: <%= text_color %>;
|
15
16
|
font-size: 1em;
|
16
17
|
font-family: "Helvetica Neue", Helvetica, sans-serif;
|
17
18
|
}
|
18
19
|
|
19
20
|
/* Links & Buttons */
|
20
21
|
a {
|
21
|
-
color: <%=
|
22
|
+
color: <%= link_color %>;
|
22
23
|
text-decoration: none;
|
23
24
|
}
|
24
25
|
a:hover {
|
25
|
-
color: <%=
|
26
|
+
color: <%= hover_color %>;
|
26
27
|
}
|
27
28
|
.button {
|
28
29
|
cursor: pointer;
|
@@ -31,10 +32,10 @@
|
|
31
32
|
padding: 0;
|
32
33
|
border: none;
|
33
34
|
background: none;
|
34
|
-
color: <%=
|
35
|
+
color: <%= link_color %>;
|
35
36
|
}
|
36
37
|
.button:hover {
|
37
|
-
color: <%=
|
38
|
+
color: <%= hover_color %>;
|
38
39
|
}
|
39
40
|
|
40
41
|
/* Inputs */
|
@@ -43,16 +44,16 @@
|
|
43
44
|
font-family: inherit;
|
44
45
|
height: 1.2em;
|
45
46
|
border: solid 1px <%= grey %>;
|
46
|
-
border-radius:
|
47
|
-
background:
|
47
|
+
border-radius: <%= border_radius %>;
|
48
|
+
background: #ffffff
|
48
49
|
line-height: 1;
|
49
50
|
padding-left: 0.5em;
|
50
51
|
}
|
51
52
|
|
52
53
|
::-webkit-input-placeholder, ::-moz-placeholder {
|
53
54
|
font-weight: 300;
|
54
|
-
font-size: 0.
|
55
|
-
color: <%=
|
55
|
+
font-size: 0.9em;
|
56
|
+
color: <%= dark_grey %>;
|
56
57
|
}
|
57
58
|
|
58
59
|
/* Header */
|
@@ -102,7 +103,7 @@
|
|
102
103
|
margin-left: 1em;
|
103
104
|
padding-left: 20%;
|
104
105
|
}
|
105
|
-
ul.action_bar {
|
106
|
+
ul.action_bar, ul.version_list {
|
106
107
|
margin: 0 0 5px;
|
107
108
|
padding: 0;
|
108
109
|
list-style: none;
|
@@ -130,6 +131,17 @@
|
|
130
131
|
ul.action_bar li.languages a {
|
131
132
|
font-size: 0.9em;
|
132
133
|
}
|
134
|
+
.version_list_wrapper {
|
135
|
+
box-sizing: border-box;
|
136
|
+
-moz-box-sizing: border-box;
|
137
|
+
border: solid 1px #cccccc;
|
138
|
+
border-radius: <%= border_radius %>;
|
139
|
+
margin: 2% 0;
|
140
|
+
}
|
141
|
+
ul.version_list {
|
142
|
+
font-size: 1em;
|
143
|
+
line-height: 1.5em;
|
144
|
+
}
|
133
145
|
li.splitter {
|
134
146
|
width: 1px;
|
135
147
|
border-left: 1px <%= grey %> solid;
|
@@ -148,24 +160,24 @@
|
|
148
160
|
-moz-box-sizing: border-box;
|
149
161
|
padding: 1em;
|
150
162
|
border: solid 1px <%= grey %>;
|
151
|
-
border-radius:
|
163
|
+
border-radius: <%= border_radius %>;
|
152
164
|
}
|
153
165
|
.mail_preview .mail_details {
|
154
166
|
margin: 0 0 1em 0;
|
155
167
|
padding: 0;
|
156
|
-
color: <%=
|
168
|
+
color: <%= dark_grey %>;
|
157
169
|
list-style: none;
|
158
|
-
font-size: 0.
|
170
|
+
font-size: 0.9em;
|
159
171
|
}
|
160
172
|
.mail_preview .mail_details li {
|
161
|
-
line-height:
|
173
|
+
line-height: 1em;
|
162
174
|
}
|
163
175
|
.mail_preview .mail_attachments {
|
164
176
|
padding: 1em 0 0 0;
|
165
177
|
border-top: solid 1px <%= grey %>;
|
166
|
-
color: <%=
|
178
|
+
color: <%= dark_grey %>;
|
167
179
|
list-style: none;
|
168
|
-
font-size: 0.
|
180
|
+
font-size: 0.9em;
|
169
181
|
}
|
170
182
|
.mail_preview .mail_attachments ul {
|
171
183
|
display: inline-block;
|
@@ -182,7 +194,7 @@
|
|
182
194
|
padding-top: 1em;
|
183
195
|
border: none;
|
184
196
|
border-top: solid 1px <%= grey %>;
|
185
|
-
border-radius:
|
197
|
+
border-radius: <%= border_radius %>;
|
186
198
|
min-height: 100px;
|
187
199
|
}
|
188
200
|
.welcome_message {
|
@@ -202,7 +214,7 @@
|
|
202
214
|
float: left;
|
203
215
|
}
|
204
216
|
.format_mail li a.format_selected {
|
205
|
-
color: <%=
|
217
|
+
color: <%= hover_color %>;
|
206
218
|
font-weight: bold;
|
207
219
|
}
|
208
220
|
.format_mail li + li {
|
@@ -226,40 +238,40 @@
|
|
226
238
|
max-height: 90vh;
|
227
239
|
overflow-y: scroll;
|
228
240
|
}
|
229
|
-
|
230
|
-
margin: 0 0
|
241
|
+
section.nav_list {
|
242
|
+
margin: 0 0 1em 0em;
|
231
243
|
}
|
232
|
-
|
244
|
+
section.nav_list .nav_title {
|
233
245
|
margin: 0 0 0.4em;
|
234
246
|
font-weight: 400;
|
235
247
|
font-size: 1.2em;
|
236
248
|
}
|
237
|
-
|
249
|
+
section.nav_list ul {
|
238
250
|
margin: 0;
|
239
251
|
padding: 0;
|
240
252
|
list-style: none;
|
241
253
|
}
|
242
|
-
|
254
|
+
section.nav_list ul li {
|
243
255
|
margin-bottom: 0.4em;
|
244
256
|
list-style: none;
|
245
257
|
}
|
246
|
-
|
247
|
-
color: <%= linkColor %>;
|
258
|
+
section.nav_list a {
|
248
259
|
text-decoration: none;
|
249
260
|
font-size: 0.9em;
|
250
261
|
}
|
251
|
-
|
252
|
-
|
262
|
+
section.nav_list a.selected_mail, section.nav_list a:hover,
|
263
|
+
.version_list a.selected_mail, .version_list a:hover {
|
264
|
+
color: <%= hover_color %>;
|
253
265
|
font-weight: bold;
|
254
266
|
}
|
255
267
|
|
256
268
|
/* Alert messages */
|
257
269
|
.alert {
|
258
|
-
border-radius:
|
270
|
+
border-radius: <%= border_radius %>;
|
259
271
|
padding: 16px;
|
260
272
|
margin-bottom: 1.1em;
|
261
|
-
color:
|
262
|
-
background-color: <%=
|
273
|
+
color: #ffffff;
|
274
|
+
background-color: <%= dark_blue %>;
|
263
275
|
}
|
264
276
|
|
265
277
|
/* Icons */
|
@@ -1,12 +1,12 @@
|
|
1
1
|
Maily.setup do |config|
|
2
2
|
# On/off engine
|
3
|
-
# config.enabled = Rails.env.production?
|
3
|
+
# config.enabled = !Rails.env.production?
|
4
4
|
|
5
5
|
# Allow templates edition
|
6
|
-
# config.allow_edition = Rails.env.production?
|
6
|
+
# config.allow_edition = !Rails.env.production?
|
7
7
|
|
8
8
|
# Allow deliveries
|
9
|
-
# config.allow_delivery = Rails.env.production?
|
9
|
+
# config.allow_delivery = !Rails.env.production?
|
10
10
|
|
11
11
|
# Your application available_locales (or I18n.available_locales) by default
|
12
12
|
# config.available_locales = [:en, :es, :pt, :fr]
|
@@ -22,4 +22,4 @@ Maily.setup do |config|
|
|
22
22
|
|
23
23
|
# Customize welcome message
|
24
24
|
# config.welcome_message = "Welcome to our email testing platform. If you have any problem, please contact support team at support@example.com."
|
25
|
-
end
|
25
|
+
end
|
data/lib/maily.rb
CHANGED
@@ -10,9 +10,9 @@ module Maily
|
|
10
10
|
:base_controller, :http_authorization, :hooks_path, :welcome_message
|
11
11
|
|
12
12
|
def init!
|
13
|
-
self.enabled = Rails.env.production?
|
14
|
-
self.allow_edition = Rails.env.production?
|
15
|
-
self.allow_delivery = Rails.env.production?
|
13
|
+
self.enabled = !Rails.env.production?
|
14
|
+
self.allow_edition = !Rails.env.production?
|
15
|
+
self.allow_delivery = !Rails.env.production?
|
16
16
|
self.available_locales = Rails.application.config.i18n.available_locales || I18n.available_locales
|
17
17
|
self.base_controller = 'ActionController::Base'
|
18
18
|
self.http_authorization = nil
|
data/lib/maily/email.rb
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
module Maily
|
2
2
|
class Email
|
3
|
-
|
3
|
+
DEFAULT_VERSION = 'default'.freeze
|
4
|
+
|
5
|
+
attr_accessor :name, :mailer, :arguments, :template_path, :template_name, :description, :with_params, :version
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def name_with_version(name, version = nil)
|
9
|
+
_version = formatted_version(version)
|
10
|
+
[name, _version].join(':')
|
11
|
+
end
|
12
|
+
|
13
|
+
def formatted_version(version)
|
14
|
+
_version = version.presence || DEFAULT_VERSION
|
15
|
+
_version&.parameterize&.underscore
|
16
|
+
end
|
17
|
+
end
|
4
18
|
|
5
19
|
def initialize(name, mailer)
|
6
20
|
self.name = name
|
@@ -17,12 +31,8 @@ module Maily
|
|
17
31
|
end
|
18
32
|
|
19
33
|
def parameterized_mailer_klass
|
20
|
-
|
21
|
-
|
22
|
-
mailer_klass.with(params)
|
23
|
-
else
|
24
|
-
mailer_klass
|
25
|
-
end
|
34
|
+
params = with_params && with_params.transform_values { |param| param.respond_to?(:call) ? param.call : param }
|
35
|
+
mailer_klass.with(params)
|
26
36
|
end
|
27
37
|
|
28
38
|
def parameters
|
@@ -58,6 +68,8 @@ module Maily
|
|
58
68
|
def register_hook(*args)
|
59
69
|
if args.last.is_a?(Hash)
|
60
70
|
self.description = args.last.delete(:description)
|
71
|
+
self.with_params = args.last.delete(:with_params)
|
72
|
+
self.version = Maily::Email.formatted_version(args.last.delete(:version))
|
61
73
|
|
62
74
|
if tpl_path = args.last.delete(:template_path)
|
63
75
|
self.template_path = tpl_path
|
@@ -67,8 +79,6 @@ module Maily
|
|
67
79
|
self.template_name = tpl_name
|
68
80
|
end
|
69
81
|
|
70
|
-
self.with_params = args.last.delete(:with_params)
|
71
|
-
|
72
82
|
args.pop
|
73
83
|
end
|
74
84
|
|
@@ -109,5 +119,17 @@ module Maily
|
|
109
119
|
f.write(new_content)
|
110
120
|
end
|
111
121
|
end
|
122
|
+
|
123
|
+
def versions
|
124
|
+
regexp = Regexp.new("^#{self.name}:")
|
125
|
+
|
126
|
+
mailer.emails.select do |email_key, _email|
|
127
|
+
email_key.match?(regexp)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def has_versions?
|
132
|
+
versions.count > 1
|
133
|
+
end
|
112
134
|
end
|
113
135
|
end
|
data/lib/maily/mailer.rb
CHANGED
@@ -27,8 +27,9 @@ module Maily
|
|
27
27
|
all[mailer_name]
|
28
28
|
end
|
29
29
|
|
30
|
-
def find_email(email_name)
|
31
|
-
|
30
|
+
def find_email(email_name, version = nil)
|
31
|
+
key = Maily::Email.name_with_version(email_name, version)
|
32
|
+
emails[key]
|
32
33
|
end
|
33
34
|
|
34
35
|
def emails_list
|
@@ -40,13 +41,15 @@ module Maily
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def register_hook(email_name, *args)
|
43
|
-
|
44
|
+
version = get_version(*args)
|
45
|
+
email = find_email(email_name, version) || add_email(email_name, version)
|
44
46
|
email && email.register_hook(*args)
|
45
47
|
end
|
46
48
|
|
47
49
|
def hide_email(*email_names)
|
48
50
|
email_names.each do |email_name|
|
49
|
-
|
51
|
+
_email_name = Maily::Email.name_with_version(email_name.to_s)
|
52
|
+
emails.delete(_email_name)
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
@@ -60,9 +63,17 @@ module Maily
|
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
63
|
-
def add_email(email_name)
|
66
|
+
def add_email(email_name, version = nil)
|
67
|
+
hide_email(email_name) if version
|
64
68
|
email = Maily::Email.new(email_name.to_s, self)
|
65
|
-
|
69
|
+
key = Maily::Email.name_with_version(email_name, version)
|
70
|
+
emails[key] = email
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_version(*args)
|
74
|
+
return unless args.last.is_a?(Hash)
|
75
|
+
|
76
|
+
Maily::Email.formatted_version(args.last[:version])
|
66
77
|
end
|
67
78
|
end
|
68
79
|
end
|
data/lib/maily/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maily
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|