Module: ActionMailer::InlineCssHelper

Defined in:
lib/action_mailer/inline_css_helper.rb

Instance Method Summary collapse

Instance Method Details

#embedded_style_tag(file = mailer.mailer_name) ⇒ Object

Embed CSS loaded from a file in a ‘style’ tag. CSS file can be given with or without .css extension, and will be searched for in “#Rails.root/public/stylesheets/mailers” by default.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/action_mailer/inline_css_helper.rb', line 6

def embedded_style_tag(file = mailer.mailer_name)
  ['.css', ''].each do |ext|
    [Rails.root.join("public", "stylesheets", "mailers"), Rails.root].each do |parent_path|
      guessed_path = parent_path.join(file+ext).to_s
      if File.exist?(guessed_path)
        return (:style, File.read(guessed_path), {:type => "text/css"}, false)
      end
    end
  end
  nil
end