maily 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,13 @@
1
1
  module Maily
2
2
  class ApplicationController < Maily.base_controller.constantize
3
- before_filter :maily_enabled?, :http_authorization
3
+ before_action :maily_enabled?, :http_authorization
4
4
 
5
5
  layout 'maily/application'
6
6
 
7
7
  private
8
8
 
9
9
  def maily_enabled?
10
- Maily.enabled || raise('Maily: engine disabled!')
10
+ Maily.enabled || head(404, message: "Maily disabled")
11
11
  end
12
12
 
13
13
  def http_authorization
@@ -1,14 +1,18 @@
1
1
  module Maily
2
2
  class EmailsController < ApplicationController
3
- before_filter :allowed_action?, only: [:edit, :update, :deliver]
4
- before_filter :load_mailers, only: [:index, :show, :edit]
5
- before_filter :load_mailer_and_email, except: [:index]
6
- around_filter :perform_with_locale, only: [:show, :raw, :deliver]
3
+ before_action :allowed_action?, only: [:edit, :update, :deliver]
4
+ before_action :load_mailers, only: [:index, :show, :edit]
5
+ before_action :load_mailer_and_email, except: [:index]
6
+ around_action :perform_with_locale, only: [:show, :raw, :deliver]
7
7
 
8
8
  def index
9
9
  end
10
10
 
11
11
  def show
12
+ if !@maily_email.correct_number_of_arguments?
13
+ alert = "#{@maily_email.required_arguments.size} arguments needed for #{@maily_email.name} email"
14
+ redirect_to(root_path, alert: alert)
15
+ end
12
16
  end
13
17
 
14
18
  def raw
@@ -47,7 +51,7 @@ module Maily
47
51
  private
48
52
 
49
53
  def allowed_action?
50
- Maily.allowed_action?(action_name) || raise("Maily: action #{action_name} not allowed!")
54
+ Maily.allowed_action?(action_name) || redirect_to(root_path, alert: "Maily: action #{action_name} not allowed!")
51
55
  end
52
56
 
53
57
  def load_mailers
@@ -1,5 +1,9 @@
1
1
  module Maily
2
2
  module EmailsHelper
3
+ def total_emails(mailers)
4
+ mailers.map { |mailer| mailer.emails.size }.sum
5
+ end
6
+
3
7
  def part_class(part)
4
8
  'format_selected' if (part == params[:part]) || (part == 'html' && !params[:part])
5
9
  end
@@ -5,16 +5,17 @@
5
5
  <%= stylesheet_link_tag "maily/application", :media => "all" %>
6
6
  <%= javascript_include_tag "maily/application" %>
7
7
  <%= csrf_meta_tags %>
8
- <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
9
- <!--[if lt IE 9]>
10
- <script src="/assets/javascripts/html5shiv.js"></script>
11
- <![endif]-->
12
8
  </head>
13
9
  <body>
14
10
  <%= render 'maily/shared/header' %>
15
11
 
16
12
  <div class="wrap_content clearfix">
17
13
  <%= render 'maily/shared/sidebar' %>
14
+
15
+ <% if flash[:alert].present? %>
16
+ <p class="alert"><%= flash[:alert] %></p>
17
+ <% end %>
18
+
18
19
  <%= yield %>
19
20
  </div>
20
21
 
@@ -1,3 +1,4 @@
1
1
  <div class="content">
2
+ <h2><%= total_emails(@mailers) %> emails found</h2>
3
+ <p><%= Maily.welcome_message %></p>
2
4
  </div>
3
-
@@ -1,4 +1,10 @@
1
1
  <div class="content">
2
+ <% if @maily_email.description %>
3
+ <div>
4
+ <b>Description </b><%= @maily_email.description %>
5
+ </div><br>
6
+ <% end %>
7
+
2
8
  <ul class="maily_action_bar">
3
9
  <li>
4
10
  <em class="icon-maily-pencil"></em>
@@ -10,7 +16,7 @@
10
16
  <ul>
11
17
  <li>
12
18
  <em class="icon-maily-earth"></em>
13
- Languages:</li>
19
+ Languages</li>
14
20
  <% Maily.available_locales.each do |locale| %>
15
21
  <li><%= link_to locale.upcase, url_for(params.merge(locale: locale)) %></li>
16
22
  <% end %>
@@ -22,7 +28,7 @@
22
28
  <li>
23
29
  <%= form_tag(deliver_maily_email_path(mailer: params[:mailer], email: params[:email], locale: params[:locale]), method: :post, class: 'maily_send') do %>
24
30
  <ul>
25
- <li>Send to:</li>
31
+ <li>Send to</li>
26
32
  <li><%= email_field_tag :to, nil, class: 'maily_textfield', placeholder: "Enter email", required: true %></li>
27
33
  <li><%= submit_tag 'Send', class: 'maily_button' %></li>
28
34
  </ul>
@@ -1,3 +1,3 @@
1
1
  <footer class="footer">
2
- <%= link_to content_tag(:em, "", class: 'icon-maily-github') + "Maily v#{Maily::VERSION}", 'https://github.com/markets/maily' %>
2
+ <p>Powered by <%= link_to("Maily v#{Maily::VERSION}", 'https://github.com/markets/maily', target: '_blank') %></p>
3
3
  </footer>
