2009-12-17 01:23:08 +00:00
|
|
|
module ActionMailer
|
|
|
|
module MailHelper
|
|
|
|
# Uses Text::Format to take the text and format it, indented two spaces for
|
|
|
|
# each line, and wrapped at 72 columns.
|
|
|
|
def block_format(text)
|
2010-06-01 09:32:16 +00:00
|
|
|
begin
|
|
|
|
require 'text/format'
|
|
|
|
rescue LoadError => e
|
|
|
|
$stderr.puts "You don't have text-format installed in your application. Please add it to your Gemfile and run bundle install"
|
|
|
|
raise e
|
|
|
|
end unless defined?(Text::Format)
|
|
|
|
|
2009-12-17 01:23:08 +00:00
|
|
|
formatted = text.split(/\n\r\n/).collect { |paragraph|
|
|
|
|
Text::Format.new(
|
|
|
|
:columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph
|
|
|
|
).format
|
|
|
|
}.join("\n")
|
|
|
|
|
|
|
|
# Make list points stand on their own line
|
|
|
|
formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" }
|
|
|
|
formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" }
|
|
|
|
|
|
|
|
formatted
|
|
|
|
end
|
2009-12-25 20:35:40 +00:00
|
|
|
|
|
|
|
# Access the mailer instance.
|
2010-01-24 18:52:44 +00:00
|
|
|
def mailer
|
2010-01-23 10:37:34 +00:00
|
|
|
@_controller
|
2009-12-25 20:35:40 +00:00
|
|
|
end
|
2010-01-22 10:01:21 +00:00
|
|
|
|
|
|
|
# Access the message instance.
|
2010-01-24 18:52:44 +00:00
|
|
|
def message
|
2010-01-24 18:36:42 +00:00
|
|
|
@_message
|
2010-01-22 10:01:21 +00:00
|
|
|
end
|
2009-12-17 01:23:08 +00:00
|
|
|
end
|
|
|
|
end
|