Access the message attachments list.
# File lib/action_mailer/mail_helper.rb, line 28 28: def attachments 29: @_message.attachments 30: end
Uses Text::Format to take the text and format it, indented two spaces for each line, and wrapped at 72 columns.
# File lib/action_mailer/mail_helper.rb, line 5 5: def block_format(text) 6: formatted = text.split(/\n\r\n/).collect { |paragraph| 7: format_paragraph(paragraph) 8: }.join("\n") 9: 10: # Make list points stand on their own line 11: formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" } 12: formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" } 13: 14: formatted 15: end
Returns text wrapped at len columns and indented indent spaces.
my_text = "Here is a sample text with more than 40 characters" format_paragraph(my_text, 25, 4) # => " Here is a sample text with\n more than 40 characters"
# File lib/action_mailer/mail_helper.rb, line 40 40: def format_paragraph(text, len = 72, indent = 2) 41: sentences = [[]] 42: 43: text.split.each do |word| 44: if (sentences.last + [word]).join(' ').length > len 45: sentences << [word] 46: else 47: sentences.last << word 48: end 49: end 50: 51: sentences.map { |sentence| 52: "#{" " * indent}#{sentence.join(' ')}" 53: }.join "\n" 54: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.