maily 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/.gitignore +1 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +46 -7
  4. data/app/assets/images/maily/fonts/JosefinSans-Light.ttf +0 -0
  5. data/app/assets/images/maily/icons/maily.eot +0 -0
  6. data/app/assets/images/maily/icons/maily.svg +90 -0
  7. data/app/assets/images/maily/icons/maily.ttf +0 -0
  8. data/app/assets/images/maily/icons/maily.woff +0 -0
  9. data/app/assets/javascripts/maily/application.js +0 -14
  10. data/app/assets/javascripts/maily/html5shiv.js +8 -0
  11. data/app/assets/stylesheets/maily/application.scss +310 -0
  12. data/app/assets/stylesheets/maily/icons.css +199 -0
  13. data/app/assets/stylesheets/maily/normalize.css +406 -0
  14. data/app/controllers/maily/emails_controller.rb +14 -12
  15. data/app/helpers/maily/application_helper.rb +3 -0
  16. data/app/helpers/maily/emails_helper.rb +3 -0
  17. data/app/views/layouts/maily/application.html.erb +10 -4
  18. data/app/views/maily/emails/edit.html.erb +19 -10
  19. data/app/views/maily/emails/index.html.erb +2 -9
  20. data/app/views/maily/emails/show.html.erb +59 -36
  21. data/app/views/maily/shared/_footer.html.erb +3 -0
  22. data/app/views/maily/shared/_header.html.erb +3 -0
  23. data/app/views/maily/shared/_sidebar.html.erb +12 -0
  24. data/config/routes.rb +6 -6
  25. data/lib/generators/maily/install_generator.rb +9 -8
  26. data/lib/generators/templates/initializer.rb +6 -8
  27. data/lib/maily.rb +7 -1
  28. data/lib/maily/email.rb +39 -5
  29. data/lib/maily/mailer.rb +1 -1
  30. data/lib/maily/version.rb +1 -1
  31. data/maily.gemspec +2 -2
  32. data/screenshot.png +0 -0
  33. metadata +17 -6
  34. data/Gemfile.lock +0 -99
  35. data/app/assets/stylesheets/maily/application.css +0 -13
@@ -1,12 +1,11 @@
1
1
  module Maily
2
2
  class EmailsController < ApplicationController
3
-
4
3
  before_filter :allowed_action?, only: [:edit, :update, :deliver]
5
- before_filter :load_mailer_and_email, except: [:index, :edit, :update]
4
+ before_filter :load_mailers, only: [:index, :show, :edit]
5
+ before_filter :load_mailer_and_email, except: [:index]
6
6
  around_filter :perform_with_locale, only: [:show, :raw, :deliver]
7
7
 
8
8
  def index
9
- @mailers = Maily::Mailer.all
10
9
  end
11
10
 
12
11
  def show
@@ -28,15 +27,13 @@ module Maily
28
27
  end
29
28
 
30
29
  def edit
31
- @email = File.read("#{Rails.root}/app/views/#{params[:mailer]}/#{params[:method]}.html.erb")
30
+ @template = @maily_email.template(params[:part])
32
31
  end
33
32
 
34
33
  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
34
+ @maily_email.update_template(params[:body], params[:part])
38
35
 
39
- redirect_to maily_email_path(mailer: params[:mailer], method: params[:method])
36
+ redirect_to maily_email_path(mailer: params[:mailer], email: params[:email], part: params[:part])
40
37
  end
41
38
 
42
39
  def deliver
@@ -44,7 +41,7 @@ module Maily
44
41
 
45
42
  @email.deliver
46
43
 
47
- redirect_to maily_email_path(mailer: params[:mailer], method: params[:method])
44
+ redirect_to maily_email_path(mailer: params[:mailer], email: params[:email])
48
45
  end
49
46
 
50
47
  private
@@ -53,9 +50,14 @@ module Maily
53
50
  Maily.allowed_action?(action_name) || raise("Maily: action #{action_name} not allowed!")
54
51
  end
55
52
 
53
+ def load_mailers
54
+ @mailers = Maily::Mailer.all
55
+ end
56
+
56
57
  def load_mailer_and_email
57
- @mailer = Maily::Mailer.find(params[:mailer])
58
- @email = @mailer.find_email(params[:method]).call
58
+ mailer = Maily::Mailer.find(params[:mailer])
59
+ @maily_email = mailer.find_email(params[:email])
60
+ @email = @maily_email.call
59
61
  end
60
62
 
