GithubHelp home page GithubHelp logo

rallysf / premailer-rails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fphilipe/premailer-rails

0.0 13.0 0.0 509 KB

Inline CSS for emails made easy. Combines premailer with the asset pipeline.

License: MIT License

premailer-rails's Introduction

premailer-rails

Build Status Gem Version Dependency Status Code Climate Coverage Status

This gem is a no config solution for the wonderful Premailer gem to be used with Rails. It uses interceptors which were introduced in Rails 3 and tweaks all mails which are delivered and adds a plain text part to them and inlines all CSS rules into the HTML part.

By default it inlines all inline <style> declarations and all the CSS files that are linked to in the HTML:

<link type='text/css' ... />

Don't worry about the host in the CSS URL since this will be ignored.

The retrieval of the file depends on your assets configuration:

  • Rails 3.1 asset pipeline: It will load the compiled version of the CSS asset which is normally located in app/assets/stylesheets/. If the asset can't be found (e.g. it is only available on a CDN and not locally), it will be HTTP requested.

  • Classic static assets: It will try to load the CSS file located in public/stylesheets/

Installation

Simply add the gem to your Gemfile in your Rails project:

gem 'premailer-rails'

premailer-rails requires either nokogiri or hpricot. It doesn't list them as a dependency so you can choose which one to use.

gem 'nokogiri'
# or
gem 'hpricot'

If both are loaded for some reason, premailer chooses hpricot.

That's it!

Configuration

Premailer itself accepts a number of options. In order for premailer-rails to pass these options on to the underlying premailer instance, specify them in an initializer:

Premailer::Rails.config.merge!(preserve_styles: true,
                               remove_ids:      true)

For a list of options, refer to the Premailer documentation

The default configs are:

{
  input_encoding:     'UTF-8',
  inputencoding:      'UTF-8',
  generate_text_part: true
}

The input encoding option changed at some point. To make sure this option works regardless of the premailer version, the old and new setting is specified. If you want to use another encoding make sure to specify the right one or both.

If you don't want to automatically generate a text part from the html part, set the config :generate_text_part to false.

Note that the options :with_html_string and :css_string are used internally and thus will be overridden.

Bitdeli Badge

premailer-rails's People

Contributors

fphilipe avatar luma avatar der-flo avatar jonnii avatar andrewhubbs avatar bitdeli-chef avatar eclubb avatar guiocavalcanti avatar masterexploder avatar jezstephens avatar iloveitaly avatar rmarynch avatar svenwin avatar jlxw avatar zdenal avatar

Watchers

Michael Gregson avatar Serdar Yildirim avatar Sridhar Nallani avatar Sachin Maharjan avatar Sasha Devol avatar James Cloos avatar  avatar Rally avatar John Frost avatar Sunil kumar Pissaye avatar JJ avatar Satish Salokhe avatar JagadeeshwaranC avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.