letter_bomb 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +2 -3
- data/app/controllers/letter_bomb/mailers_controller.rb +29 -3
- data/app/views/letter_bomb/mailers/index.html.erb +2 -2
- data/app/views/letter_bomb/mailers/show.html.erb +13 -6
- data/lib/letter_bomb/engine.rb +0 -12
- data/lib/letter_bomb/preview.rb +10 -2
- data/lib/letter_bomb/version.rb +1 -1
- data/spec/dummy/app/mailers/foo_mailer_preview.rb +12 -0
- data/spec/dummy/app/mailers/user_mailer/preview.rb +6 -0
- data/spec/dummy/app/mailers/user_mailer.rb +1 -13
- data/spec/dummy/app/views/user_mailer/welcome.html.erb +1 -1
- data/spec/dummy/app/views/user_mailer/welcome.text.erb +3 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +10568 -0
- data/spec/dummy/log/test.log +913 -0
- data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/pids/server.pid +1 -1
- data/spec/lib/letter_bomb/preview_spec.rb +4 -17
- data/spec/requests/mailer_preview_listing_spec.rb +3 -2
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca88daac8b46e5920ae83fb0df5232d37deab93d
|
4
|
+
data.tar.gz: e01a4819e6c2717b49db1a82f7c34590b29d5804
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df503fcfd3a2406b40c15dc87780c24b8ae38c6c0ae575cf48fb0389ca9b086f1b3995240f000651a38defc82f5f40f19ecac5dcaec39f7b138dd61fdc01c2ea
|
7
|
+
data.tar.gz: b063d82333e4db87cd7560265921d64e3bfb3046b021f9d607b5ccd83de8e41b9e1a9d865ba5967bd6e9213efe484536046efbef8fb06d89e5e6ba87fb95c071
|
data/README.md
CHANGED
@@ -25,7 +25,8 @@ mount LetterBomb::Engine, at: '/letter_bomb'
|
|
25
25
|
|
26
26
|
and hit `/letter_bomb` for a list of previews.
|
27
27
|
|
28
|
-
Previews can be defined anywhere within `app/mailers`.
|
28
|
+
Previews can be defined anywhere within `app/mailers` suffixed with `preview`, i.e. `app/mailers/user_mailer_preview.rb` or `app/mailers/user_mailer/preview.rb`.
|
29
|
+
Preview method names are arbitrary so long as they return a `Mail` object.
|
29
30
|
|
30
31
|
```ruby
|
31
32
|
class UserMailer::Preview < LetterBomb::Preview
|
@@ -53,8 +54,6 @@ class UserMailer::Preview < LetterBomb::Preview
|
|
53
54
|
end
|
54
55
|
```
|
55
56
|
|
56
|
-
Preview class names and methods are arbitrary so long as they return a `Mail` object.
|
57
|
-
|
58
57
|
Alternatives
|
59
58
|
------------
|
60
59
|
|
@@ -1,13 +1,39 @@
|
|
1
1
|
module LetterBomb
|
2
2
|
class MailersController < ApplicationController
|
3
|
+
|
3
4
|
def index
|
4
5
|
@mailers = LetterBomb::Preview.previews
|
5
6
|
end
|
6
7
|
|
7
8
|
def show
|
8
|
-
|
9
|
-
|
10
|
-
@mail =
|
9
|
+
klass = params[:mailer_class]
|
10
|
+
@action = params[:mailer_action]
|
11
|
+
@mail = klass.constantize.preview_action(@action)
|
12
|
+
|
13
|
+
respond_to do |format|
|
14
|
+
format.html
|
15
|
+
format.text { render formats: [:html], content_type: 'text/html' }
|
16
|
+
end
|
11
17
|
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def body_part
|
22
|
+
return @mail unless @mail.multipart?
|
23
|
+
|
24
|
+
content_type = Rack::Mime.mime_type(".#{params[:format]}")
|
25
|
+
if @mail.respond_to?(:all_parts)
|
26
|
+
@mail.all_parts.find { |part| part.content_type.match(content_type) } || @mail.parts.first
|
27
|
+
else
|
28
|
+
@mail.parts.find { |part| part.content_type.match(content_type) } || @mail.parts.first
|
29
|
+
end
|
30
|
+
end
|
31
|
+
helper_method :body_part
|
32
|
+
|
33
|
+
def html_template?
|
34
|
+
params[:format] == 'html'
|
35
|
+
end
|
36
|
+
helper_method :html_template?
|
37
|
+
|
12
38
|
end
|
13
39
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
<h1>
|
1
|
+
<h1>Mailer Previews</h1>
|
2
2
|
|
3
3
|
<% @mailers.each do |mailer| %>
|
4
4
|
<p><%= mailer.to_s %></p>
|
5
5
|
|
6
6
|
<ul>
|
7
7
|
<% mailer.mailer_actions.each do |action| %>
|
8
|
-
<li><%= link_to action, mailer_path(mailer.to_s, action) %></li>
|
8
|
+
<li><%= link_to action, mailer_path(mailer.to_s, action, format: :html) %></li>
|
9
9
|
<% end %>
|
10
10
|
</ul>
|
11
11
|
|
@@ -75,14 +75,21 @@
|
|
75
75
|
|
76
76
|
<dt>To:</dt>
|
77
77
|
<dd><%= @mail.to %></dd>
|
78
|
-
|
79
|
-
<dt>Content-Type:</dt>
|
80
|
-
<dd><%= @mail.content_type %></dd>
|
81
78
|
</dl>
|
79
|
+
|
80
|
+
<% if @mail.multipart? %>
|
81
|
+
<p class="alternate">
|
82
|
+
<% if html_template? %>
|
83
|
+
<a href="<%= @action %>.txt">View plain text version</a>
|
84
|
+
<% else %>
|
85
|
+
<a href="<%= @action %>.html">View HTML version</a>
|
86
|
+
<% end %>
|
87
|
+
</p>
|
88
|
+
<% end %>
|
82
89
|
</div>
|
83
90
|
|
84
|
-
<% if
|
85
|
-
<%=
|
91
|
+
<% if html_template? %>
|
92
|
+
<%= body_part.body.to_s.html_safe %>
|
86
93
|
<% else %>
|
87
|
-
<pre id="message_body"><%=
|
94
|
+
<pre id="message_body"><%= body_part.body %></pre>
|
88
95
|
<% end %>
|
data/lib/letter_bomb/engine.rb
CHANGED
@@ -1,17 +1,5 @@
|
|
1
1
|
module LetterBomb
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
isolate_namespace LetterBomb
|
4
|
-
|
5
|
-
initializer 'letterbomb.mailers.autoload' do |app|
|
6
|
-
# TODO this is sloppy. the reason behind it is:
|
7
|
-
# 1) to generate the list of previews, we need all subclasses.
|
8
|
-
# rails doesn't load them up front, so we need to do that manually.
|
9
|
-
#
|
10
|
-
# 2) because we load the mailers and previews up-front, we have to manually tell
|
11
|
-
# rails to reload each per request.
|
12
|
-
ActionDispatch::Callbacks.before do
|
13
|
-
Dir[File.join(app.config.root, "/app/mailers/**/*.rb")].each { |file| load(file) }
|
14
|
-
end
|
15
|
-
end
|
16
4
|
end
|
17
5
|
end
|
data/lib/letter_bomb/preview.rb
CHANGED
@@ -2,11 +2,15 @@ module LetterBomb
|
|
2
2
|
class Preview
|
3
3
|
|
4
4
|
def self.previews
|
5
|
-
|
5
|
+
load_dir = Rails.application.root.join('app/mailers').to_s
|
6
|
+
Dir.glob(load_dir + '/**/*preview.rb').map do |filename|
|
7
|
+
# app/mailers/module/class.rb => module/class.rb => module/class => Module::Class
|
8
|
+
lchomp(filename, load_dir).chomp('.rb').camelize.constantize
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
12
|
def self.mailer_actions
|
9
|
-
|
13
|
+
public_instance_methods(false).map(&:to_s).sort
|
10
14
|
end
|
11
15
|
|
12
16
|
def self.preview_action(mailer_action)
|
@@ -29,5 +33,9 @@ module LetterBomb
|
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
36
|
+
def self.lchomp(base, arg)
|
37
|
+
base.to_s.reverse.chomp(arg.to_s.reverse).reverse
|
38
|
+
end
|
39
|
+
|
32
40
|
end
|
33
41
|
end
|
data/lib/letter_bomb/version.rb
CHANGED
@@ -4,18 +4,6 @@ class UserMailer < ActionMailer::Base
|
|
4
4
|
|
5
5
|
def welcome(var)
|
6
6
|
@var = var
|
7
|
-
mail(subject: 'welcome to the show!')
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class UserMailer::Preview < LetterBomb::Preview
|
12
|
-
def welcome
|
13
|
-
user = User.create!(name: 'john')
|
14
|
-
UserMailer.welcome(user.name)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class UserMailer::PreviewAgaian < LetterBomb::Preview
|
19
|
-
def foo
|
7
|
+
mail(subject: 'welcome to the show!')
|
20
8
|
end
|
21
9
|
end
|
Binary file
|
Binary file
|