61
63
  def perform_with_locale
@@ -64,4 +66,4 @@ module Maily
64
66
  end
65
67
  end
66
68
  end
67
- end
69
+ end
@@ -1,4 +1,7 @@
1
1
  module Maily
2
2
  module ApplicationHelper
3
+ def sidebar_class(mailer, email)
4
+ 'maily_selected_mail' if mailer.name == params[:mailer] && email.name == params[:email]
5
+ end
3
6
  end
4
7
  end
@@ -1,4 +1,7 @@
1
1
  module Maily
2
2
  module EmailsHelper
3
+ def part_class(part)
4
+ 'format_selected' if (part == params[:part]) || (part == 'html' && !params[:part])
5
+ end
3
6
  end
4
7
  end
@@ -5,13 +5,19 @@
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]-->
8
12
  </head>
9
13
  <body>
14
+ <%= render 'maily/shared/header' %>
10
15
 
11
- <%= yield %>
12
-
13
- <hr/>
14
- <%= link_to "Maily v#{Maily::VERSION}", 'https://github.com/markets/maily' %>
16
+ <div class="wrap_content clearfix">
17
+ <%= render 'maily/shared/sidebar' %>
18
+ <%= yield %>
19
+ </div>
15
20
 
21
+ <%= render 'maily/shared/footer' %>
16
22
  </body>
17
23
  </html>
@@ -1,12 +1,21 @@
1
- <h1><%= "Editing: #{params[:mailer].humanize} > #{params[:method].humanize}" %></h1>
1
+ <div class="content">
2
+ <%= form_tag(update_maily_email_path(mailer: params[:mailer], email: params[:email], part: params[:part]), method: :put) do %>
3
+ <ul class="maily_action_bar">
4
+ <li>
5
+ <em class="icon-maily-eye"></em>
6
+ <%= link_to 'Show', maily_email_path(mailer: params[:mailer], email: params[:email]) %>
7
+ </li>
2
8
 
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>
9
+ <li class="maily_splitter">|</li>
7
10
 
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 %>
11
+ <li>
12
+ <em class="icon-maily-checkmark"></em>
13
+ <%= submit_tag 'Update', class: 'maily_button' %>
14
+ </li>
15
+ </ul>
16
+
17
+ <div class="maily_mail_preview">
18
+ <%= text_area_tag :body, @template, class:'maily_mail_updatearea' %>
19
+ </div>
20
+ <% end %>
21
+ </div>
@@ -1,10 +1,3 @@
1
- <h1>Emails list</h1>
1
+ <div class="content">
2
+ </div>
2
3
 
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>
@@ -1,43 +1,66 @@
1
- <h1><%= "#{params[:mailer].humanize} > #{params[:method].humanize}" %></h1>
1
+ <div class="content">
2
+ <ul class="maily_action_bar">
3
+ <li>
4
+ <em class="icon-maily-pencil"></em>
5
+ <%= link_to 'Edit', edit_maily_email_path(mailer: params[:mailer], email: params[:email], part: params[:part]) %>
6
+ </li>
2
7
 
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>
8
+ <li class="maily_languages">
9
+ <% if Maily.available_locales.present? %>
10
+ <ul>
11
+ <li>
12
+ <em class="icon-maily-earth"></em>
13
+ Languages:</li>
14
+ <% Maily.available_locales.each do |locale| %>
15
+ <li><%= link_to locale.upcase, url_for(params.merge(locale: locale)) %></li>
16
+ <% end %>
17
+ </ul>
18
+ <% end %>
19
+ </li>
7
20
 
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 %>
21
+ <li class="maily_splitter">|</li>
22
+ <li>
23
+ <%= form_tag(deliver_maily_email_path(mailer: params[:mailer], email: params[:email], locale: params[:locale]), method: :post, class: 'maily_send') do %>
24
+ <ul>
25
+ <li>Send to:</li>
26
+ <li><%= email_field_tag :to, nil, class: 'maily_textfield', placeholder: "Enter email", required: true %></li>
27
+ <li><%= submit_tag 'Send', class: 'maily_button' %></li>
28
+ </ul>
29
+ <% end %>
30
+ </li>
31
+ </ul>
14
32
 
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>
33
+ <div class="maily_mail_preview">
34
+ <ul class="maily_mail_details">
35
+ <% if @email.subject %><li><b>Subject</b> <%= @email.subject %></li><% end %>
36
+ <% if @email.from %><li><b>From</b> <%= @email.from.join(', ') %></li><% end %>
37
+ <% if @email.to %><li><b>To</b> <%= @email.to.join(', ') %></li><% end %>
38
+ <% if @email.cc %><li><b>Cc</b> <%= @email.cc.join(', ') %></li><% end %>
39
+ <% if @email.bcc %><li><b>Bcc</b> <%= @email.bcc.join(', ') %></li><% end %>
40
+ </ul>
21
41
 
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>
42
+ <% if @email.html_part && @email.text_part %>
43
+ <ul class="maily_format_mail">
44
+ <li><%= link_to 'HTML', url_for(params.merge(part: 'html')), class: part_class('html') %></li>
45
+ <li><%= link_to 'TEXT', url_for(params.merge(part: 'text')), class: part_class('text') %></li>
46
+ </ul>
47
+ <% end %>
30
48
 
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) %>
49
+ <% if @email.html_part || @email.text_part || @email.body.present? %>
50
+ <iframe class="maily_preview" src="<%= raw_maily_email_path(mailer: params[:mailer], email: params[:email], locale: params[:locale], part: params[:part]) %>" frameborder="1" height="100%" width="100%"></iframe>
37
51
  <% end %>
