Class: ActionMailer::InStyle::Processor
- Inherits:
-
Object
- Object
- ActionMailer::InStyle::Processor
- Defined in:
- lib/action_mailer/in_style/processor.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#premailer ⇒ Object
readonly
Returns the value of attribute premailer.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_attachments! ⇒ Object
Re-add any attachments.
-
#add_html_part! ⇒ Object
Add an HTML part with CSS inlined.
-
#add_text_part! ⇒ Object
Add a text part with either the pre-existing text part, or one generated with premailer.
- #capture_existing_message_parts ⇒ Object
- #html_part ⇒ Object
-
#initialize(message) ⇒ Processor
constructor
Initialize Accepts one argument: - ActionMailer message object.
-
#inline! ⇒ Object
InStyle! Processes the message object, replacing the html part with an inlined html version.
- #original_message_parts ⇒ Object
- #reset_message_body! ⇒ Object
Constructor Details
#initialize(message) ⇒ Processor
Initialize Accepts one argument:
-
ActionMailer message object
16 17 18 19 20 21 |
# File 'lib/action_mailer/in_style/processor.rb', line 16 def initialize() @message = @existing_html_part = .html_part || (.content_type =~ /text\/html/ && ) @premailer = ActionMailer::InStyle::Premailer.new(html_part.body.to_s, :with_html_string => true, :remove_classes => true) end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
11 12 13 |
# File 'lib/action_mailer/in_style/processor.rb', line 11 def @message end |
#premailer ⇒ Object (readonly)
Returns the value of attribute premailer.
11 12 13 |
# File 'lib/action_mailer/in_style/processor.rb', line 11 def premailer @premailer end |
Class Method Details
.inline!(message) ⇒ Object
7 8 9 |
# File 'lib/action_mailer/in_style/processor.rb', line 7 def self.inline!() new().inline! end |
Instance Method Details
#add_attachments! ⇒ Object
Re-add any attachments
62 63 64 |
# File 'lib/action_mailer/in_style/processor.rb', line 62 def @existing_attachments.each {|a| .body << a } end |
#add_html_part! ⇒ Object
Add an HTML part with CSS inlined.
46 47 48 49 50 51 |
# File 'lib/action_mailer/in_style/processor.rb', line 46 def add_html_part! part = Mail::Part.new part.body = premailer.to_inline_css part.content_type = "text/html; charset=#{@msg_charset}" .html_part = part end |
#add_text_part! ⇒ Object
Add a text part with either the pre-existing text part, or one generated with premailer.
54 55 56 57 58 59 |
# File 'lib/action_mailer/in_style/processor.rb', line 54 def add_text_part! part = Mail::Part.new part.body = @existing_text_part || premailer.to_plain_text part.content_type = "text/plain; charset=#{@msg_charset}" .text_part = part end |
#capture_existing_message_parts ⇒ Object
66 67 68 69 70 |
# File 'lib/action_mailer/in_style/processor.rb', line 66 def @existing_text_part = .text_part && .text_part.body.to_s @existing_attachments = . @msg_charset = .charset end |
#html_part ⇒ Object
23 24 25 |
# File 'lib/action_mailer/in_style/processor.rb', line 23 def html_part @existing_html_part end |
#inline! ⇒ Object
InStyle! Processes the message object, replacing the html part with an inlined html version.
If the message contains attachments or text parts, these parts are preserved. If the message does not contain a text part, one will be constructed from the text content available in the html part.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/action_mailer/in_style/processor.rb', line 34 def inline! add_text_part! add_html_part! end |
#original_message_parts ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/action_mailer/in_style/processor.rb', line 72 def { :html_part => html_part, :text_part => @existing_text_part, :attachments => @existing_attachments, :charset => @msg_charset } end |
#reset_message_body! ⇒ Object
83 84 85 86 |
# File 'lib/action_mailer/in_style/processor.rb', line 83 def .body = nil .body.instance_variable_set("@parts", Mail::PartsList.new) end |