-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit aac6696
Showing
11 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.gem | ||
.bundle | ||
Gemfile.lock | ||
pkg/* | ||
tmp/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--backtrace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rvm use 1.9.2@letter_opener --create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
source "http://rubygems.org" | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks | ||
require 'rspec/core/rake_task' | ||
|
||
desc "Run RSpec" | ||
RSpec::Core::RakeTask.new do |t| | ||
t.verbose = false | ||
end | ||
task :default => :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Gem::Specification.new do |s| | ||
s.name = "letter_opener" | ||
s.version = "0.0.1" | ||
s.author = "Ryan Bates" | ||
s.email = "[email protected]" | ||
s.homepage = "http://github.com/ryanb/letter_opener" | ||
s.summary = "Preview mail in browser instead of sending." | ||
s.description = "When mail is sent from your application, Open Mail will open a preview in the browser instead of sending." | ||
|
||
s.files = Dir["{lib,spec}/**/*", "[A-Z]*"] - ["Gemfile.lock"] | ||
s.require_path = "lib" | ||
|
||
s.add_dependency 'launchy' | ||
s.add_development_dependency 'rspec', '~> 2.6.0' | ||
s.add_development_dependency 'mail', '~> 2.3.0' | ||
|
||
s.rubyforge_project = s.name | ||
s.required_rubygems_version = ">= 1.3.4" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require "fileutils" | ||
require "digest/sha1" | ||
require "letter_opener/delivery_method" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module LetterOpener | ||
class DeliveryMethod | ||
def initialize(options = {}) | ||
@options = {:location => './letter_opener'}.merge!(options) | ||
end | ||
|
||
def deliver!(mail) | ||
identity = Time.now.to_i.to_s + Digest::SHA1.hexdigest(mail.encoded)[0..6] | ||
path = File.join(@options[:location], identity) | ||
FileUtils.mkdir_p(path) | ||
File.open(File.join(path, "index.html"), 'w') do |f| | ||
template = File.expand_path("../views/index.html.erb", __FILE__) | ||
f.write ERB.new(File.read(template)).result(binding) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<style type="text/css"> | ||
#message_headers { | ||
position: absolute; | ||
top: 0px; | ||
left: 0; | ||
width: 100%; | ||
height: 85px; | ||
padding: 10px 0 0 0; | ||
margin: 0; | ||
background: #fff; | ||
font-size: 12px; | ||
font-family: "Lucida Grande"; | ||
border-bottom: 1px solid #dedede; | ||
overflow: hidden; | ||
} | ||
|
||
#message_headers dl { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
#message_headers dt { | ||
width: 60px; | ||
padding: 1px; | ||
float: left; | ||
text-align: right; | ||
font-weight: bold; | ||
color: #7f7f7f; | ||
} | ||
|
||
#message_headers dd { | ||
margin-left: 70px; | ||
padding: 1px; | ||
} | ||
|
||
#message_headers p.alternate { | ||
position: absolute; | ||
top: 0; | ||
right: 15px; | ||
} | ||
|
||
#message_headers p.alternate a { | ||
color: #09c; | ||
} | ||
|
||
pre#message_body { | ||
padding: 10px; | ||
word-wrap: break-word; | ||
} | ||
|
||
body { | ||
margin-top: 96px; | ||
} | ||
</style> | ||
|
||
<div id="message_headers"> | ||
<dl> | ||
<dt>From:</dt> | ||
<dd><%= mail.from %></dd> | ||
|
||
<dt>Subject:</dt> | ||
<dd><strong><%= mail.subject %></strong></dd> | ||
|
||
<dt>Date:</dt> | ||
<dd><%= Time.now.strftime("%b %e, %Y %I:%M:%S %p %Z") %></dd> | ||
|
||
<dt>To:</dt> | ||
<dd><%= mail.to %></dd> | ||
</dl> | ||
|
||
<% if false && mail.multipart? %> | ||
<p class="alternate"> | ||
<% if body_part.content_type && body_part.content_type.match(/text\/html/) %> | ||
<a href="<%= name %>.txt">View plain text version</a> | ||
<% else %> | ||
<a href="<%= name %>.html">View HTML version</a> | ||
<% end %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<pre id="message_body"><%= mail.body %></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "spec_helper" | ||
|
||
describe LetterOpener::DeliveryMethod do | ||
before(:each) do | ||
location = File.expand_path('../../../tmp/letter_opener', __FILE__) | ||
FileUtils.rm_rf(location) | ||
Mail.defaults do | ||
delivery_method LetterOpener::DeliveryMethod, :location => location | ||
end | ||
@location = location | ||
end | ||
|
||
it "saves text into html document" do | ||
mail = Mail.deliver do | ||
from '[email protected]' | ||
to '[email protected]' | ||
subject 'Hello' | ||
body 'World!' | ||
end | ||
html = File.read(Dir["#{@location}/*/index.html"].first) | ||
html.should include("Hello") | ||
html.should include("World!") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
Bundler.require(:default) | ||
|
||
require "mail" | ||
|
||
RSpec.configure do |config| | ||
end |