maily 0.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.
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +99 -0
- data/MIT-LICENSE +20 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/app/assets/images/maily/.gitkeep +0 -0
- data/app/assets/javascripts/maily/application.js +15 -0
- data/app/assets/stylesheets/maily/application.css +13 -0
- data/app/controllers/maily/application_controller.rb +14 -0
- data/app/controllers/maily/emails_controller.rb +67 -0
- data/app/helpers/maily/application_helper.rb +4 -0
- data/app/helpers/maily/emails_helper.rb +4 -0
- data/app/views/layouts/maily/application.html.erb +17 -0
- data/app/views/maily/emails/edit.html.erb +12 -0
- data/app/views/maily/emails/index.html.erb +10 -0
- data/app/views/maily/emails/show.html.erb +43 -0
- data/config/routes.rb +10 -0
- data/lib/generators/maily/install_generator.rb +43 -0
- data/lib/generators/templates/initializer.rb +18 -0
- data/lib/maily.rb +45 -0
- data/lib/maily/email.rb +36 -0
- data/lib/maily/engine.rb +6 -0
- data/lib/maily/mailer.rb +38 -0
- data/lib/maily/version.rb +3 -0
- data/maily.gemspec +25 -0
- data/script/rails +8 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
maily (0.0.1)
|
5
|
+
rails (~> 3.2.13)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (3.2.14)
|
11
|
+
actionpack (= 3.2.14)
|
12
|
+
mail (~> 2.5.4)
|
13
|
+
actionpack (3.2.14)
|
14
|
+
activemodel (= 3.2.14)
|
15
|
+
activesupport (= 3.2.14)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
journey (~> 1.0.4)
|
19
|
+
rack (~> 1.4.5)
|
20
|
+
rack-cache (~> 1.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.2.1)
|
23
|
+
activemodel (3.2.14)
|
24
|
+
activesupport (= 3.2.14)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
activerecord (3.2.14)
|
27
|
+
activemodel (= 3.2.14)
|
28
|
+
activesupport (= 3.2.14)
|
29
|
+
arel (~> 3.0.2)
|
30
|
+
tzinfo (~> 0.3.29)
|
31
|
+
activeresource (3.2.14)
|
32
|
+
activemodel (= 3.2.14)
|
33
|
+
activesupport (= 3.2.14)
|
34
|
+
activesupport (3.2.14)
|
35
|
+
i18n (~> 0.6, >= 0.6.4)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
arel (3.0.2)
|
38
|
+
builder (3.0.4)
|
39
|
+
columnize (0.3.6)
|
40
|
+
debugger (1.6.0)
|
41
|
+
columnize (>= 0.3.1)
|
42
|
+
debugger-linecache (~> 1.2.0)
|
43
|
+
debugger-ruby_core_source (~> 1.2.1)
|
44
|
+
debugger-linecache (1.2.0)
|
45
|
+
debugger-ruby_core_source (1.2.2)
|
46
|
+
erubis (2.7.0)
|
47
|
+
hike (1.2.3)
|
48
|
+
i18n (0.6.5)
|
49
|
+
journey (1.0.4)
|
50
|
+
json (1.8.0)
|
51
|
+
mail (2.5.4)
|
52
|
+
mime-types (~> 1.16)
|
53
|
+
treetop (~> 1.4.8)
|
54
|
+
mime-types (1.25)
|
55
|
+
multi_json (1.8.0)
|
56
|
+
polyglot (0.3.3)
|
57
|
+
rack (1.4.5)
|
58
|
+
rack-cache (1.2)
|
59
|
+
rack (>= 0.4)
|
60
|
+
rack-ssl (1.3.3)
|
61
|
+
rack
|
62
|
+
rack-test (0.6.2)
|
63
|
+
rack (>= 1.0)
|
64
|
+
rails (3.2.14)
|
65
|
+
actionmailer (= 3.2.14)
|
66
|
+
actionpack (= 3.2.14)
|
67
|
+
activerecord (= 3.2.14)
|
68
|
+
activeresource (= 3.2.14)
|
69
|
+
activesupport (= 3.2.14)
|
70
|
+
bundler (~> 1.0)
|
71
|
+
railties (= 3.2.14)
|
72
|
+
railties (3.2.14)
|
73
|
+
actionpack (= 3.2.14)
|
74
|
+
activesupport (= 3.2.14)
|
75
|
+
rack-ssl (~> 1.3.2)
|
76
|
+
rake (>= 0.8.7)
|
77
|
+
rdoc (~> 3.4)
|
78
|
+
thor (>= 0.14.6, < 2.0)
|
79
|
+
rake (10.1.0)
|
80
|
+
rdoc (3.12.2)
|
81
|
+
json (~> 1.4)
|
82
|
+
sprockets (2.2.2)
|
83
|
+
hike (~> 1.2)
|
84
|
+
multi_json (~> 1.0)
|
85
|
+
rack (~> 1.0)
|
86
|
+
tilt (~> 1.1, != 1.3.0)
|
87
|
+
thor (0.18.1)
|
88
|
+
tilt (1.4.1)
|
89
|
+
treetop (1.4.15)
|
90
|
+
polyglot
|
91
|
+
polyglot (>= 0.3.1)
|
92
|
+
tzinfo (0.3.37)
|
93
|
+
|
94
|
+
PLATFORMS
|
95
|
+
ruby
|
96
|
+
|
97
|
+
DEPENDENCIES
|
98
|
+
debugger
|
99
|
+
maily!
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Maily
|
2
|
+
==============
|
3
|
+
|
4
|
+
**[IN PROGRESS: working, but not ready for first release]**
|
5
|
+
|
6
|
+
Rails Engine to preview, follow up, test and edit application emails.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
Add this line to you Gemfile:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem 'maily'
|
13
|
+
```
|
14
|
+
|
15
|
+
Run generator:
|
16
|
+
|
17
|
+
```
|
18
|
+
rails g maily:install
|
19
|
+
```
|
20
|
+
|
21
|
+
This installator mounts the engine:
|
22
|
+
```
|
23
|
+
mount Maily::Engine, at: 'maily'
|
24
|
+
```
|
25
|
+
|
26
|
+
And adds an initializer to customize some settings and define hooks.
|
27
|
+
|
28
|
+
## Hooks
|
29
|
+
Hooks are used to collect data for emails:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
user = User.new(email: 'user@example.com')
|
33
|
+
comment = Comment.new(body: 'Lorem ipsum')
|
34
|
+
service = Service.new(price: '100USD')
|
35
|
+
|
36
|
+
Maily.hooks_for('Notifier') do |mailer|
|
37
|
+
mailer.register_hook(:welcome, user)
|
38
|
+
mailer.register_hook(:new_comment, user, comment)
|
39
|
+
end
|
40
|
+
|
41
|
+
Maily.hooks_for('PaymentNotifier') do |mailer|
|
42
|
+
mailer.register_hook(:invoice, user, service)
|
43
|
+
end
|
44
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Maily
|
2
|
+
class ApplicationController < Maily.base_controller.constantize
|
3
|
+
|
4
|
+
before_filter :maily_enabled?
|
5
|
+
|
6
|
+
layout 'maily/application'
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def maily_enabled?
|
11
|
+
Maily.enabled || raise('Maily: engine disabled!')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Maily
|
2
|
+
class EmailsController < ApplicationController
|
3
|
+
|
4
|
+
before_filter :allowed_action?, only: [:edit, :update, :deliver]
|
5
|
+
before_filter :load_mailer_and_email, except: [:index, :edit, :update]
|
6
|
+
around_filter :perform_with_locale, only: [:show, :raw, :deliver]
|
7
|
+
|
8
|
+
def index
|
9
|
+
@mailers = Maily::Mailer.all
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
end
|
14
|
+
|
15
|
+
def raw
|
16
|
+
content = if @email.parts.present?
|
17
|
+
params[:part] == 'text' ? @email.text_part.body : @email.html_part.body
|
18
|
+
else
|
19
|
+
@email.body
|
20
|
+
end
|
21
|
+
|
22
|
+
render text: content, layout: false
|
23
|
+
end
|
24
|
+
|
25
|
+
def attachment
|
26
|
+
attachment = @email.attachments.find { |elem| elem.filename == params[:attachment] }
|
27
|
+
send_data attachment.body, filename: attachment.filename, type: attachment.content_type
|
28
|
+
end
|
29
|
+
|
30
|
+
def edit
|
31
|
+
@email = File.read("#{Rails.root}/app/views/#{params[:mailer]}/#{params[:method]}.html.erb")
|
32
|
+
end
|
33
|
+
|
34
|
+
def update
|
35
|
+
@email = File.open("#{Rails.root}/app/views/#{params[:mailer]}/#{params[:method]}.html.erb", 'w') do |f|
|
36
|
+
f.write(params[:body])
|
37
|
+
end
|
38
|
+
|
39
|
+
redirect_to maily_email_path(mailer: params[:mailer], method: params[:method])
|
40
|
+
end
|
41
|
+
|
42
|
+
def deliver
|
43
|
+
@email.to = params[:to]
|
44
|
+
|
45
|
+
@email.deliver
|
46
|
+
|
47
|
+
redirect_to maily_email_path(mailer: params[:mailer], method: params[:method])
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def allowed_action?
|
53
|
+
Maily.allowed_action?(action_name) || raise("Maily: action #{action_name} not allowed!")
|
54
|
+
end
|
55
|
+
|
56
|
+
def load_mailer_and_email
|
57
|
+
@mailer = Maily::Mailer.find(params[:mailer])
|
58
|
+
@email = @mailer.find_email(params[:method]).call
|
59
|
+
end
|
60
|
+
|
61
|
+
def perform_with_locale
|
62
|
+
I18n.with_locale(params[:locale]) do
|
63
|
+
yield
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Maily</title>
|
5
|
+
<%= stylesheet_link_tag "maily/application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "maily/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
<hr/>
|
14
|
+
<%= link_to "Maily v#{Maily::VERSION}", 'https://github.com/markets/maily' %>
|
15
|
+
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h1><%= "Editing: #{params[:mailer].humanize} > #{params[:method].humanize}" %></h1>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<%= link_to 'Return to list', root_path %> |
|
5
|
+
<%= link_to 'Show', maily_email_path(mailer: params[:mailer], method: params[:method]) %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<h2>Body</h2>
|
9
|
+
<%= form_tag(update_maily_email_path(mailer: params[:mailer], method: params[:method]), method: :put) do %>
|
10
|
+
<%= text_area_tag :body, @email, cols: 80, rows: 30 %>
|
11
|
+
<p><%= submit_tag 'Update' %></p>
|
12
|
+
<% end %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h1>Emails list</h1>
|
2
|
+
|
3
|
+
<ul>
|
4
|
+
<% @mailers.each do |mailer| %>
|
5
|
+
<h2><%= mailer.name.humanize %></h2>
|
6
|
+
<% mailer.emails.each do |email| %>
|
7
|
+
<li><%= link_to email.name.humanize, maily_email_path(mailer: mailer.name, method: email.name) %></li>
|
8
|
+
<% end %>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<h1><%= "#{params[:mailer].humanize} > #{params[:method].humanize}" %></h1>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<%= link_to 'Return to list', root_path %> |
|
5
|
+
<%= link_to 'Edit', edit_maily_email_path(mailer: params[:mailer], method: params[:method]) %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<h2>Send</h2>
|
9
|
+
<%= form_tag(deliver_maily_email_path(mailer: params[:mailer], method: params[:method], locale: params[:locale]), method: :post) do %>
|
10
|
+
<%= label_tag 'To:' %>
|
11
|
+
<%= email_field_tag :to %>
|
12
|
+
<%= submit_tag 'Send' %>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<h2>Languages</h2>
|
16
|
+
<p>
|
17
|
+
<% Maily.available_locales.each do |locale| %>
|
18
|
+
<%= link_to locale, url_for(params.merge(locale: locale)) %>
|
19
|
+
<% end %>
|
20
|
+
</p>
|
21
|
+
|
22
|
+
<h2>Details</h2>
|
23
|
+
<ul>
|
24
|
+
<li>Subject: <%= @email.subject %></li>
|
25
|
+
<li>From: <%= @email.from %></li>
|
26
|
+
<li>To: <%= @email.to %></li>
|
27
|
+
<li>Cc: <%= @email.cc %></li>
|
28
|
+
<li>Bcc: <%= @email.bcc %></li>
|
29
|
+
</ul>
|
30
|
+
|
31
|
+
<p>
|
32
|
+
<%= link_to 'HTML', url_for(params.merge(part: 'html')) if @email.html_part %>
|
33
|
+
<%= link_to 'TEXT', url_for(params.merge(part: 'text')) if @email.text_part %>
|
34
|
+
<% if @email.attachments.present? %>
|
35
|
+
<% @email.attachments.each do |attachment| %>
|
36
|
+
<%= link_to attachment.filename, attachment_maily_email_path(mailer: params[:mailer], method: params[:method], attachment: attachment.filename) %>
|
37
|
+
<% end %>
|
38
|
+
<% end %>
|
39
|
+
</p>
|
40
|
+
|
41
|
+
<% if @email.html_part || @email.text_part || @email.body.present? %>
|
42
|
+
<iframe src="<%= raw_maily_email_path(mailer: params[:mailer], method: params[:method], locale: params[:locale], part: params[:part]) %>" frameborder="1" height="100%" width="100%"></iframe>
|
43
|
+
<% end %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Maily::Engine.routes.draw do
|
2
|
+
get ':mailer/:method' => 'emails#show', as: :maily_email
|
3
|
+
get ':mailer/:method/raw' => 'emails#raw', as: :raw_maily_email
|
4
|
+
get ':mailer/:method/edit' => 'emails#edit', as: :edit_maily_email
|
5
|
+
put ':mailer/:method' => 'emails#update', as: :update_maily_email
|
6
|
+
post ':mailer/:method/deliver' => 'emails#deliver', as: :deliver_maily_email
|
7
|
+
get ':mailer/:method/attachment' => 'emails#attachment', as: :attachment_maily_email
|
8
|
+
|
9
|
+
root :to => 'emails#index'
|
10
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Maily
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
desc 'Maily installation: route and initializer'
|
5
|
+
source_root File.expand_path("../../templates", __FILE__)
|
6
|
+
|
7
|
+
def install
|
8
|
+
generate_routing
|
9
|
+
build_initializer
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def generate_routing
|
15
|
+
route "mount Maily::Engine, at: 'maily'"
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_initializer
|
19
|
+
template 'initializer.rb', 'config/initializers/maily.rb'
|
20
|
+
|
21
|
+
hooks = []
|
22
|
+
fixtures = []
|
23
|
+
|
24
|
+
Maily::Mailer.all.each do |mailer|
|
25
|
+
hooks << "# Maily.hooks_for('#{mailer.name.classify}') do |mailer|"
|
26
|
+
mailer.emails.each do |email|
|
27
|
+
if email.require_hook?
|
28
|
+
fixtures << email.required_arguments
|
29
|
+
hooks << "# mailer.register_hook(:#{email.name}, #{email.required_arguments.join(', ')})"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
hooks << "# end\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
inject_into_file "config/initializers/maily.rb", after: "end\n" do
|
36
|
+
"\n" + fixtures.flatten.uniq.map{ |f| f = "# #{f.to_s} = ''" }.join("\n") +
|
37
|
+
"\n" + hooks.join("\n")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Maily.init!
|
2
|
+
|
3
|
+
# Maily.setup do |config|
|
4
|
+
# On/off engine. True by default
|
5
|
+
# config.enabled = Rails.env.production? ? false : true
|
6
|
+
|
7
|
+
# Allow views edition. True by default
|
8
|
+
# config.allow_edition = Rails.env.production? ? false : true
|
9
|
+
|
10
|
+
# Allow deliveries. True by default
|
11
|
+
# config.allow_delivery = Rails.env.production? ? false : true
|
12
|
+
|
13
|
+
# I18n.available_locales by default
|
14
|
+
# config.available_locales = [:en, :es, :pt, :fr]
|
15
|
+
|
16
|
+
# 'ActionController::Base' by default
|
17
|
+
# config.base_controller = 'FooController'
|
18
|
+
# end
|
data/lib/maily.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'maily/engine'
|
2
|
+
require 'maily/version'
|
3
|
+
require 'maily/mailer'
|
4
|
+
require 'maily/email'
|
5
|
+
|
6
|
+
module Maily
|
7
|
+
class << self
|
8
|
+
|
9
|
+
attr_accessor :enabled, :allow_edition, :allow_delivery, :available_locales, :base_controller
|
10
|
+
|
11
|
+
def init!
|
12
|
+
self.enabled = true
|
13
|
+
self.allow_edition = true
|
14
|
+
self.allow_delivery = true
|
15
|
+
self.available_locales = I18n.available_locales
|
16
|
+
self.base_controller = 'ActionController::Base'
|
17
|
+
end
|
18
|
+
|
19
|
+
def build_emails
|
20
|
+
Dir[Rails.root + 'app/mailers/*.rb'].each do |mailer|
|
21
|
+
klass = File.basename(mailer, '.rb')
|
22
|
+
methods = klass.camelize.constantize.send(:instance_methods, false)
|
23
|
+
Maily::Mailer.new(klass, methods)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def hooks_for(mailer_name)
|
28
|
+
mailer = Maily::Mailer.find(mailer_name.underscore)
|
29
|
+
yield(mailer) if block_given?
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup
|
33
|
+
yield(self)
|
34
|
+
end
|
35
|
+
|
36
|
+
def allowed_action?(action)
|
37
|
+
case action.to_sym
|
38
|
+
when :edit, :update
|
39
|
+
allow_edition
|
40
|
+
when :deliver
|
41
|
+
allow_delivery
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/maily/email.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Maily
|
2
|
+
class Email
|
3
|
+
|
4
|
+
attr_accessor :name, :mailer, :arguments
|
5
|
+
|
6
|
+
def initialize(name, mailer)
|
7
|
+
self.name = name.to_s
|
8
|
+
self.mailer = mailer
|
9
|
+
self.arguments = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def require_hook?
|
13
|
+
mailer_klass.instance_method(name).parameters.any?
|
14
|
+
end
|
15
|
+
|
16
|
+
def required_arguments
|
17
|
+
mailer_klass.instance_method(name).parameters.map(&:last)
|
18
|
+
end
|
19
|
+
|
20
|
+
def register_hook(*args)
|
21
|
+
self.arguments = args.flatten
|
22
|
+
end
|
23
|
+
|
24
|
+
def mailer_klass_name
|
25
|
+
mailer.camelize
|
26
|
+
end
|
27
|
+
|
28
|
+
def mailer_klass
|
29
|
+
mailer_klass_name.constantize
|
30
|
+
end
|
31
|
+
|
32
|
+
def call
|
33
|
+
mailer_klass.send(name, *arguments)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/maily/engine.rb
ADDED
data/lib/maily/mailer.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Maily
|
2
|
+
class Mailer
|
3
|
+
|
4
|
+
cattr_accessor :collection
|
5
|
+
attr_accessor :name, :emails
|
6
|
+
|
7
|
+
def initialize(name, methods)
|
8
|
+
self.collection ||= []
|
9
|
+
self.name = name
|
10
|
+
self.emails = self.class.build_emails(methods, name)
|
11
|
+
self.collection << self
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.all
|
15
|
+
Maily.build_emails if collection.nil?
|
16
|
+
collection
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.find(mailer_name)
|
20
|
+
all.find { |mailer| mailer.name == mailer_name }
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.build_emails(methods, mailer)
|
24
|
+
methods.map do |email|
|
25
|
+
Maily::Email.new(email, mailer)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def register_hook(email_name, *args)
|
30
|
+
email = find_email(email_name)
|
31
|
+
email.register_hook(args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_email(email_name)
|
35
|
+
emails.find { |email| email.name == email_name.to_s }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/maily.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "maily/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "maily"
|
9
|
+
s.version = Maily::VERSION
|
10
|
+
s.authors = ["markets"]
|
11
|
+
s.email = ["srmarc.ai@gmail.com"]
|
12
|
+
s.homepage = "https://github.com/markets/maily"
|
13
|
+
s.summary = "Rails Engine to follow up application emails."
|
14
|
+
s.description = "Rails Engine to follow up application emails."
|
15
|
+
s.license = "MIT"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split($/)
|
18
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "rails", ">= 3.0.0"
|
23
|
+
|
24
|
+
s.add_development_dependency 'debugger'
|
25
|
+
end
|
data/script/rails
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/maily/engine', __FILE__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'rails/engine/commands'
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maily
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- markets
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-01-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: debugger
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Rails Engine to follow up application emails.
|
47
|
+
email:
|
48
|
+
- srmarc.ai@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- Gemfile.lock
|
56
|
+
- MIT-LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- app/assets/images/maily/.gitkeep
|
60
|
+
- app/assets/javascripts/maily/application.js
|
61
|
+
- app/assets/stylesheets/maily/application.css
|
62
|
+
- app/controllers/maily/application_controller.rb
|
63
|
+
- app/controllers/maily/emails_controller.rb
|
64
|
+
- app/helpers/maily/application_helper.rb
|
65
|
+
- app/helpers/maily/emails_helper.rb
|
66
|
+
- app/views/layouts/maily/application.html.erb
|
67
|
+
- app/views/maily/emails/edit.html.erb
|
68
|
+
- app/views/maily/emails/index.html.erb
|
69
|
+
- app/views/maily/emails/show.html.erb
|
70
|
+
- config/routes.rb
|
71
|
+
- lib/generators/maily/install_generator.rb
|
72
|
+
- lib/generators/templates/initializer.rb
|
73
|
+
- lib/maily.rb
|
74
|
+
- lib/maily/email.rb
|
75
|
+
- lib/maily/engine.rb
|
76
|
+
- lib/maily/mailer.rb
|
77
|
+
- lib/maily/version.rb
|
78
|
+
- maily.gemspec
|
79
|
+
- script/rails
|
80
|
+
homepage: https://github.com/markets/maily
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.8.23
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Rails Engine to follow up application emails.
|
105
|
+
test_files: []
|