Skip to content

JackDanger/inline_styles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

InlineStyles

Squish a CSS stylesheet into any semantic html

Why?

HTML-formatted emails don't render uniformly unless the css is attached to the 'style' attribute of every element. Unless you want to maintain your templates with explicit inline styles you'll need to apply them automatically.

How?

class Mailer < ActionMailer::Base
  def message(email)
    recipients email
    subject "Looks nice, eh?"
    html = render(:file   => "message.html",
                  :layout => "email_layout.html")
    body InlineStyles::Page.new.with_html(html).with_css(stylesheet_content).apply
  end

  protected

    def stylesheet_content
      File.read("#{Rails.root}/public/stylesheets/messages.css")
    end
end

Requirements

InlineStyles uses the css_parser and Hpricot gems

Copyright

Copyright (c) 2009 Jack Danger Canty. See LICENSE for details.

About

Apply CSS styles from a stylesheet directly into element attributes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages