email_preview 0.2.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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +65 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/app/controllers/email_preview_controller.rb +18 -0
- data/app/views/email_preview/index.html.erb +12 -0
- data/app/views/email_preview/list.html.erb +5 -0
- data/app/views/email_preview/show.html.erb +33 -0
- data/config/routes.rb +10 -0
- data/email_preview.gemspec +63 -0
- data/lib/email_preview.rb +23 -0
- data/lib/engine.rb +2 -0
- data/test/helper.rb +10 -0
- data/test/test_email_preview.rb +19 -0
- metadata +113 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ryan Sonnek
|
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.rdoc
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
= email_preview
|
2
|
+
|
3
|
+
preview emails within your web browser
|
4
|
+
|
5
|
+
= Features
|
6
|
+
* preview HTML emails from within your web browser
|
7
|
+
* emails are reloaded with each view so you can tweak/save/refresh for instant verification
|
8
|
+
* convenient form to send any email preview directly to your *real* inbox
|
9
|
+
* only exposes routes in development mode to prevent leaking into production mode
|
10
|
+
|
11
|
+
= Installation
|
12
|
+
|
13
|
+
gem 'email_preview'
|
14
|
+
|
15
|
+
= Usage
|
16
|
+
|
17
|
+
config/initializers/email_preview.rb
|
18
|
+
EmailPreview.register 'simple example email' do
|
19
|
+
Mail.new do
|
20
|
+
to 'tom@example.com'
|
21
|
+
from 'me@foo.com'
|
22
|
+
body 'check this out'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
EmailPreview.register 'multipart email (html + text)' do
|
27
|
+
Mail.new do
|
28
|
+
from 'mikel@test.lindsaar.net'
|
29
|
+
to 'you@test.lindsaar.net'
|
30
|
+
subject 'This is a test email'
|
31
|
+
|
32
|
+
text_part do
|
33
|
+
body 'This is plain text'
|
34
|
+
end
|
35
|
+
html_part do
|
36
|
+
content_type 'text/html; charset=UTF-8'
|
37
|
+
body '<h1>This is HTML</h1>'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
EmailPreview.register 'user activation email' do
|
43
|
+
u = User.new :email => 'foo@example.com'
|
44
|
+
UserNotifier.activation
|
45
|
+
end
|
46
|
+
|
47
|
+
by default, email_preview is only available in development mode. to turn on globally use:
|
48
|
+
EmailPreview.allowed_environments << 'production'
|
49
|
+
|
50
|
+
browse the list of registered emails and preview them in your browser at:
|
51
|
+
http://localhost:3000/email_preview
|
52
|
+
|
53
|
+
== Note on Patches/Pull Requests
|
54
|
+
|
55
|
+
* Fork the project.
|
56
|
+
* Make your feature addition or bug fix.
|
57
|
+
* Add tests for it. This is important so I don't break it in a
|
58
|
+
future version unintentionally.
|
59
|
+
* Commit, do not mess with rakefile, version, or history.
|
60
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
61
|
+
* Send me a pull request. Bonus points for topic branches.
|
62
|
+
|
63
|
+
== Copyright
|
64
|
+
|
65
|
+
Copyright (c) 2010 Ryan Sonnek. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
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
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
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
|
+
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
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class EmailPreviewController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
before_filter :enforce_allowed_environments
|
4
|
+
before_filter :build_email, :only => [:show, :deliver]
|
5
|
+
|
6
|
+
def deliver
|
7
|
+
@mail.to params[:to]
|
8
|
+
@mail.deliver
|
9
|
+
redirect_to email_preview_path(params[:id])
|
10
|
+
end
|
11
|
+
private
|
12
|
+
def enforce_allowed_environments
|
13
|
+
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)
|
14
|
+
end
|
15
|
+
def build_email
|
16
|
+
@mail = EmailPreview.preview params[:id]
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<div>
|
2
|
+
To: <%= @mail.to %>
|
3
|
+
</div>
|
4
|
+
<div>
|
5
|
+
From: <%= @mail.from %>
|
6
|
+
</div>
|
7
|
+
<div>
|
8
|
+
Subject: <%= @mail.subject %>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<% form_tag deliver_email_preview_path(params[:id]) do %>
|
12
|
+
<p>Send this email to your inbox:</p>
|
13
|
+
<%= text_field_tag :to %>
|
14
|
+
<button type="submit">Send</button>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<!--
|
18
|
+
<h3>Debug output</h3>
|
19
|
+
<pre>
|
20
|
+
<%= @mail.to_s %>
|
21
|
+
</pre>
|
22
|
+
-->
|
23
|
+
|
24
|
+
<h3>Body</h3>
|
25
|
+
<% parts = @mail.multipart? ? @mail.parts : [@mail] %>
|
26
|
+
<% parts.each do |part| %>
|
27
|
+
<h4><%= part.content_type %></h4>
|
28
|
+
<% if part.content_type.include?('text/plain') %>
|
29
|
+
<pre><%= part.body %></pre>
|
30
|
+
<% elsif part.content_type.include?('text/html') %>
|
31
|
+
<%= part.body.to_s.html_safe %>
|
32
|
+
<% end %>
|
33
|
+
<% end %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{email_preview}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ryan Sonnek"]
|
12
|
+
s.date = %q{2010-06-09}
|
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
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"app/controllers/email_preview_controller.rb",
|
27
|
+
"app/views/email_preview/index.html.erb",
|
28
|
+
"app/views/email_preview/list.html.erb",
|
29
|
+
"app/views/email_preview/show.html.erb",
|
30
|
+
"config/routes.rb",
|
31
|
+
"email_preview.gemspec",
|
32
|
+
"lib/email_preview.rb",
|
33
|
+
"lib/engine.rb",
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/test_email_preview.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/wireframe/email_preview}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.7}
|
41
|
+
s.summary = %q{preview emails within your webbrowser}
|
42
|
+
s.test_files = [
|
43
|
+
"test/helper.rb",
|
44
|
+
"test/test_email_preview.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<mail>, [">= 2.2.3"])
|
53
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<mail>, [">= 2.2.3"])
|
56
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<mail>, [">= 2.2.3"])
|
60
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'engine' if defined?(Rails)
|
2
|
+
|
3
|
+
module EmailPreview
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :emails
|
7
|
+
attr_accessor :allowed_environments
|
8
|
+
|
9
|
+
def allowed_environments
|
10
|
+
@allowed_environments ||= ['development', 'test']
|
11
|
+
@allowed_environments
|
12
|
+
end
|
13
|
+
def register(key, &block)
|
14
|
+
self.emails ||= {}
|
15
|
+
self.emails[key] = block
|
16
|
+
end
|
17
|
+
def preview(key)
|
18
|
+
puts self.emails[key]
|
19
|
+
block = self.emails[key]
|
20
|
+
block.call
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/engine.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestEmailPreview < Test::Unit::TestCase
|
4
|
+
context "with one registered email" do
|
5
|
+
setup do
|
6
|
+
EmailPreview.register "basic email" do
|
7
|
+
Mail.new do
|
8
|
+
from 'mikel@test.lindsaar.net'
|
9
|
+
to 'you@test.lindsaar.net'
|
10
|
+
subject 'This is a test email'
|
11
|
+
body 'i like testing'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
should "have one entry in the configuration" do
|
16
|
+
assert_equal 1, EmailPreview.emails.keys.length
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: email_preview
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ryan Sonnek
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-09 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: mail
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
version: 2.2.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: thoughtbot-shoulda
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: render and send sample html and plain text emails to see what they will *really* look like
|
52
|
+
email: ryan@socialcast.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- LICENSE
|
59
|
+
- README.rdoc
|
60
|
+
files:
|
61
|
+
- .document
|
62
|
+
- .gitignore
|
63
|
+
- LICENSE
|
64
|
+
- README.rdoc
|
65
|
+
- Rakefile
|
66
|
+
- VERSION
|
67
|
+
- app/controllers/email_preview_controller.rb
|
68
|
+
- app/views/email_preview/index.html.erb
|
69
|
+
- app/views/email_preview/list.html.erb
|
70
|
+
- app/views/email_preview/show.html.erb
|
71
|
+
- config/routes.rb
|
72
|
+
- email_preview.gemspec
|
73
|
+
- lib/email_preview.rb
|
74
|
+
- lib/engine.rb
|
75
|
+
- test/helper.rb
|
76
|
+
- test/test_email_preview.rb
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://github.com/wireframe/email_preview
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- --charset=UTF-8
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.3.7
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: preview emails within your webbrowser
|
111
|
+
test_files:
|
112
|
+
- test/helper.rb
|
113
|
+
- test/test_email_preview.rb
|