38
- <% end %>
39
- </p>
40
52
 
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 %>
53
+ <% if @email.attachments.present? %>
54
+ <ul class="maily_mail_attachments">
55
+ <li>Attachments:</li>
56
+ <li>
57
+ <ul>
58
+ <% @email.attachments.each do |attachment| %>
59
+ <li><em class="icon-maily-attachment"></em><%= link_to attachment.filename, attachment_maily_email_path(mailer: params[:mailer], email: params[:email], attachment: attachment.filename) %></li>
60
+ <% end %>
61
+ </ul>
62
+ </li>
63
+ </ul>
64
+ <% end %>
65
+ </div>
66
+ </div>
@@ -0,0 +1,3 @@
1
+ <footer class="footer">
2
+ <%= link_to content_tag(:em, "", class: 'icon-maily-github') + "Maily v#{Maily::VERSION}", 'https://github.com/markets/maily' %>
3
+ </footer>
@@ -0,0 +1,3 @@
1
+ <header class="header">
2
+ <a href="<%= root_path %>" class="logo_link"><em class="icon-maily-envelope"></em>Maily</a>
3
+ </header>
@@ -0,0 +1,12 @@
1
+ <aside class="sidebar">
2
+ <% @mailers.each do |mailer| %>
3
+ <section class="nav_list">
4
+ <h3 class="title nav_title"><%= mailer.name.humanize %></h3>
5
+ <ul>
6
+ <% mailer.emails.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
+ <% end %>
9
+ </ul>
10
+ </section>
11
+ <% end %>
12
+ </aside>
@@ -1,10 +1,10 @@
1
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
2
+ get ':mailer/:email' => 'emails#show', as: :maily_email
3
+ get ':mailer/:email/raw' => 'emails#raw', as: :raw_maily_email
4
+ get ':mailer/:email/edit' => 'emails#edit', as: :edit_maily_email
5
+ put ':mailer/:email' => 'emails#update', as: :update_maily_email
6
+ post ':mailer/:email/deliver' => 'emails#deliver', as: :deliver_maily_email
7
+ get ':mailer/:email/attachment' => 'emails#attachment', as: :attachment_maily_email
8
8
 
9
9
  root :to => 'emails#index'
10
10
  end
@@ -7,6 +7,7 @@ module Maily
7
7
  def install
8
8
  generate_routing
9
9
  build_initializer
10
+ build_hooks
10
11
  end
11
12
 
12
13
  private
@@ -17,26 +18,26 @@ module Maily
17
18
 
18
19
  def build_initializer
19
20
  template 'initializer.rb', 'config/initializers/maily.rb'
21
+ end
20
22
 
21
- hooks = []
23
+ def build_hooks
22
24
  fixtures = []
25
+ hooks = []
23
26
 
24
27
  Maily::Mailer.all.each do |mailer|
25
- hooks << "# Maily.hooks_for('#{mailer.name.classify}') do |mailer|"
28
+ hooks << "\nMaily.hooks_for('#{mailer.name.classify}') do |mailer|"
26
29
  mailer.emails.each do |email|
27
30
  if email.require_hook?
28
31
  fixtures << email.required_arguments
29
- hooks << "# mailer.register_hook(:#{email.name}, #{email.required_arguments.join(', ')})"
32
+ hooks << " mailer.register_hook(:#{email.name}, #{email.required_arguments.join(', ')})"
30
33
  end
