maily 0.12.1 → 2.0.1

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: 9e2d3eb5fa12bff5214c0c3bf8279fa4ae87e1c2a1fa7e0d3ff15600576f836f
4
- data.tar.gz: 5cb5fb89ad2e8a3c710f91e42c4ddaf7003a5673d96e71a5d23d9132a8036388
3
+ metadata.gz: f5d36fc2996857665c3ca2722d87efacccdd1a389e2ff2c96e00ce4f8a2d0de4
4
+ data.tar.gz: e48248be9469c2f524434855a48ccbe11743631456b4659c941cc7c6cb4c2e68
5
5
  SHA512:
6
- metadata.gz: 3c4bcb08461590baedc7d0db69e49e9df161db4c79aa9339b1623147a89e66a0e1e4e9af4cf97b213b6370687c1ba9afef940640473af665f93fa10172536967
7
- data.tar.gz: 50b5ad7a8155169dcda86df69b76fae8d30eed92d1634b9dfbec5aedfc1db07ba8b39129069b4b98efc786412fb115940820f8d409d8786c941549c73c8c5daf
6
+ metadata.gz: eb0e6fac2533eaf67e2c946ca7a7a18faa8d3765114d33cc7ae82036c010812f8a5849f445da776047a07a9cdcf8359b84a0279bf77068b23e1b707a42a6d90e
7
+ data.tar.gz: ad9bce77b87ed40340f2a3c491f17d722dab9d0922e11d34f0d1ebf94b5d2aca9218c7d8ba22bdea2ebf3e30f13f14a650049d1548b4f7b989efebf986d27966
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.1]
6
+
7
+ - Don't show empty mailer classes in sidebar (#51)
8
+
9
+ ## [2.0.0]
10
+
11
+ - Email versions (#49)
12
+ - Drop official support for EOL Rails versions: 5.1, 5.0 and 4.2
13
+ - Drop official support for EOL Rubies: 2.4
14
+
15
+ ## [1.0.0]
16
+
17
+ - Avoid the dependency on Sprockets (#48)
18
+
19
+ ## [0.12.3]
20
+
21
+ - Styles: fix input placeholder color in Firefox
22
+
23
+ ## [0.12.2]
24
+
25
+ - Refine logo and UI (#45)
26
+
5
27
  ## [0.12.1]
6
28
 
7
29
  - Sprockets v4 fixes (#44)
@@ -131,6 +153,11 @@ All notable changes to this project will be documented in this file.
131
153
 
132
154
  - First real usable release :tada:
133
155
 
156
+ [2.0.1]: https://github.com/markets/maily/compare/v2.0.0...v2.0.1
157
+ [2.0.0]: https://github.com/markets/maily/compare/v1.0.0...v2.0.0
158
+ [1.0.0]: https://github.com/markets/maily/compare/v0.12.3...v1.0.0
159
+ [0.12.3]: https://github.com/markets/maily/compare/v0.12.2...v0.12.3
160
+ [0.12.2]: https://github.com/markets/maily/compare/v0.12.1...v0.12.2
134
161
  [0.12.1]: https://github.com/markets/maily/compare/v0.12.0...v0.12.1
135
162
  [0.12.0]: https://github.com/markets/maily/compare/v0.11.0...v0.12.0
136
163
  [0.11.0]: https://github.com/markets/maily/compare/v0.10.1...v0.11.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
 
Binary file
@@ -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">
@@ -21,7 +21,7 @@
21
21
  <li class="splitter">|</li>
22
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 %>
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(mailer: params[:mailer], email: params[:email], locale: params[:locale], part: params[:part]) %>" frameborder="1" width="100%"></iframe>
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(mailer: params[:mailer], email: params[:email], attachment: attachment.filename) %>
74
+ <%= link_to attachment.filename, attachment_maily_email_path(maily_params.merge(attachment: attachment.filename)) %>
64
75
  </li>
65
76
  <% end %>
66
77
  </ul>
@@ -1,7 +1,7 @@
1
1
  <% if flash[:alert].present? %>
2
- <div class="alert alert-warning"><%= flash[:alert].html_safe %></div>
2
+ <div class="alert"><%= flash[:alert].html_safe %></div>
3
3
  <% end %>
4
4
 
5
5
  <% if flash[:notice].present? %>
6
- <div class="alert alert-success"><%= flash[:notice].html_safe %></div>
7
- <% end %>
6
+ <div class="alert"><%= flash[:notice].html_safe %></div>
7
+ <% end %>
@@ -1,6 +1,9 @@
1
1
  <header class="header">
2
2
  <a href="<%= root_path %>" class="logo_link">
3
- <%= image_tag 'maily/logo.png', align: 'center', width: 40 %>
4
- <span>Maily</span>
3
+ <%= logo %>
4
+ </a>
5
+
6
+ <a href="<%= main_app.root_path %>" class="back_to_app">
7
+ Back to app
5
8
  </a>
6
9
  </header>
@@ -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.1"
2
+ VERSION = "2.0.1"
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.1
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - markets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-21 00:00:00.000000000 Z
11
+ date: 2021-04-17 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,6 +0,0 @@
1
- $blue: #59abc6;
2
- $red: #a94442;
3
- $grey: #ccc;
4
- $darkgrey: #666;
5
- $textColor: #444;
6
- $linkColor: $blue;
@@ -1,305 +0,0 @@
1
- @import url("https://fonts.googleapis.com/css?family=Josefin+Sans:light");
2
-
3
- @import "maily/variables";
4
-
5
- /* Body */
6
- body {
7
- color: $textColor;
8
- font-size: 1em;
9
- font-family: "Helvetica Neue", Helvetica, sans-serif;
10
-
11
- a {
12
- color: $linkColor;
13
- text-decoration: none;
14
- &:hover {
15
- color: darken($linkColor, 20%);
16
- }
17
- }
18
- }
19
-
20
- /* Inputs */
21
- input {
22
- font-size: 100%;
23
- font-family: inherit;
24
- height: 1.2em;
25
- border: solid 1px $grey;
26
- border-radius: 2px;
27
- background: #fff;
28
- line-height: 1;
29
- }
30
-
31
- ::-webkit-input-placeholder {
32
- padding: 0 .2em;
33
- vertical-align: bottom;
34
- font-weight: 300;
35
- }
36
- :-moz-placeholder { font-size: 0.6em; }
37
- ::-moz-placeholder { font-size: 0.6em; }
38
- :-ms-input-placeholder { font-size: 0.6em; }
39
-
40
- /* Header */
41
- header.header, footer.footer {
42
- position: fixed;
43
- left: 0;
44
- z-index: 99;
45
- width: 100%;
46
- background-color: rgba(255,255,255, .95);
47
- }
48
-
49
- header.header {
50
- padding: 1em;
51
- top: 0;
52
- box-shadow: 0 .0625em .3125em rgba(0,0,0, .15);
53
-
54
- .logo_link {
55
- color: $textColor;
56
- font: 400 2em/1 'Josefin Sans';
57
- margin-left: 10px;
58
-
59
- img, span {
60
- vertical-align: text-bottom;
61
- }
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: "Helvetica Neue", Helvetica, sans-serif;
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
- }
115
-
116
- li.splitter {
117
- width: 1px;
118
- border-left: 1px $grey solid;
119
- text-indent: -999999em;
120
- }
121
-
122
- .mail_description {
123
- margin-bottom: 2em;
124
- }
125
-
126
- .mail_deliver {
127
- ul {
128
- li {
129
- float: left;
130
- margin-right: .4em;
131
- }
132
- }
133
- }
134
-
135
- .mail_preview {
136
- height: 100%;
137
- box-sizing: border-box;
138
- -moz-box-sizing: border-box;
139
- padding: 1em;
140
- border: solid 1px $grey;
141
- border-radius: 3px;
142
-
143
- .mail_details {
144
- margin: 0 0 1em 0;
145
- padding: 0;
146
- color: $darkgrey;
147
- list-style: none;
148
- font-size: .8em;
149
-
150
- li { line-height: 1.5em; }
151
- }
152
-
153
- .mail_attachments {
154
- padding: 1em 0 0 0;
155
- border-top: solid 1px $grey;
156
- color: $darkgrey;
157
- list-style: none;
158
- font-size: .8em;
159
-
160
- ul {
161
- display: inline-block;
162
- margin: 0;
163
- padding: 0;
164
- width: 100%;
165
- list-style: none;
166
-
167
- li {
168
- float: left;
169
- margin: 1em 1em 0 0;
170
- }
171
- }
172
- }
173
-
174
- iframe.mail_iframe {
175
- padding-top: 1em;
176
- border: none;
177
- border-top: solid 1px $grey;
178
- border-radius: 2px;
179
- min-height: 100px;
180
- }
181
- }
182
-
183
- .welcome_message {
184
- margin-top: 3em;
185
- max-width: 80%;
186
- }
187
-
188
- .button {
189
- box-sizing: border-box;
190
- -moz-box-sizing: border-box;
191
- padding: 0;
192
- border: none;
193
- background: none;
194
- color: $linkColor;
195
- &:hover {
196
- color: darken($linkColor, 20%);
197
- }
198
- }
199
-
200
- .format_mail {
201
- position: relative;
202
- display: inline-block;
203
- float: right;
204
- margin: -2em 0 0 0;
205
- padding: 0;
206
- width: 6.5em;
207
- list-style: none;
208
-
209
- li {
210
- float: left;
211
-
212
- a.format_selected {
213
- color: darken($linkColor, 20%);
214
- font-weight: bold;
215
- }
216
-
217
- + li {
218
- margin: 0 0 0 .4em;
219
- padding: 0 0 0 .4em;
220
- border-left: solid 1px $grey;
221
- }
222
- }
223
- }
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
-
235
- /* Sidebar */
236
- aside.sidebar {
237
- float: left;
238
- width: 20%;
239
- max-height: 90vh;
240
- overflow-y: scroll;
241
-
242
- section.nav_list {
243
- margin: 0 0 1.5em 1.5em;
244
-
245
- .nav_title {
246
- margin: 0 0 .4em;
247
- font-weight: 400;
248
- font-size: 1.2em;
249
- }
250
-
251
- ul {
252
- margin: 0;
253
- padding: 0;
254
- list-style: none;
255
-
256
- li {
257
- margin-bottom: .4em;
258
- list-style: none;
259
-
260
- a {
261
- color: $linkColor;
262
- text-decoration: none;
263
- font-size: .9em;
264
-
265
- &.selected_mail {
266
- color: darken($linkColor, 20%);
267
- font-weight: bold;
268
-
269
- &:before {
270
- content: "\003E";
271
- font-weight: bolder;
272
- font-size: 1.2em;
273
- margin-right: 2px;
274
- }
275
- }
276
- &:hover {
277
- color: darken($linkColor, 20%);
278
- }
279
- }
280
- }
281
- }
282
- }
283
- }
284
-
285
- /* Alert messages */
286
- .alert {
287
- border-radius: 3px;
288
- padding: 16px;
289
- margin-bottom: 1.1em;
290
- }
291
- .alert-warning {
292
- color: $red;
293
- background-color: lighten($red, 40%);
294
- }
295
- .alert-success {
296
- color: #fff;
297
- background-color: darken($blue, 20%);
298
- }
299
-
300
- /* Icons */
301
- img.icon {
302
- width: 20px;
303
- font-size: .9em;
304
- vertical-align: bottom;
305
- }