Skip to content

Commit

Permalink
adding readme and simplifying file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Sep 7, 2011
1 parent fe3755e commit 74cfa35
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
32 changes: 32 additions & 0 deletions README.rdoc
@@ -0,0 +1,32 @@
= Letter Opener

Preview mail in your browser instead of sending it. When using the included delivery method, any sent mail will open automatically into the browser.

== Rails Setup

Add the gem to your development environment and run the +bundle+ command.

gem "letter_opener", :group => :development

And then set the delivery method in <tt>config/environments/development.rb</tt>

config.action_mailer.delivery_method = :letter_opener

Now any delivered mail will pop up in your browser. The messages are stored in <tt>tmp/letter_opener</tt>.


== Other Setup

This can be used with any environment that uses the Mail gem. Simply set the delivery method when configuring Mail and specify a location.

require "letter_opener"
Mail.defaults do
delivery_method LetterOpener::DeliveryMethod, :location => "tmp/letter_opener"
end


== Development & Feedback

Questions or comments? Please use the {issue tracker}[https://github.com/ryanb/private_pub/issues]. If you would like to contribue to this project, clone this repository and run +bundle+ and +rake+ to run the tests.

Special thanks to the {mail_view}[https://github.com/37signals/mail_view/] gem for inspiring this project.
2 changes: 1 addition & 1 deletion letter_opener.gemspec
Expand Up @@ -5,7 +5,7 @@ Gem::Specification.new do |s|
s.email = "ryan@railscasts.com"
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.description = "When mail is sent from your application, Letter Opener will open a preview in the browser instead of sending."

s.files = Dir["{lib,spec}/**/*", "[A-Z]*"] - ["Gemfile.lock"]
s.require_path = "lib"
Expand Down
9 changes: 4 additions & 5 deletions lib/letter_opener/delivery_method.rb
Expand Up @@ -5,14 +5,13 @@ def initialize(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|
path = File.join(@options[:location], "#{Time.now.to_i}_#{Digest::SHA1.hexdigest(mail.encoded)[0..6]}.html")
FileUtils.mkdir_p(@options[:location])
File.open(path, 'w') do |f|
template = File.expand_path("../views/index.html.erb", __FILE__)
f.write ERB.new(File.read(template)).result(binding)
end
Launchy.open("file://#{File.join(path, "index.html")}")
Launchy.open("file://#{path}")
end
end
end
2 changes: 1 addition & 1 deletion spec/letter_opener/delivery_method_spec.rb
Expand Up @@ -19,7 +19,7 @@
subject 'Hello'
body 'World!'
end
html = File.read(Dir["#{@location}/*/index.html"].first)
html = File.read(Dir["#{@location}/*.html"].first)
html.should include("Hello")
html.should include("World!")
end
Expand Down

0 comments on commit 74cfa35

Please sign in to comment.