31
34
  end
32
- hooks << "# end\n"
35
+ hooks << "end"
33
36
  end
34
37
 
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
+ create_file "lib/maily_hooks.rb" do
39
+ fixtures.flatten.uniq.map{ |f| f = "#{f.to_s} = ''" }.join("\n") + "\n" + hooks.join("\n") + "\n"
38
40
  end
39
-
40
41
  end
41
42
  end
42
43
  end
@@ -1,18 +1,16 @@
1
- Maily.init!
2
-
3
- # Maily.setup do |config|
1
+ Maily.setup do |config|
4
2
  # On/off engine. True by default
5
- # config.enabled = Rails.env.production? ? false : true
3
+ # config.enabled = Rails.env.production? ? false : true
6
4
 
7
5
  # Allow views edition. True by default
8
- # config.allow_edition = Rails.env.production? ? false : true
6
+ # config.allow_edition = Rails.env.production? ? false : true
9
7
 
10
8
  # Allow deliveries. True by default
11
- # config.allow_delivery = Rails.env.production? ? false : true
9
+ # config.allow_delivery = Rails.env.production? ? false : true
12
10
 
13
11
  # I18n.available_locales by default
14
12
  # config.available_locales = [:en, :es, :pt, :fr]
15
13
 
16
14
  # 'ActionController::Base' by default
17
- # config.base_controller = 'FooController'
18
- # end
15
+ # config.base_controller = 'FooController'
16
+ end
@@ -16,12 +16,17 @@ module Maily
16
16
  self.base_controller = 'ActionController::Base'
17
17
  end
18
18
 
19
- def build_emails
19
+ def load_emails_and_hooks
20
+ # Load emails
20
21
  Dir[Rails.root + 'app/mailers/*.rb'].each do |mailer|
21
22
  klass = File.basename(mailer, '.rb')
22
23
  methods = klass.camelize.constantize.send(:instance_methods, false)
23
24
  Maily::Mailer.new(klass, methods)
24
25
  end
26
+
27
+ # Load hooks
28
+ hooks_file_path = "#{Rails.root}/lib/maily_hooks.rb"
29
+ require hooks_file_path if File.exists?(hooks_file_path)
25
30
  end
26
31
 
27
32
  def hooks_for(mailer_name)
@@ -30,6 +35,7 @@ module Maily
30
35
  end
31
36
 
32
37
  def setup
38
+ init!
33
39
  yield(self)
34
40
  end
35
41
 
@@ -1,12 +1,13 @@
1
1
  module Maily
2
2
  class Email
3
3
 
4
- attr_accessor :name, :mailer, :arguments
4
+ attr_accessor :name, :mailer, :arguments, :template_path
5
5
 
6
6
  def initialize(name, mailer)
7
- self.name = name.to_s
8
- self.mailer = mailer
9
- self.arguments = nil
7
+ self.name = name.to_s
8
+ self.mailer = mailer
9
+ self.arguments = nil
10
+ self.template_path = mailer
10
11
  end
11
12
 
12
13
  def require_hook?
@@ -18,7 +19,14 @@ module Maily
18
19
  end
19
20
 
20
21
  def register_hook(*args)
21
- self.arguments = args.flatten
22
+ args = args.flatten
23
+
24
+ if args.last.is_a?(Hash) && new_path = args.last.delete(:template_path)
25
+ self.template_path = new_path
26
+ args.pop
27
+ end
28
+
29
+ self.arguments = args
22
30
  end
23
31
 
24
32
  def mailer_klass_name
@@ -32,5 +40,31 @@ module Maily
32
40
  def call
33
41
  mailer_klass.send(name, *arguments)
34
42
  end
43
+
44
+ def base_path(part)
45
+ "#{Rails.root}/app/views/#{template_path}/#{name}.#{part}.erb"
46
+ end
47
+
48
+ def path(part = nil)
49
+ if part
50
+ base_path(part)
51
+ else
52
+ if File.exist?(path('html'))
53
+ base_path('html')
54
+ else
55
+ base_path('text')
56
+ end
57
+ end
58
+ end
59
+
60
+ def template(part = nil)
61
+ File.read(path(part))
62
+ end
63
+
64
+ def update_template(new_content, part = nil)
65
+ File.open(path(part), 'w') do |f|
66
+ f.write(new_content)
67
+ end
68
+ end
35
69
  end
36
70
  end