Permalink
Browse files

adding readme and simplifying file paths

  • Loading branch information...
1 parent fe3755e commit 74cfa354760d2eeb6dd9be1414a7b9365f96300d @ryanb committed Sep 7, 2011
Showing with 38 additions and 7 deletions.
  1. +32 −0 README.rdoc
  2. +1 −1 letter_opener.gemspec
  3. +4 −5 lib/letter_opener/delivery_method.rb
  4. +1 −1 spec/letter_opener/delivery_method_spec.rb
View
@@ -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.
View
@@ -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"
@@ -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
@@ -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

0 comments on commit 74cfa35

Please sign in to comment.