Action Mailer MailHelper
为 ActionMailer::Base
提供辅助方法,用于轻松格式化消息、访问邮件或消息实例以及附件列表。
方法
- A
- B
- F
- M
实例公共方法
attachments() 链接
访问消息附件列表。
源代码: 显示 | 在 GitHub 上
# File actionmailer/lib/action_mailer/mail_helper.rb, line 45 def attachments mailer.attachments end
block_format(text) 链接
获取文本并对其进行格式化,每行缩进两个空格,并在 72 列处换行
text = <<-TEXT
This is
the paragraph.
* item1 * item2
TEXT
block_format text
# => " This is the paragraph.\n\n * item1\n * item2\n"
源代码: 显示 | 在 GitHub 上
# File actionmailer/lib/action_mailer/mail_helper.rb, line 22 def block_format(text) formatted = text.split(/\n\r?\n/).collect { |paragraph| format_paragraph(paragraph) }.join("\n\n") # Make list points stand on their own line formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { " #{$1} #{$2.strip}\n" } formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { " #{$1} #{$2.strip}\n" } formatted end
format_paragraph(text, len = 72, indent = 2) 链接
返回在 len
列处换行并在 indent
个空格处缩进的 text
。默认情况下,列长度 len
等于 72 个字符,缩进 indent
等于两个空格。
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"
源代码: 显示 | 在 GitHub 上
# File actionmailer/lib/action_mailer/mail_helper.rb, line 57 def format_paragraph(text, len = 72, indent = 2) sentences = [[]] text.split.each do |word| if sentences.first.present? && (sentences.last + [word]).join(" ").length > len sentences << [word] else sentences.last << word end end indentation = " " * indent sentences.map! { |sentence| "#{indentation}#{sentence.join(' ')}" }.join "\n" end
mailer() 链接
访问邮件实例。
来源:显示 | 在 GitHub 上
# File actionmailer/lib/action_mailer/mail_helper.rb, line 35 def mailer @_controller end
message() 链接
访问消息实例。
来源:显示 | 在 GitHub 上
# File actionmailer/lib/action_mailer/mail_helper.rb, line 40 def message @_message end