@@ -1,7 +1,7 @@
1
1
  <aside class="sidebar">
2
2
  <% @mailers.each do |mailer| %>
3
3
  <section class="nav_list">
4
- <h3 class="title nav_title"><%= mailer.name.humanize %></h3>
4
+ <h3 class="title nav_title"><%= "#{mailer.name.humanize} (#{mailer.emails.length})" %></h3>
5
5
  <ul>
6
6
  <% mailer.emails.each do |email| %>
7
7
  <li><%= link_to email.name.humanize, maily_email_path(mailer: mailer.name, email: email.name), class: sidebar_class(mailer, email) %></li>
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 3.2.0"
5
+ gem "rails", "~> 5.1.0"
6
6
 
7
7
  gemspec :path => "../"
@@ -14,6 +14,12 @@ Maily.setup do |config|
14
14
  # Run maily under different controller ('ActionController::Base' by default)
15
15
  # config.base_controller = '::AdminController'
16
16
 
17
+ # Configure hooks path
18
+ # config.hooks_path = 'lib/maily_hooks.rb'
19
+
17
20
  # Http basic authentication (nil by default)
18
21
  # config.http_authorization = { username: 'admin', password: 'secret' }
22
+
23
+ # Customize welcome message
24
+ # config.welcome_message = "Welcome to our email testing platform. If you have any problem, please contact support team at support@example.com."
19
25
  end
data/lib/maily.rb CHANGED
@@ -6,7 +6,7 @@ require 'maily/email'
6
6
  module Maily
7
7
  class << self
8
8
  attr_accessor :enabled, :allow_edition, :allow_delivery, :available_locales,
9
- :base_controller, :http_authorization
9
+ :base_controller, :http_authorization, :hooks_path, :welcome_message
10
10
 
11
11
  def init!
12
12
  self.enabled = Rails.env.production? ? false : true
@@ -15,18 +15,21 @@ module Maily
15
15
  self.available_locales = I18n.available_locales
16
16
  self.base_controller = 'ActionController::Base'
17
17
  self.http_authorization = nil
18
+ self.hooks_path = "lib/maily_hooks.rb"
19
+ self.welcome_message = "Use the menu on the left hand side of the screen to navigate through the different email templates."
18
20
  end
19
21
 
20
22
  def load_emails_and_hooks
21
23
  # Load emails from file system
22
24
  Dir[Rails.root + 'app/mailers/*.rb'].each do |mailer|
23
- klass = File.basename(mailer, '.rb')
24
- methods = klass.camelize.constantize.send(:instance_methods, false)
25
- Maily::Mailer.new(klass, methods)
25
+ klass_name = File.basename(mailer, '.rb')
26
+ klass = klass_name.camelize.constantize
27
+ methods = klass.send(:public_instance_methods, false)
28
+ Maily::Mailer.new(klass_name, methods)
26
29
  end
27
30
 
28
31
  # Load hooks
29
- hooks_file_path = "#{Rails.root}/lib/maily_hooks.rb"
32
+ hooks_file_path = File.join(Rails.root, hooks_path)
30
33
  require hooks_file_path if File.exist?(hooks_file_path)
31
34
  end
32
35
 
data/lib/maily/email.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  module Maily
2
2
  class Email
3
- attr_accessor :name, :mailer, :arguments, :template_path
3
+ attr_accessor :name, :mailer, :arguments, :template_path, :description
4
4
 
5
5
  def initialize(name, mailer)
6
6
  self.name = name.to_s
7
7
  self.mailer = mailer
8
8
  self.arguments = nil
9
9
  self.template_path = mailer
10
+ self.description = nil
10
11
  end
11
12
 
12
13
  def parameters
@@ -21,11 +22,16 @@ module Maily
21
22
  parameters.map(&:last)
22
23
  end
23
24
 
25
+ def correct_number_of_arguments?
26
+ required_arguments.size == arguments.size
27
+ end
28
+
24
29
  def register_hook(*args)
25
30
  args = args.flatten
26
31
 
27
- if args.last.is_a?(Hash) && new_path = args.last.delete(:template_path)
28
- self.template_path = new_path
32
+ if args.last.is_a?(Hash)
33
+ self.description = args.last.delete(:description)
34
+ self.template_path = args.last.delete(:template_path)
29
35
  args.pop
30
36
  end
31
37
 
@@ -41,7 +47,13 @@ module Maily
41
47
  end
42
48
 
43
49
  def call
44
- mailer_klass.send(name, *arguments)
50
+ *args = arguments && arguments.map { |arg| arg.respond_to?(:call) ? arg.call : arg }
51
+
52
+ if args == [nil]
53
+ mailer_klass.public_send(name)
54
+ else
55
+ mailer_klass.public_send(name, *args)
56
+ end
45
57
  end
46
58
 
47
59
  def base_path(part)
data/lib/maily/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Maily
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/maily.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.email = ["srmarc.ai@gmail.com"]
8
8
  s.homepage = "https://github.com/markets/maily"
