From 74cfa354760d2eeb6dd9be1414a7b9365f96300d Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Wed, 7 Sep 2011 12:01:20 -0700 Subject: [PATCH] adding readme and simplifying file paths --- README.rdoc | 32 ++++++++++++++++++++++ letter_opener.gemspec | 2 +- lib/letter_opener/delivery_method.rb | 9 +++--- spec/letter_opener/delivery_method_spec.rb | 2 +- 4 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 README.rdoc diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..31f3a32 --- /dev/null +++ b/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 config/environments/development.rb + + config.action_mailer.delivery_method = :letter_opener + +Now any delivered mail will pop up in your browser. The messages are stored in tmp/letter_opener. + + +== 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. diff --git a/letter_opener.gemspec b/letter_opener.gemspec index 169f96a..9e189ee 100644 --- a/letter_opener.gemspec +++ b/letter_opener.gemspec @@ -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" diff --git a/lib/letter_opener/delivery_method.rb b/lib/letter_opener/delivery_method.rb index ef0a711..d1d4ecc 100644 --- a/lib/letter_opener/delivery_method.rb +++ b/lib/letter_opener/delivery_method.rb @@ -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 diff --git a/spec/letter_opener/delivery_method_spec.rb b/spec/letter_opener/delivery_method_spec.rb index a0f3e0b..5d6c708 100644 --- a/spec/letter_opener/delivery_method_spec.rb +++ b/spec/letter_opener/delivery_method_spec.rb @@ -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