maily 0.12.2 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d38fbf8d086c1aade273877ebf112b0277001e6f6d585a63b86783086ac22c3
4
- data.tar.gz: c31053939be691ddc0870035ae244de39aa29a2b7346bf038ea330fcbc5ea89b
3
+ metadata.gz: f56b187b737b69eebc37a1d71bd792c8dde6059ed71727e038e832b73f2ec18c
4
+ data.tar.gz: f5bfc85ebb1ed72c5f405a236e33ff62892e14815375f0ff1989b774a48ea90c
5
5
  SHA512:
6
- metadata.gz: eb6e44d06a0e7b8ea53d66b961d388254d6b789d2d1de2489ea9b4d93461c161534402dd6e4d91b2e4fb4061b4c64c7e63f130abdf3d7a6ab523003062ea5ffc
7
- data.tar.gz: a85efd1d8719d2adc5d9e312a061f2aa897506dedd47f82462f36fd86103133478851a3dd6af44dfa4d79e9d2e5eb7510b84d81d3f70269c1d7c6cc62889452e
6
+ metadata.gz: 618f0f112671a0c9355b25d4ef5d6912cf209e423b61ffdeb80372d15be28581864c3b041aaf1213d31de9405605596ab726ef84a55c29cfc8338deca2664bf2
7
+ data.tar.gz: fb8ec2d9c389f4516e726dcfb5c0488ea4db4eca2bc8d89526180f945d77c065783e5d81439d1546a8eb3744f1d7adec2351b3aff69c6440d0fe97025b830acf
data/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [2.0.2]
6
+
7
+ - UI: Hide delivery form if `allow_delivery` is false (#54)
8
+
9
+ ## [2.0.1]
10
+
11
+ - UI: Don't show empty mailer classes in sidebar (#51)
12
+
13
+ ## [2.0.0]
14
+
15
+ - Email versions (#49)
16
+ - Drop official support for EOL Rails versions: 5.1, 5.0 and 4.2
17
+ - Drop official support for EOL Rubies: 2.4
18
+
19
+ ## [1.0.0]
20
+
21
+ - Avoid the dependency on Sprockets (#48)
22
+
23
+ ## [0.12.3]
24
+
25
+ - Styles: fix input placeholder color in Firefox
26
+
5
27
  ## [0.12.2]
6
28
 
7
29
  - Refine logo and UI (#45)
@@ -135,6 +157,11 @@ All notable changes to this project will be documented in this file.
135
157
 
136
158
  - First real usable release :tada:
137
159
 
160
+ [2.0.2]: https://github.com/markets/maily/compare/v2.0.1...v2.0.2
161
+ [2.0.1]: https://github.com/markets/maily/compare/v2.0.0...v2.0.1
162
+ [2.0.0]: https://github.com/markets/maily/compare/v1.0.0...v2.0.0
163
+ [1.0.0]: https://github.com/markets/maily/compare/v0.12.3...v1.0.0
164
+ [0.12.3]: https://github.com/markets/maily/compare/v0.12.2...v0.12.3
138
165
  [0.12.2]: https://github.com/markets/maily/compare/v0.12.1...v0.12.2
139
166
  [0.12.1]: https://github.com/markets/maily/compare/v0.12.0...v0.12.1
140
167
  [0.12.0]: https://github.com/markets/maily/compare/v0.11.0...v0.12.0
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://travis-ci.com/markets/maily"><img src="https://travis-ci.com/markets/maily.svg?branch=master"></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 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(mailer: params[:mailer], email: params[:email], part: params[:part]), notice: 'Template updated!'
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(mailer: params[:mailer], email: params[:email]), notice: "Email sent to <b>#{params[:to]}</b>!"
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,8 +14,25 @@ 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
+
21
+ def logo
22
+ image_tag(file_to_base64('logo.png', 'image/png'))
23
+ end
24
+
17
25
  def icon(name)
18
- image_tag "maily/icons/#{name}.svg", class: 'icon'
26
+ image_tag(file_to_base64("icons/#{name}.svg", 'image/svg+xml'), class: :icon)
27
+ end
28
+
29
+ private
30
+
31
+ def file_to_base64(path, mime_type)
32
+ file = Maily::Engine.root.join('app/assets/images/maily').join(path)
33
+ base64_contents = Base64.strict_encode64(file.read)
34
+
35
+ "data:#{mime_type};base64,#{base64_contents}"
19
36
  end
20
37
  end
21
38
  end
@@ -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
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <title><%= title %></title>
5
5
  <%= csrf_meta_tags %>
6
- <%= stylesheet_link_tag "maily/application", media: "all" %>
6
+ <%= render 'maily/shared/stylesheet' %>
7
7
  <%= render 'maily/shared/javascript' %>
8
8
  </head>
9
9
  <body>
@@ -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,6 +1,6 @@
1
1
  <header class="header">
2
2
  <a href="<%= root_path %>" class="logo_link">
3
- <%= image_tag 'maily/logo.png' %>
3
+ <%= logo %>
4
4
  </a>
5
5
 
6
6
  <a href="<%= main_app.root_path %>" class="back_to_app">
@@ -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>
@@ -0,0 +1,283 @@
1
+ <%
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"
10
+ %>
11
+
12
+ <style>
13
+ /* Body */
14
+ body {
15
+ color: <%= text_color %>;
16
+ font-size: 1em;
17
+ font-family: "Helvetica Neue", Helvetica, sans-serif;
18
+ }
19
+
20
+ /* Links & Buttons */
21
+ a {
22
+ color: <%= link_color %>;
23
+ text-decoration: none;
24
+ }
25
+ a:hover {
26
+ color: <%= hover_color %>;
27
+ }
28
+ .button {
29
+ cursor: pointer;
30
+ box-sizing: border-box;
31
+ -moz-box-sizing: border-box;
32
+ padding: 0;
33
+ border: none;
34
+ background: none;
35
+ color: <%= link_color %>;
36
+ }
37
+ .button:hover {
38
+ color: <%= hover_color %>;
39
+ }
40
+
41
+ /* Inputs */
42
+ input {
43
+ font-size: 100%;
44
+ font-family: inherit;
45
+ height: 1.2em;
46
+ border: solid 1px <%= grey %>;
47
+ border-radius: <%= border_radius %>;
48
+ background: #ffffff
49
+ line-height: 1;
50
+ padding-left: 0.5em;
51
+ }
52
+
53
+ ::-webkit-input-placeholder, ::-moz-placeholder {
54
+ font-weight: 300;
55
+ font-size: 0.9em;
56
+ color: <%= dark_grey %>;
57
+ }
58
+
59
+ /* Header */
60
+ header.header, footer.footer {
61
+ position: fixed;
62
+ left: 0;
63
+ z-index: 99;
64
+ width: 100%;
65
+ background-color: rgba(255, 255, 255, 0.95);
66
+ }
67
+ header.header {
68
+ padding: 0.6em;
69
+ top: 0;
70
+ box-shadow: 0 0.0625em 0.3125em rgba(0, 0, 0, 0.15);
71
+ }
72
+ header.header .logo_link {
73
+ margin-left: 1em;
74
+ }
75
+ header.header .logo_link img {
76
+ height: 45px;
77
+ }
78
+ header.header .back_to_app {
79
+ float: right;
80
+ margin-right: 2em;
81
+ margin-top: 1em;
82
+ }
83
+
84
+ /* Footer */
85
+ footer.footer {
86
+ padding: 0 1em;
87
+ bottom: 0;
88
+ box-shadow: 0 -0.0625em 0.3125em rgba(0, 0, 0, 0.15);
89
+ font-family: inherit;
90
+ font-size: 0.9em;
91
+ }
92
+
93
+ /* Main content */
94
+ .wrap_content {
95
+ display: inline-block;
96
+ box-sizing: border-box;
97
+ -moz-box-sizing: border-box;
98
+ padding: 6em 0.75em 4em;
99
+ width: 100%;
100
+ }
101
+ .content {
102
+ margin-right: 2em;
103
+ margin-left: 1em;
104
+ padding-left: 20%;
105
+ }
106
+ ul.action_bar, ul.version_list {
107
+ margin: 0 0 5px;
108
+ padding: 0;
109
+ list-style: none;
110
+ font-size: 1.2em;
111
+ }
112
+ ul.action_bar, ul.action_bar ul {
113
+ display: inline-block;
114
+ width: 100%;
115
+ }
116
+ ul.action_bar li, ul.action_bar ul li {
117
+ float: left;
118
+ margin-right: 0.5em;
119
+ }
120
+ ul.action_bar li:last-child, ul.action_bar ul li:last-child {
121
+ margin-right: 0;
122
+ }
123
+ ul.action_bar ul {
124
+ margin: 0;
125
+ padding: 0;
126
+ list-style: none;
127
+ }
128
+ ul.action_bar li.languages {
129
+ float: right;
130
+ }
131
+ ul.action_bar li.languages a {
132
+ font-size: 0.9em;
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
+ }
145
+ li.splitter {
146
+ width: 1px;
147
+ border-left: 1px <%= grey %> solid;
148
+ text-indent: -999999em;
149
+ }
150
+ .mail_description {
151
+ margin-bottom: 2em;
152
+ }
153
+ .mail_deliver ul li {
154
+ float: left;
155
+ margin-right: 0.4em;
156
+ }
157
+ .mail_preview {
158
+ height: 100%;
159
+ box-sizing: border-box;
160
+ -moz-box-sizing: border-box;
161
+ padding: 1em;
162
+ border: solid 1px <%= grey %>;
163
+ border-radius: <%= border_radius %>;
164
+ }
165
+ .mail_preview .mail_details {
166
+ margin: 0 0 1em 0;
167
+ padding: 0;
168
+ color: <%= dark_grey %>;
169
+ list-style: none;
170
+ font-size: 0.9em;
171
+ }
172
+ .mail_preview .mail_details li {
173
+ line-height: 1em;
174
+ }
175
+ .mail_preview .mail_attachments {
176
+ padding: 1em 0 0 0;
177
+ border-top: solid 1px <%= grey %>;
178
+ color: <%= dark_grey %>;
179
+ list-style: none;
180
+ font-size: 0.9em;
181
+ }
182
+ .mail_preview .mail_attachments ul {
183
+ display: inline-block;
184
+ margin: 0;
185
+ padding: 0;
186
+ width: 100%;
187
+ list-style: none;
188
+ }
189
+ .mail_preview .mail_attachments ul li {
190
+ float: left;
191
+ margin: 1em 1em 0 0;
192
+ }
193
+ .mail_preview iframe.mail_iframe {
194
+ padding-top: 1em;
195
+ border: none;
196
+ border-top: solid 1px <%= grey %>;
197
+ border-radius: <%= border_radius %>;
198
+ min-height: 100px;
199
+ }
200
+ .welcome_message {
201
+ margin-top: 3em;
202
+ max-width: 80%;
203
+ }
204
+ .format_mail {
205
+ position: relative;
206
+ display: inline-block;
207
+ float: right;
208
+ margin: -2em 0 0 0;
209
+ padding: 0;
210
+ width: 6.5em;
211
+ list-style: none;
212
+ }
213
+ .format_mail li {
214
+ float: left;
215
+ }
216
+ .format_mail li a.format_selected {
217
+ color: <%= hover_color %>;
218
+ font-weight: bold;
219
+ }
220
+ .format_mail li + li {
221
+ margin: 0 0 0 0.4em;
222
+ padding: 0 0 0 0.4em;
223
+ border-left: solid 1px <%= grey %>;
224
+ }
225
+ .mail_updatearea {
226
+ position: relative;
227
+ overflow: visible;
228
+ min-height: 450px;
229
+ width: 100%;
230
+ height: 100%;
231
+ border: none;
232
+ }
233
+
234
+ /* Sidebar */
235
+ aside.sidebar {
236
+ float: left;
237
+ width: 20%;
238
+ max-height: 90vh;
239
+ overflow-y: scroll;
240
+ }
241
+ section.nav_list {
242
+ margin: 0 0 1em 0em;
243
+ }
244
+ section.nav_list .nav_title {
245
+ margin: 0 0 0.4em;
246
+ font-weight: 400;
247
+ font-size: 1.2em;
248
+ }
249
+ section.nav_list ul {
250
+ margin: 0;
251
+ padding: 0;
252
+ list-style: none;
253
+ }
254
+ section.nav_list ul li {
255
+ margin-bottom: 0.4em;
256
+ list-style: none;
257
+ }
258
+ section.nav_list a {
259
+ text-decoration: none;
260
+ font-size: 0.9em;
261
+ }
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 %>;
265
+ font-weight: bold;
266
+ }
267
+
268
+ /* Alert messages */
269
+ .alert {
270
+ border-radius: <%= border_radius %>;
271
+ padding: 16px;
272
+ margin-bottom: 1.1em;
273
+ color: #ffffff;
274
+ background-color: <%= dark_blue %>;
275
+ }
276
+
277
+ /* Icons */
278
+ img.icon {
279
+ width: 20px;
280
+ font-size: 0.9em;
281
+ vertical-align: bottom;
282
+ }
283
+ </style>
@@ -29,4 +29,4 @@ module Maily
29
29
  end
30
30
  end
31
31
  end
32
- end
32
+ end
@@ -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.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
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
 
@@ -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/engine.rb CHANGED
@@ -2,12 +2,5 @@ module Maily
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace Maily
4
4
  load_generators
5
-
6
- config.assets.precompile << %w(
7
- maily/application.css
8
- maily/logo.png
9
- maily/icons/globe.svg
10
- maily/icons/paperclip.svg
11
- )
12
5
  end
13
6
  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 = "0.12.2"
2
+ VERSION = "2.0.2"
3
3
  end
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: 0.12.2
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - markets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-19 00:00:00.000000000 Z
11
+ date: 2021-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
- - !ruby/object:Gem::Dependency
28
- name: sassc-rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec-rails
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,8 +66,6 @@ files:
80
66
  - app/assets/images/maily/icons/globe.svg
81
67
  - app/assets/images/maily/icons/paperclip.svg
82
68
  - app/assets/images/maily/logo.png
83
- - app/assets/stylesheets/maily/_variables.scss
84
- - app/assets/stylesheets/maily/application.scss
85
69
  - app/controllers/maily/application_controller.rb
86
70
  - app/controllers/maily/emails_controller.rb
87
71
  - app/helpers/maily/application_helper.rb
@@ -95,6 +79,7 @@ files:
95
79
  - app/views/maily/shared/_header.html.erb
96
80
  - app/views/maily/shared/_javascript.html.erb
97
81
  - app/views/maily/shared/_sidebar.html.erb
82
+ - app/views/maily/shared/_stylesheet.html.erb
98
83
  - config/routes.rb
99
84
  - lib/generators/maily/install_generator.rb
100
85
  - lib/generators/templates/initializer.rb
@@ -1,5 +0,0 @@
1
- $blue: #59abc6;
2
- $grey: #ccc;
3
- $darkgrey: #666;
4
- $textColor: #333;
5
- $linkColor: $blue;
@@ -1,292 +0,0 @@
1
- @import "maily/variables";
2
-
3
- /* Body */
4
- body {
5
- color: $textColor;
6
- font-size: 1em;
7
- font-family: "Helvetica Neue", Helvetica, sans-serif;
8
-
9
- a {
10
- color: $linkColor;
11
- text-decoration: none;
12
- &:hover {
13
- color: darken($linkColor, 20%);
14
- }
15
- }
16
- }
17
-
18
- /* Inputs */
19
- input {
20
- font-size: 100%;
21
- font-family: inherit;
22
- height: 1.2em;
23
- border: solid 1px $grey;
24
- border-radius: 6px;
25
- background: #fff;
26
- line-height: 1;
27
- padding-left: 0.5em;
28
- }
29
-
30
- ::-webkit-input-placeholder, ::-moz-placeholder {
31
- font-weight: 300;
32
- font-size: 0.8em;
33
- color: red;
34
- }
35
-
36
- /* Header */
37
- header.header, footer.footer {
38
- position: fixed;
39
- left: 0;
40
- z-index: 99;
41
- width: 100%;
42
- background-color: rgba(255,255,255, .95);
43
- }
44
-
45
- header.header {
46
- padding: 0.6em;
47
- top: 0;
48
- box-shadow: 0 .0625em .3125em rgba(0,0,0, .15);
49
-
50
- .logo_link {
51
- margin-left: 1em;
52
-
53
- img {
54
- height: 45px;
55
- }
56
- }
57
-
58
- .back_to_app {
59
- float: right;
60
- margin-right: 2em;
61
- margin-top: 1em;
62
- }
63
- }
64
-
65
- /* Footer */
66
- footer.footer {
67
- padding: 0 1em;
68
- bottom: 0;
69
- box-shadow: 0 -.0625em .3125em rgba(0,0,0, .15);
70
- font-family: inherit;
71
- font-size: .9em;
72
- }
73
-
74
- /* Main content */
75
- .wrap_content {
76
- display: inline-block;
77
- box-sizing: border-box;
78
- -moz-box-sizing: border-box;
79
- padding: 6em .75em 4em;
80
- width: 100%;
81
- }
82
-
83
- .content {
84
- margin-right: 2em;
85
- margin-left: 1em;
86
- padding-left: 20%;
87
-
88
- ul.action_bar {
89
- margin: 0 0 5px;
90
- padding: 0;
91
- list-style: none;
92
- font-size: 1.2em;
93
-
94
- &, & ul {
95
- display: inline-block;
96
- width: 100%;
97
- }
98
-
99
- li, ul li {
100
- float: left;
101
- margin-right: .5em;
102
- &:last-child { margin-right: 0; }
103
- }
104
-
105
- ul {
106
- margin: 0;
107
- padding: 0;
108
- list-style: none;
109
- }
110
-
111
- li.languages {
112
- float: right;
113
-
114
- a { font-size: 0.9em; }
115
- }
116
- }
117
-
118
- li.splitter {
119
- width: 1px;
120
- border-left: 1px $grey solid;
121
- text-indent: -999999em;
122
- }
123
-
124
- .mail_description {
125
- margin-bottom: 2em;
126
- }
127
-
128
- .mail_deliver {
129
- ul {
130
- li {
131
- float: left;
132
- margin-right: .4em;
133
- }
134
- }
135
- }
136
-
137
- .mail_preview {
138
- height: 100%;
139
- box-sizing: border-box;
140
- -moz-box-sizing: border-box;
141
- padding: 1em;
142
- border: solid 1px $grey;
143
- border-radius: 3px;
144
-
145
- .mail_details {
146
- margin: 0 0 1em 0;
147
- padding: 0;
148
- color: $darkgrey;
149
- list-style: none;
150
- font-size: .8em;
151
-
152
- li { line-height: 1.5em; }
153
- }
154
-
155
- .mail_attachments {
156
- padding: 1em 0 0 0;
157
- border-top: solid 1px $grey;
158
- color: $darkgrey;
159
- list-style: none;
160
- font-size: .8em;
161
-
162
- ul {
163
- display: inline-block;
164
- margin: 0;
165
- padding: 0;
166
- width: 100%;
167
- list-style: none;
168
-
169
- li {
170
- float: left;
171
- margin: 1em 1em 0 0;
172
- }
173
- }
174
- }
175
-
176
- iframe.mail_iframe {
177
- padding-top: 1em;
178
- border: none;
179
- border-top: solid 1px $grey;
180
- border-radius: 3px;
181
- min-height: 100px;
182
- }
183
- }
184
-
185
- .welcome_message {
186
- margin-top: 3em;
187
- max-width: 80%;
188
- }
189
-
190
- .button {
191
- cursor: pointer;
192
- box-sizing: border-box;
193
- -moz-box-sizing: border-box;
194
- padding: 0;
195
- border: none;
196
- background: none;
197
- color: $linkColor;
198
- &:hover {
199
- color: darken($linkColor, 20%);
200
- }
201
- }
202
-
203
- .format_mail {
204
- position: relative;
205
- display: inline-block;
206
- float: right;
207
- margin: -2em 0 0 0;
208
- padding: 0;
209
- width: 6.5em;
210
- list-style: none;
211
-
212
- li {
213
- float: left;
214
-
215
- a.format_selected {
216
- color: darken($linkColor, 20%);
217
- font-weight: bold;
218
- }
219
-
220
- + li {
221
- margin: 0 0 0 .4em;
222
- padding: 0 0 0 .4em;
223
- border-left: solid 1px $grey;
224
- }
225
- }
226
- }
227
-
228
- .mail_updatearea {
229
- position: relative;
230
- overflow: visible;
231
- min-height: 450px;
232
- width: 100%;
233
- height: 100%;
234
- border: none;
235
- }
236
- }
237
-
238
- /* Sidebar */
239
- aside.sidebar {
240
- float: left;
241
- width: 20%;
242
- max-height: 90vh;
243
- overflow-y: scroll;
244
-
245
- section.nav_list {
246
- margin: 0 0 1.5em 1.5em;
247
-
248
- .nav_title {
249
- margin: 0 0 .4em;
250
- font-weight: 400;
251
- font-size: 1.2em;
252
- }
253
-
254
- ul {
255
- margin: 0;
256
- padding: 0;
257
- list-style: none;
258
-
259
- li {
260
- margin-bottom: .4em;
261
- list-style: none;
262
-
263
- a {
264
- color: $linkColor;
265
- text-decoration: none;
266
- font-size: .9em;
267
-
268
- &:hover, &.selected_mail {
269
- color: darken($linkColor, 20%);
270
- font-weight: bold;
271
- }
272
- }
273
- }
274
- }
275
- }
276
- }
277
-
278
- /* Alert messages */
279
- .alert {
280
- border-radius: 3px;
281
- padding: 16px;
282
- margin-bottom: 1.1em;
283
- color: #fff;
284
- background-color: darken($blue, 20%);
285
- }
286
-
287
- /* Icons */
288
- img.icon {
289
- width: 20px;
290
- font-size: .9em;
291
- vertical-align: bottom;
292
- }