9
9
  s.summary = "Rails Engine to preview emails in the browser."
10
- s.description = "Rails Engine to preview, follow up, test and edit the emails of your applications in the browser"
10
+ s.description = "Maily is a Rails Engine to manage, test and navigate through all your email templates of your app, being able to preview them directly in your browser."
11
11
  s.license = "MIT"
12
12
 
13
13
  s.files = `git ls-files`.split($/)
@@ -13,7 +13,8 @@ describe Maily::EmailsController, type: :controller do
13
13
 
14
14
  it 'raise error if disabled' do
15
15
  Maily.enabled = false
16
- expect { get :index }.to raise_error('Maily: engine disabled!')
16
+ get :index
17
+ expect(response.status).to eq(404)
17
18
  end
18
19
 
19
20
  it 'responds with 401 if http authorization fails' do
@@ -1,4 +1,6 @@
1
+ email = -> { 'foo@foo.com' }
2
+
1
3
  Maily.hooks_for('Notifier') do |mailer|
2
- mailer.register_hook(:invitation, 'foo@foo.com')
3
- mailer.register_hook(:recommendation, template_path: 'notifications')
4
- end
4
+ mailer.register_hook(:invitation, email)
5
+ mailer.register_hook(:recommendation, template_path: 'notifications', description: 'description')
6
+ end
data/spec/email_spec.rb CHANGED
@@ -24,7 +24,13 @@ describe Maily::Email do
24
24
  expect(email.require_hook?).to be true
25
25
  end
26
26
 
27
- it "should handle arguments successfully" do
27
+ it 'should handle lazy arguments successfully' do
28
+ expect(email.arguments).to be_present
29
+ expect(email.arguments.size).to eq(email.required_arguments.size)
30
+ end
31
+
32
+ it 'should handle not lazy arguments successfully' do
33
+ allow(email).to receive(:email).and_return('foo@foo.com')
28
34
  expect(email.arguments).to be_present
29
35
  expect(email.arguments.size).to eq(email.required_arguments.size)
30
36
  end
@@ -38,4 +44,9 @@ describe Maily::Email do
38
44
  email = mailer.find_email('recommendation')
39
45
  expect(email.template_path).to eq('notifications')
40
46
  end
47
+
48
+ it "should handle description via hook" do
49
+ email = mailer.find_email('recommendation')
50
+ expect(email.description).to eq('description')
51
+ end
41
52
  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.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,8 +80,8 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Rails Engine to preview, follow up, test and edit the emails of your
84
- applications in the browser
83
+ description: Maily is a Rails Engine to manage, test and navigate through all your
84
+ email templates of your app, being able to preview them directly in your browser.
85
85
  email:
86
86
  - srmarc.ai@gmail.com
87
87
  executables: []
@@ -95,14 +95,12 @@ files:
95
95
  - MIT-LICENSE
96
96
  - README.md
97
97
  - Rakefile
98
- - app/assets/images/maily/.gitkeep
99
98
  - app/assets/images/maily/fonts/JosefinSans-Light.ttf
100
99
  - app/assets/images/maily/icons/maily.eot
101
100
  - app/assets/images/maily/icons/maily.svg
102
101
  - app/assets/images/maily/icons/maily.ttf
103
102
  - app/assets/images/maily/icons/maily.woff
104
103
  - app/assets/javascripts/maily/application.js
105
- - app/assets/javascripts/maily/html5shiv.js
106
104
  - app/assets/stylesheets/maily/application.scss
107
105
  - app/assets/stylesheets/maily/icons.css
108
106
  - app/assets/stylesheets/maily/normalize.css
@@ -118,10 +116,9 @@ files:
118
116
  - app/views/maily/shared/_header.html.erb
119
117
  - app/views/maily/shared/_sidebar.html.erb
120
118
  - config/routes.rb
121
- - gemfiles/rails_3.2.gemfile
122
- - gemfiles/rails_4.1.gemfile
123
119
  - gemfiles/rails_4.2.gemfile
124
120
  - gemfiles/rails_5.0.gemfile
121
+ - gemfiles/rails_5.1.gemfile
125
122
  - lib/generators/maily/install_generator.rb
126
123
  - lib/generators/templates/initializer.rb
127
124
  - lib/maily.rb
@@ -199,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
196
  version: '0'
200
197
  requirements: []
201
198
  rubyforge_project:
202
- rubygems_version: 2.5.1
199
+ rubygems_version: 2.5.2
203
200
  signing_key:
204
201
  specification_version: 4
205
202
  summary: Rails Engine to preview emails in the browser.
File without changes
@@ -1,8 +0,0 @@
1
- /*
2
- HTML5 Shiv v3.7.0 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
3
- */
4
- (function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag();
5
- a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/[\w\-]+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x<style>article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}</style>";
6
- c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="<xyz></xyz>";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode||
7
- "undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output progress section summary template time video",version:"3.7.0",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);
8
- if(g)return a.createDocumentFragment();for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d<h;d++)c.createElement(e[d]);return c}};l.html5=e;q(f)})(this,document);
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 4.1.0"
6
-
7
- gemspec :path => "../"