email_preview 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/email_preview_controller.rb +1 -1
- data/app/helpers/email_preview_helper.rb +5 -0
- data/app/views/email_preview/details.html.erb +2 -2
- data/app/views/email_preview/navigation.html.erb +3 -4
- data/app/views/email_preview/show.html.erb +1 -1
- data/lib/email_preview.rb +9 -25
- data/lib/email_preview/engine.rb +3 -1
- data/lib/email_preview/fixture.rb +25 -0
- data/lib/email_preview/version.rb +1 -1
- data/test/test_email_preview.rb +1 -1
- metadata +6 -4
@@ -24,7 +24,7 @@ class EmailPreviewController < ApplicationController
|
|
24
24
|
raise "'#{Rails.env}' is not in the supported list of environments from EmailPreview.allowed_environments: #{EmailPreview.allowed_environments.inspect}" unless EmailPreview.allowed_environments.include?(Rails.env)
|
25
25
|
end
|
26
26
|
def build_email
|
27
|
-
@fixture = EmailPreview
|
27
|
+
@fixture = EmailPreview[params[:id]]
|
28
28
|
@mail = EmailPreview.preview params[:id]
|
29
29
|
@parts = @mail.multipart? ? @mail.parts : [@mail]
|
30
30
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
h2, ul, li { margin:0; padding:0; }
|
3
3
|
|
4
4
|
h2 {
|
5
|
+
clear: both;
|
5
6
|
margin: 5px;
|
6
7
|
}
|
7
8
|
.headers {
|
@@ -57,9 +58,8 @@
|
|
57
58
|
<h2>Content</h2>
|
58
59
|
<ul>
|
59
60
|
<% @parts.each do |part| %>
|
60
|
-
<% render_format = (part.content_type && part.content_type.include?('text/html')) ? 'html' : 'txt' %>
|
61
61
|
<li>
|
62
|
-
<%= link_to "View #{render_format} output", preview_email_preview_path(params[:id], :format => render_format), :target => 'preview' %>
|
62
|
+
<%= link_to "View #{render_format(part)} output", preview_email_preview_path(params[:id], :format => render_format(part)), :target => 'preview' %>
|
63
63
|
</li>
|
64
64
|
<% end %>
|
65
65
|
</ul>
|
@@ -14,9 +14,8 @@
|
|
14
14
|
<% EmailPreview.categories.each do |category| %>
|
15
15
|
<h3><%= category %></h3>
|
16
16
|
<ul>
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
<% end%>
|
17
|
+
<% EmailPreview.registry.select {|f| f.category == category }.sort_by(&:description).each do |fixture| %>
|
18
|
+
<li><%= link_to fixture.description, email_preview_path(EmailPreview.registry.index(fixture)), :target => 'show' %>
|
19
|
+
<% end%>
|
21
20
|
</ul>
|
22
21
|
<% end %>
|
@@ -5,6 +5,6 @@
|
|
5
5
|
</head>
|
6
6
|
<frameset rows="250px,*">
|
7
7
|
<frame src="<%= details_email_preview_path(params[:id]) %>" name="details" />
|
8
|
-
<frame name="preview" />
|
8
|
+
<frame name="preview" src="<%= preview_email_preview_path(params[:id], :format => render_format(@parts.first)) %>" />
|
9
9
|
</frameset>
|
10
10
|
</html>
|
data/lib/email_preview.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'mail'
|
2
2
|
require 'email_preview/engine' if defined?(Rails)
|
3
|
+
require 'email_preview/fixture'
|
3
4
|
|
4
5
|
module EmailPreview
|
5
6
|
class << self
|
@@ -10,25 +11,24 @@ module EmailPreview
|
|
10
11
|
attr_accessor :before_preview_hook
|
11
12
|
|
12
13
|
def register(description, options={}, &block)
|
13
|
-
|
14
|
-
|
15
|
-
options[:category] ||= 'General'
|
16
|
-
options[:description] ||= description.to_s
|
17
|
-
options[:block] ||= block
|
18
|
-
self.registry[key] = options
|
14
|
+
fixture = EmailPreview::Fixture.new(description, options, &block)
|
15
|
+
self.registry << fixture
|
19
16
|
end
|
20
17
|
def categories
|
21
|
-
self.registry.
|
18
|
+
self.registry.collect {|f| f.category }.uniq
|
22
19
|
end
|
23
20
|
def preview(key)
|
24
21
|
EmailPreview.before_preview_hook.call
|
25
22
|
mail = nil
|
26
23
|
ActiveRecord::Base.transaction do
|
27
|
-
mail = self
|
24
|
+
mail = self[key].preview
|
28
25
|
raise ActiveRecord::Rollback, "EmailPreview rollback" if EmailPreview.transactional?
|
29
26
|
end
|
30
27
|
mail
|
31
28
|
end
|
29
|
+
def [](key)
|
30
|
+
self.registry[key.to_i]
|
31
|
+
end
|
32
32
|
def transactional?
|
33
33
|
!!self.transactional
|
34
34
|
end
|
@@ -36,26 +36,10 @@ module EmailPreview
|
|
36
36
|
@before_preview_hook = block
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
40
|
-
class Fixture
|
41
|
-
attr_accessor :id, :category, :description, :callback
|
42
|
-
def preview
|
43
|
-
@mail ||= self.callback.call
|
44
|
-
end
|
45
|
-
def preview_with_transaction
|
46
|
-
return preview_without_transaction unless EmailPreview.transactional?
|
47
|
-
mail = nil
|
48
|
-
ActiveRecord::Base.transaction do
|
49
|
-
mail = preview_without_transaction
|
50
|
-
raise ActiveRecord::Rollback, "EmailPreview rollback"
|
51
|
-
end
|
52
|
-
mail
|
53
|
-
end
|
54
|
-
end
|
55
39
|
end
|
56
40
|
|
57
41
|
# initialize registry
|
58
|
-
EmailPreview.registry =
|
42
|
+
EmailPreview.registry = []
|
59
43
|
|
60
44
|
# default to only run in development and test environment
|
61
45
|
EmailPreview.allowed_environments = %w{ development test }
|
data/lib/email_preview/engine.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
module EmailPreview
|
2
|
+
class Fixture
|
3
|
+
DEFAULT_CATEGORY = 'General'
|
4
|
+
attr_accessor :category, :description, :callback
|
5
|
+
|
6
|
+
def initialize(description, options = {}, &block)
|
7
|
+
self.category = options[:category] || DEFAULT_CATEGORY
|
8
|
+
self.description = options[:description] || description.to_s
|
9
|
+
self.callback = block
|
10
|
+
end
|
11
|
+
def preview
|
12
|
+
@mail ||= self.callback.call
|
13
|
+
end
|
14
|
+
def preview_with_transaction
|
15
|
+
return preview_without_transaction unless EmailPreview.transactional?
|
16
|
+
mail = nil
|
17
|
+
ActiveRecord::Base.transaction do
|
18
|
+
mail = preview_without_transaction
|
19
|
+
raise ActiveRecord::Rollback, "EmailPreview rollback"
|
20
|
+
end
|
21
|
+
mail
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/test/test_email_preview.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_preview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 1.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Sonnek
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- app/controllers/email_preview_controller.rb
|
84
|
+
- app/helpers/email_preview_helper.rb
|
84
85
|
- app/views/email_preview/details.html.erb
|
85
86
|
- app/views/email_preview/index.html.erb
|
86
87
|
- app/views/email_preview/navigation.html.erb
|
@@ -89,6 +90,7 @@ files:
|
|
89
90
|
- email_preview.gemspec
|
90
91
|
- lib/email_preview.rb
|
91
92
|
- lib/email_preview/engine.rb
|
93
|
+
- lib/email_preview/fixture.rb
|
92
94
|
- lib/email_preview/version.rb
|
93
95
|
- test/helper.rb
|
94
96
|
- test/test_email_preview.rb
|