email_preview 0.4.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +25 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -46
- data/app/controllers/email_preview_controller.rb +11 -1
- data/app/views/email_preview/details.html.erb +49 -0
- data/app/views/email_preview/index.html.erb +2 -2
- data/app/views/email_preview/navigation.html.erb +2 -2
- data/app/views/email_preview/show.html.erb +10 -41
- data/config/routes.rb +2 -0
- data/email_preview.gemspec +17 -53
- data/lib/{engine.rb → email_preview/engine.rb} +0 -0
- data/lib/email_preview/version.rb +3 -0
- data/lib/email_preview.rb +20 -8
- data/test/test_email_preview.rb +1 -1
- metadata +18 -15
- data/VERSION +0 -1
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,23 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "email_preview"
|
8
|
-
gem.summary = %Q{preview emails within your webbrowser}
|
9
|
-
gem.description = %Q{render and send sample html and plain text emails to see what they will *really* look like}
|
10
|
-
gem.email = "ryan@socialcast.com"
|
11
|
-
gem.homepage = "http://github.com/wireframe/email_preview"
|
12
|
-
gem.authors = ["Ryan Sonnek"]
|
13
|
-
gem.add_runtime_dependency "mail", ">= 2.2.3"
|
14
|
-
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
15
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
-
end
|
17
|
-
Jeweler::GemcutterTasks.new
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
21
3
|
|
22
4
|
require 'rake/testtask'
|
23
5
|
Rake::TestTask.new(:test) do |test|
|
@@ -25,30 +7,4 @@ Rake::TestTask.new(:test) do |test|
|
|
25
7
|
test.pattern = 'test/**/test_*.rb'
|
26
8
|
test.verbose = true
|
27
9
|
end
|
28
|
-
|
29
|
-
begin
|
30
|
-
require 'rcov/rcovtask'
|
31
|
-
Rcov::RcovTask.new do |test|
|
32
|
-
test.libs << 'test'
|
33
|
-
test.pattern = 'test/**/test_*.rb'
|
34
|
-
test.verbose = true
|
35
|
-
end
|
36
|
-
rescue LoadError
|
37
|
-
task :rcov do
|
38
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
task :test => :check_dependencies
|
43
|
-
|
44
10
|
task :default => :test
|
45
|
-
|
46
|
-
require 'rake/rdoctask'
|
47
|
-
Rake::RDocTask.new do |rdoc|
|
48
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
-
|
50
|
-
rdoc.rdoc_dir = 'rdoc'
|
51
|
-
rdoc.title = "email_preview #{version}"
|
52
|
-
rdoc.rdoc_files.include('README*')
|
53
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
-
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class EmailPreviewController < ApplicationController
|
2
2
|
unloadable
|
3
3
|
before_filter :enforce_allowed_environments
|
4
|
-
before_filter :build_email, :only => [:show, :deliver]
|
4
|
+
before_filter :build_email, :only => [:show, :deliver, :details, :preview]
|
5
5
|
layout nil
|
6
6
|
|
7
7
|
def deliver
|
@@ -9,11 +9,21 @@ class EmailPreviewController < ApplicationController
|
|
9
9
|
@mail.deliver
|
10
10
|
redirect_to email_preview_path(params[:id])
|
11
11
|
end
|
12
|
+
def preview
|
13
|
+
@part = if request.format == 'html'
|
14
|
+
@parts.detect {|p| p.content_type.include?('text/html') }
|
15
|
+
else
|
16
|
+
@parts.detect {|p| p.content_type.include?('text/plain') }
|
17
|
+
end
|
18
|
+
@part ||= @parts.first
|
19
|
+
render :text => @part.body.to_s
|
20
|
+
end
|
12
21
|
private
|
13
22
|
def enforce_allowed_environments
|
14
23
|
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)
|
15
24
|
end
|
16
25
|
def build_email
|
17
26
|
@mail = EmailPreview.preview params[:id]
|
27
|
+
@parts = @mail.multipart? ? @mail.parts : [@mail]
|
18
28
|
end
|
19
29
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<style>
|
2
|
+
.headers {
|
3
|
+
color: #333;
|
4
|
+
}
|
5
|
+
.headers dl {
|
6
|
+
margin: 0;
|
7
|
+
padding: 0;
|
8
|
+
clear: both;
|
9
|
+
}
|
10
|
+
.headers dt {
|
11
|
+
width: 100px;
|
12
|
+
padding: 1px;
|
13
|
+
float: left;
|
14
|
+
text-align: right;
|
15
|
+
font-weight: bold;
|
16
|
+
color: #7f7f7f;
|
17
|
+
}
|
18
|
+
.headers dd {
|
19
|
+
margin-left: 110px;
|
20
|
+
padding: 1px;
|
21
|
+
}
|
22
|
+
|
23
|
+
.deliver_form {
|
24
|
+
margin-bottom: 0;
|
25
|
+
float: right;
|
26
|
+
}
|
27
|
+
.deliver_form input {
|
28
|
+
width: 250px;
|
29
|
+
}
|
30
|
+
</style>
|
31
|
+
<%= form_tag deliver_email_preview_path(params[:id]), :class => 'deliver_form' do %>
|
32
|
+
<%= text_field_tag :to, '', :placeholder => 'Send this email to me@yourcompany.com' %>
|
33
|
+
<button type="submit">Send</button>
|
34
|
+
<% end %>
|
35
|
+
<h2>Headers</h2>
|
36
|
+
<div class="headers">
|
37
|
+
<% @mail.header_fields.each do |header| %>
|
38
|
+
<dl>
|
39
|
+
<dt><%= header.name %></dt>
|
40
|
+
<dd><%= header.decoded %></dd>
|
41
|
+
</dl>
|
42
|
+
<% end %>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<h2>Content</h2>
|
46
|
+
<% @parts.each do |part| %>
|
47
|
+
<% render_format = part.content_type.include?('text/html') ? 'html' : 'txt' %>
|
48
|
+
<%= link_to "View #{render_format} output", preview_email_preview_path(params[:id], :format => render_format), :target => 'preview' %>
|
49
|
+
<% end %>
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<title>Email Preview</title>
|
5
5
|
</head>
|
6
6
|
<frameset cols="20%,*">
|
7
|
-
<frame src="<%= navigation_email_preview_index_path %>" name="
|
8
|
-
<frame name="
|
7
|
+
<frame src="<%= navigation_email_preview_index_path %>" name="index" />
|
8
|
+
<frame name="show" />
|
9
9
|
</frameset>
|
10
10
|
</html>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<ul>
|
2
2
|
<% EmailPreview.emails.each_index do |index| %>
|
3
|
-
<li><%= link_to EmailPreview.emails[index][:description], email_preview_path(index), :target => '
|
3
|
+
<li><%= link_to EmailPreview.emails[index][:description], email_preview_path(index), :target => 'show' %>
|
4
4
|
<% end%>
|
5
|
-
</ul>
|
5
|
+
</ul>
|
@@ -1,41 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
12
|
-
.content_type {
|
13
|
-
margin: .5em 0;
|
14
|
-
}
|
15
|
-
</style>
|
16
|
-
<%= form_tag deliver_email_preview_path(params[:id]), :class => 'deliver_form' do %>
|
17
|
-
<%= text_field_tag :to, '', :placeholder => 'Send this email to me@yourcompany.com' %>
|
18
|
-
<button type="submit">Send</button>
|
19
|
-
<% end %>
|
20
|
-
<h2>Message Headers</h2>
|
21
|
-
<pre class='headers'>
|
22
|
-
<%= @mail.header_fields.collect { |header| "#{header.name}: #{header.decoded}\n"}%>
|
23
|
-
</pre>
|
24
|
-
<!--
|
25
|
-
<h3>Debug output</h3>
|
26
|
-
<pre>
|
27
|
-
<%= @mail.to_s %>
|
28
|
-
</pre>
|
29
|
-
-->
|
30
|
-
|
31
|
-
<h2>Message Content</h2>
|
32
|
-
<% parts = @mail.multipart? ? @mail.parts : [@mail] %>
|
33
|
-
<% parts.each do |part| %>
|
34
|
-
<h3 class="content_type"><%= part.content_type %></h3>
|
35
|
-
<hr />
|
36
|
-
<% if part.content_type.include?('text/plain') %>
|
37
|
-
<pre><%= part.body %></pre>
|
38
|
-
<% elsif part.content_type.include?('text/html')%>
|
39
|
-
<%= part.body.to_s.html_safe %>
|
40
|
-
<% end %>
|
41
|
-
<% end %>
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Email Preview</title>
|
5
|
+
</head>
|
6
|
+
<frameset rows="300px,*">
|
7
|
+
<frame src="<%= details_email_preview_path(params[:id]) %>" name="details" />
|
8
|
+
<frame name="preview" />
|
9
|
+
</frameset>
|
10
|
+
</html>
|
data/config/routes.rb
CHANGED
data/email_preview.gemspec
CHANGED
@@ -1,60 +1,24 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "email_preview/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
6
|
+
s.name = "email_preview"
|
7
|
+
s.version = EmailPreview::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Ryan Sonnek"]
|
10
|
+
s.email = ["ryan@codecrate.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{simple tool to preview emails in development environment}
|
13
13
|
s.description = %q{render and send sample html and plain text emails to see what they will *really* look like}
|
14
|
-
s.email = %q{ryan@socialcast.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
"LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"app/controllers/email_preview_controller.rb",
|
26
|
-
"app/views/email_preview/index.html.erb",
|
27
|
-
"app/views/email_preview/navigation.html.erb",
|
28
|
-
"app/views/email_preview/show.html.erb",
|
29
|
-
"config/routes.rb",
|
30
|
-
"email_preview.gemspec",
|
31
|
-
"lib/email_preview.rb",
|
32
|
-
"lib/engine.rb",
|
33
|
-
"test/helper.rb",
|
34
|
-
"test/test_email_preview.rb"
|
35
|
-
]
|
36
|
-
s.homepage = %q{http://github.com/wireframe/email_preview}
|
37
|
-
s.require_paths = [%q{lib}]
|
38
|
-
s.rubygems_version = %q{1.8.1}
|
39
|
-
s.summary = %q{preview emails within your webbrowser}
|
40
|
-
s.test_files = [
|
41
|
-
"test/helper.rb",
|
42
|
-
"test/test_email_preview.rb"
|
43
|
-
]
|
44
14
|
|
45
|
-
|
46
|
-
s.specification_version = 3
|
15
|
+
s.rubyforge_project = "email_preview"
|
47
16
|
|
48
|
-
|
49
|
-
|
50
|
-
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
51
|
-
else
|
52
|
-
s.add_dependency(%q<mail>, [">= 2.2.3"])
|
53
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
54
|
-
end
|
55
|
-
else
|
56
|
-
s.add_dependency(%q<mail>, [">= 2.2.3"])
|
57
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
58
|
-
end
|
59
|
-
end
|
17
|
+
s.add_runtime_dependency(%q<mail>, [">= 2.2.3"])
|
18
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
60
19
|
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
File without changes
|
data/lib/email_preview.rb
CHANGED
@@ -1,22 +1,34 @@
|
|
1
1
|
require 'mail'
|
2
|
-
require 'engine' if defined?(Rails)
|
2
|
+
require 'email_preview/engine' if defined?(Rails)
|
3
3
|
|
4
4
|
module EmailPreview
|
5
|
-
|
6
5
|
class << self
|
7
6
|
attr_accessor :emails
|
8
7
|
attr_accessor :allowed_environments
|
8
|
+
attr_accessor :transactional
|
9
9
|
|
10
|
-
def allowed_environments
|
11
|
-
@allowed_environments ||= ['development', 'test']
|
12
|
-
@allowed_environments
|
13
|
-
end
|
14
10
|
def register(description, &block)
|
15
|
-
self.emails ||= []
|
16
11
|
self.emails << {:description => description, :block => block }
|
17
12
|
end
|
18
13
|
def preview(index)
|
19
|
-
|
14
|
+
mail = nil
|
15
|
+
ActiveRecord::Base.transaction do
|
16
|
+
mail = self.emails[index.to_i][:block].call
|
17
|
+
raise ActiveRecord::Rollback, "EmailPreview rollback" if EmailPreview.transactional?
|
18
|
+
end
|
19
|
+
mail
|
20
|
+
end
|
21
|
+
def transactional?
|
22
|
+
!!self.transactional
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
26
|
+
|
27
|
+
# initialize to empty array
|
28
|
+
EmailPreview.emails = []
|
29
|
+
|
30
|
+
# default to only run in development and test environment
|
31
|
+
EmailPreview.allowed_environments = %w{ development test }
|
32
|
+
|
33
|
+
# default to rollback transactions after previewing email
|
34
|
+
EmailPreview.transactional = true
|
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: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.4.2
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Sonnek
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: mail
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: shoulda
|
38
38
|
prerelease: false
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
@@ -48,31 +48,34 @@ dependencies:
|
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
50
|
description: render and send sample html and plain text emails to see what they will *really* look like
|
51
|
-
email:
|
51
|
+
email:
|
52
|
+
- ryan@codecrate.com
|
52
53
|
executables: []
|
53
54
|
|
54
55
|
extensions: []
|
55
56
|
|
56
|
-
extra_rdoc_files:
|
57
|
-
|
58
|
-
- README.rdoc
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
59
|
files:
|
60
60
|
- .document
|
61
|
+
- .gitignore
|
62
|
+
- Gemfile
|
61
63
|
- LICENSE
|
62
64
|
- README.rdoc
|
63
65
|
- Rakefile
|
64
|
-
- VERSION
|
65
66
|
- app/controllers/email_preview_controller.rb
|
67
|
+
- app/views/email_preview/details.html.erb
|
66
68
|
- app/views/email_preview/index.html.erb
|
67
69
|
- app/views/email_preview/navigation.html.erb
|
68
70
|
- app/views/email_preview/show.html.erb
|
69
71
|
- config/routes.rb
|
70
72
|
- email_preview.gemspec
|
71
73
|
- lib/email_preview.rb
|
72
|
-
- lib/engine.rb
|
74
|
+
- lib/email_preview/engine.rb
|
75
|
+
- lib/email_preview/version.rb
|
73
76
|
- test/helper.rb
|
74
77
|
- test/test_email_preview.rb
|
75
|
-
homepage:
|
78
|
+
homepage: ""
|
76
79
|
licenses: []
|
77
80
|
|
78
81
|
post_install_message:
|
@@ -100,11 +103,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
103
|
version: "0"
|
101
104
|
requirements: []
|
102
105
|
|
103
|
-
rubyforge_project:
|
106
|
+
rubyforge_project: email_preview
|
104
107
|
rubygems_version: 1.8.1
|
105
108
|
signing_key:
|
106
109
|
specification_version: 3
|
107
|
-
summary: preview emails
|
110
|
+
summary: simple tool to preview emails in development environment
|
108
111
|
test_files:
|
109
112
|
- test/helper.rb
|
110
113
|
- test/test_email_preview.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.4.2
|