maily 1.0.0 → 2.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a71e9271060d187f12a6a5d719548bd79ec2d9518a089374c84b671924a9820
4
- data.tar.gz: faf2268d8dccb44e8c4b09d883d16928c786b2774fce5b52eb998edd1eebff78
3
+ metadata.gz: f235ba37075df3a0f065488b094fe1578e57058dd850313292bfdc41e7af75d8
4
+ data.tar.gz: 6091d90733c60d465d170f0b8243b1cad0f74d7dc34d0091dd3a9f2dafd89653
5
5
  SHA512:
6
- metadata.gz: 3e7f4a8e4004a3e39f77bac0b812d7340952eccdda134525a47e3c405bca8a136092e3c6079381f966bad0d3cb17fd90d8fca77d5ded242bf593cc47ad9b25ba
7
- data.tar.gz: bd248a071b75a4791408bf7f43837f9bbcd0160fbea84c61d63399836dcb371caf4f6e941ded8481a6a3dd767be7ef8a66df4cf01c9d2df549504b2dd1cd67a3
6
+ metadata.gz: 96185b6150391a907bff8a17535212ff383b0f400ddd28242802600eeec1d394418426097935bc7200d32a9b0dfaec6ab0744ea0d1da752a279772dd67236fd8
7
+ data.tar.gz: 14552df9ee81d40ea11e3997aa8bdbc9f4678699cb279116dc0eb74ad9ffdf4d730586562af6dfdf8473d8f33bf26e729819193f21dd8b265f723700c1f4f5bf
data/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [2.1.0]
6
+
7
+ - Use `ActionMailer::InlinePreviewInterceptor` to facilitate integration with other gems like premailer (#55)
8
+ - Move CI from Travis to GitHub Actions
9
+
10
+ ## [2.0.2]
11
+
12
+ - UI: Hide delivery form if `allow_delivery` is false (#54)
13
+
14
+ ## [2.0.1]
15
+
16
+ - UI: Don't show empty mailer classes in sidebar (#51)
17
+
18
+ ## [2.0.0]
19
+
20
+ - Email versions (#49)
21
+ - Drop official support for EOL Rails versions: 5.1, 5.0 and 4.2
22
+ - Drop official support for EOL Rubies: 2.4
23
+
5
24
  ## [1.0.0]
6
25
 
7
26
  - Avoid the dependency on Sprockets (#48)
@@ -143,6 +162,10 @@ All notable changes to this project will be documented in this file.
143
162
 
144
163
  - First real usable release :tada:
145
164
 
165
+ [2.1.0]: https://github.com/markets/maily/compare/v2.0.2...v2.1.0
166
+ [2.0.2]: https://github.com/markets/maily/compare/v2.0.1...v2.0.2
167
+ [2.0.1]: https://github.com/markets/maily/compare/v2.0.0...v2.0.1
168
+ [2.0.0]: https://github.com/markets/maily/compare/v1.0.0...v2.0.0
146
169
  [1.0.0]: https://github.com/markets/maily/compare/v0.12.3...v1.0.0
147
170
  [0.12.3]: https://github.com/markets/maily/compare/v0.12.2...v0.12.3
148
171
  [0.12.2]: https://github.com/markets/maily/compare/v0.12.1...v0.12.2
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2013-2020 Marc Anguera Insa
1
+ Copyright 2013-2021 Marc Anguera Insa
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  </p>
5
5
  <p align="center">
6
6
  <a href="https://rubygems.org/gems/maily"><img src="https://img.shields.io/gem/v/maily.svg?style=flat-square"></a>
7
- <a href="https://travis-ci.org/markets/maily"><img src="https://travis-ci.org/markets/maily.svg?branch=master"></a>
7
+ <a href="https://github.com/markets/maily/actions"><img src="https://github.com/markets/maily/workflows/CI/badge.svg"></a>
8
8
  <a href="https://codeclimate.com/github/markets/maily/maintainability"><img src="https://api.codeclimate.com/v1/badges/fff01b2137fd73070b14/maintainability"></a>
9
9
  <a href="https://github.com/markets/maily/blob/master/MIT-LICENSE"><img alt="GitHub" src="https://img.shields.io/github/license/markets/maily.svg?style=flat-square"></a>
10
10
  </p>
@@ -20,10 +20,10 @@ Maily automatically picks up all your emails and make them accessible from a kin
20
20
  * Visual preview in the browser (attachments as well)
21
21
  * Template edition (only in development)
22
22
  * Email delivery
23
- * Features configurables per environment
23
+ * Easy way (aka `Hooks`) to define and customize data for emails
24
+ * Email versions
24
25
  * Flexible authorization system
25
26
  * Minimalistic and clean interface
26
- * Easy way (aka `hooks`) to define and customize data for emails
27
27
  * Generator to handle a comfortable installation
28
28
 
29
29
  ![](support/images/screenshot.png)
@@ -50,27 +50,20 @@ This generator runs some tasks for you:
50
50
 
51
51
  ## Initialization and configuration
52
52
 
53
- You should configure Maily via an initializer. You can set different values per environment:
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? ? false : true
60
+ # config.enabled = !Rails.env.production?
68
61
 
69
62
  # Allow templates edition
70
- # config.allow_edition = Rails.env.production? ? false : true
63
+ # config.allow_edition = !Rails.env.production?
71
64
 
72
65
  # Allow deliveries
73
- # config.allow_delivery = Rails.env.production? ? false : true
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 some other plugins to get a similar functionality, but with different approaches and options. 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).
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
- > bundle exec appraisal rake
235
+ ```
236
+ > bundle exec rspec
237
+ ```
238
+
239
+ Run the test suite against all supported versions:
240
+
241
+ ```
242
+ > bundle exec appraisal install
243
+ > bundle exec appraisal rspec
244
+ ```
245
+
246
+ Run specs against specific version:
247
+
248
+ ```
249
+ > bundle exec appraisal rails-6.0 rspec
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?
@@ -25,7 +25,6 @@ module Maily
25
25
 
26
26
  content = content.raw_source
27
27
  content = view_context.simple_format(content) if @email.sub_type == 'plain' || params[:part] == 'text'
28
- content = prepare_inline_attachments(@email, content)
29
28
 
30
29
  render html: content.html_safe, layout: false
31
30
  end
@@ -43,7 +42,7 @@ module Maily
43
42
  def update
44
43
  @maily_email.update_template(params[:body], params[:part])
45
44
 
46
- redirect_to maily_email_path(mailer: params[:mailer], email: params[:email], part: params[:part]), notice: 'Template updated!'
45
+ redirect_to maily_email_path(maily_params), notice: 'Template updated!'
47
46
  end
48
47
 
49
48
  def deliver
@@ -51,7 +50,7 @@ module Maily
51
50
 
52
51
  @email.deliver
53
52
 
54
- redirect_to maily_email_path(mailer: params[:mailer], email: params[:email]), notice: "Email sent to <b>#{params[:to]}</b>!"
53
+ redirect_to maily_email_path(maily_params), notice: "Email sent to <b>#{params[:to]}</b>!"
55
54
  end
56
55
 
57
56
  private
@@ -66,7 +65,7 @@ module Maily
66
65
 
67
66
  def load_mailer_and_email
68
67
  mailer = Maily::Mailer.find(params[:mailer])
69
- @maily_email = mailer.find_email(params[:email])
68
+ @maily_email = mailer.find_email(params[:email], params[:version])
70
69
 
71
70
  if @maily_email
72
71
  @email = @maily_email.call
@@ -80,19 +79,5 @@ module Maily
80
79
  yield
81
80
  end
82
81
  end
83
-
84
- def prepare_inline_attachments(email, content)
85
- content.gsub(/src=(?:"cid:[^"]+"|'cid:[^']+')/i) do |match|
86
- if part = find_part(email, match[9..-2])
87
- %[src="data:#{part.mime_type};base64,#{Base64.encode64(part.body.raw_source)}"]
88
- else
89
- match
90
- end
91
- end
92
- end
93
-
94
- def find_part(email, cid)
95
- email.all_parts.find { |p| p.attachment? && p.cid == cid }
96
- end
97
82
  end
98
83
  end
@@ -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('maily/logo.png', 'image/png'))
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("maily/icons/#{name}.svg", 'image/svg+xml'), class: :icon)
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
- content_tag(:div, class: 'mail_description') do
11
- concat content_tag(:strong, 'Description ')
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 (part == params[:part]) || (part == 'html' && !params[:part])
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(mailer: params[:mailer], email: params[:email], part: params[:part]), method: :put) do %>
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(mailer: params[:mailer], email: params[:email]) %>
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(mailer: params[:mailer], email: params[:email], part: params[:part]) %>
5
+ <%= link_to 'Edit', edit_maily_email_path(maily_params) %>
6
6
  </li>
7
7
 
8
8
  <li class="languages">
@@ -18,19 +18,32 @@
18
18
  <% end %>
19
19
  </li>
20
20
 
21
- <li class="splitter">|</li>
21
+ <% if Maily.allowed_action?(:deliver) %>
22
+ <li class="splitter">|</li>
22
23
 
23
- <li>
24
- <%= form_tag(deliver_maily_email_path(mailer: params[:mailer], email: params[:email], locale: params[:locale]), method: :post, class: 'mail_deliver') do %>
25
- <ul>
26
- <li>Send to</li>
27
- <li><%= email_field_tag :to, nil, placeholder: "Enter email", required: true %></li>
28
- <li><%= submit_tag 'Send', class: 'button' %></li>
29
- </ul>
30
- <% end %>
31
- </li>
24
+ <li>
25
+ <%= form_tag(deliver_maily_email_path(maily_params), method: :post, class: 'mail_deliver') do %>
26
+ <ul>
27
+ <li>Send to</li>
28
+ <li><%= email_field_tag :to, nil, placeholder: "Enter email", required: true %></li>
29
+ <li><%= submit_tag 'Send', class: 'button' %></li>
30
+ </ul>
31
+ <% end %>
32
+ </li>
33
+ <% end %>
32
34
  </ul>
33
35
 
36
+ <% if @maily_email.has_versions? %>
37
+ <fieldset class="version_list_wrapper">
38
+ <legend>Versions</legend>
39
+ <ul class="version_list">
40
+ <% @maily_email.versions.each do |_version_key, version_email| %>
41
+ <li><%= link_to version_email.version.humanize, maily_email_path(maily_params.merge(version: version_email.version)), class: version_list_class(version_email) %></li>
42
+ <% end %>
43
+ </ul>
44
+ </fieldset>
45
+ <% end %>
46
+
34
47
  <div class="mail_preview">
35
48
  <ul class="mail_details">
36
49
  <% if @email.subject %><li><b>Subject</b> <%= @email.subject %></li><% end %>
@@ -49,7 +62,7 @@
49
62
  <% end %>
50
63
 
51
64
  <% if @email.html_part || @email.text_part || @email.body.present? %>
52
- <iframe class="mail_iframe" onload='resizeIframe(this)' src="<%= raw_maily_email_path(mailer: params[:mailer], email: params[:email], locale: params[:locale], part: params[:part]) %>" frameborder="1" width="100%"></iframe>
65
+ <iframe class="mail_iframe" onload='resizeIframe(this)' src="<%= raw_maily_email_path(maily_params) %>" frameborder="1" width="100%"></iframe>
53
66
  <% end %>
54
67
 
55
68
  <% if @email.has_attachments? %>
@@ -60,7 +73,7 @@
60
73
  <% @email.attachments.each do |attachment| %>
61
74
  <li>
62
75
  <%= icon 'paperclip' %>
63
- <%= link_to attachment.filename, attachment_maily_email_path(mailer: params[:mailer], email: params[:email], attachment: attachment.filename) %>
76
+ <%= link_to attachment.filename, attachment_maily_email_path(maily_params.merge(attachment: attachment.filename)) %>
64
77
  </li>
65
78
  <% end %>
66
79
  </ul>
@@ -1,12 +1,21 @@
1
1
  <aside class="sidebar">
2
2
  <% @mailers.each do |mailer| %>
3
+ <% next if mailer.total_emails.zero? %>
4
+
3
5
  <section class="nav_list">
4
6
  <h3 class="nav_title"><%= "#{mailer.name.humanize} (#{mailer.total_emails})" %></h3>
5
7
  <ul>
6
- <% mailer.emails_list.each do |email| %>
7
- <li><%= link_to email.name.humanize, maily_email_path(mailer: mailer.name, email: email.name), class: sidebar_class(mailer, email) %></li>
8
+ <% uniq_emails(mailer.emails_list).each do |email| %>
9
+ <li>
10
+ <%= link_to maily_email_path(mailer: mailer.name, email: email.name, version: email.version), class: sidebar_class(mailer, email) do %>
11
+ <%= email.name.humanize %>
12
+ <% if email.has_versions? %>
13
+ <%= "(#{email.versions.count} #{'version'.pluralize(email.versions.count)})" %>
14
+ <% end %>
15
+ <% end %>
16
+ </li>
8
17
  <% end %>
9
18
  </ul>
10
19
  </section>
11
20
  <% end %>
12
- </aside>
21
+ </aside>
@@ -1,28 +1,29 @@
1
1
  <%
2
- blue = "#59abc6"
3
- grey = "#cccccc"
4
- bluegrey = "#2f738a"
5
- darkgrey = "#666666"
6
- textColor = "#333333"
7
- linkColor = blue
8
- hoverColor = bluegrey
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: <%= textColor %>;
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: <%= linkColor %>;
22
+ color: <%= link_color %>;
22
23
  text-decoration: none;
23
24
  }
24
25
  a:hover {
25
- color: <%= hoverColor %>;
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: <%= linkColor %>;
35
+ color: <%= link_color %>;
35
36
  }
36
37
  .button:hover {
37
- color: <%= hoverColor %>;
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: 6px;
47
- background: "#ffffff";
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.8em;
55
- color: <%= darkgrey %>;
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: 3px;
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: <%= darkgrey %>;
168
+ color: <%= dark_grey %>;
157
169
  list-style: none;
158
- font-size: 0.8em;
170
+ font-size: 0.9em;
159
171
  }
160
172
  .mail_preview .mail_details li {
161
- line-height: 1.5em;
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: <%= darkgrey %>;
178
+ color: <%= dark_grey %>;
167
179
  list-style: none;
168
- font-size: 0.8em;
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: 3px;
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: <%= hoverColor %>;
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
- aside.sidebar section.nav_list {
230
- margin: 0 0 1.5em 1.5em;
241
+ section.nav_list {
242
+ margin: 0 0 1em 0em;
231
243
  }
232
- aside.sidebar section.nav_list .nav_title {
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
- aside.sidebar section.nav_list ul {
249
+ section.nav_list ul {
238
250
  margin: 0;
239
251
  padding: 0;
240
252
  list-style: none;
241
253
  }
242
- aside.sidebar section.nav_list ul li {
254
+ section.nav_list ul li {
243
255
  margin-bottom: 0.4em;
244
256
  list-style: none;
245
257
  }
246
- aside.sidebar section.nav_list ul li a {
247
- color: <%= linkColor %>;
258
+ section.nav_list a {
248
259
  text-decoration: none;
249
260
  font-size: 0.9em;
250
261
  }
251
- aside.sidebar section.nav_list ul li a:hover, aside.sidebar section.nav_list ul li a.selected_mail {
252
- color: <%= hoverColor %>;
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: 3px;
270
+ border-radius: <%= border_radius %>;
259
271
  padding: 16px;
260
272
  margin-bottom: 1.1em;
261
- color: "#ffffff";
262
- background-color: <%= bluegrey %>;
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? ? false : true
3
+ # config.enabled = !Rails.env.production?
4
4
 
5
5
  # Allow templates edition
6
- # config.allow_edition = Rails.env.production? ? false : true
6
+ # config.allow_edition = !Rails.env.production?
7
7
 
8
8
  # Allow deliveries
9
- # config.allow_delivery = Rails.env.production? ? false : true
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/email.rb CHANGED
@@ -1,6 +1,20 @@
1
1
  module Maily
2
2
  class Email
3
- attr_accessor :name, :mailer, :arguments, :template_path, :template_name, :description, :with_params
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
- if Rails.version >= '5.1'
21
- params = with_params && with_params.transform_values { |param| param.respond_to?(:call) ? param.call : param }
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
 
@@ -78,11 +88,17 @@ module Maily
78
88
  def call
79
89
  *args = arguments && arguments.map { |arg| arg.respond_to?(:call) ? arg.call : arg }
80
90
 
81
- if args == [nil]
91
+ message = if args == [nil]
82
92
  parameterized_mailer_klass.public_send(name)
83
93
  else
84
94
  parameterized_mailer_klass.public_send(name, *args)
85
95
  end
96
+
97
+ ActionMailer::Base.preview_interceptors.each do |interceptor|
98
+ interceptor.previewing_email(message)
99
+ end
100
+
101
+ message
86
102
  end
87
103
 
88
104
  def base_path(part)
@@ -109,5 +125,17 @@ module Maily
109
125
  f.write(new_content)
110
126
  end
111
127
  end
128
+
129
+ def versions
130
+ regexp = Regexp.new("^#{self.name}:")
131
+
132
+ mailer.emails.select do |email_key, _email|
133
+ email_key.match?(regexp)
134
+ end
135
+ end
136
+
137
+ def has_versions?
138
+ versions.count > 1
139
+ end
112
140
  end
113
141
  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
- emails[email_name.to_s]
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
- email = find_email(email_name) || add_email(email_name)
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
- emails.delete(email_name.to_s)
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
- self.emails[email.name] = email
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
@@ -1,3 +1,3 @@
1
1
  module Maily
2
- VERSION = "1.0.0"
2
+ VERSION = "2.1.0"
3
3
  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? ? false : true
14
- self.allow_edition = Rails.env.production? ? false : true
15
- self.allow_delivery = Rails.env.production? ? false : true
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
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: 1.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-10 00:00:00.000000000 Z
11
+ date: 2021-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.0.3
111
+ rubygems_version: 3.1.4
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Rails Engine to preview emails in the browser.