A summary of data about the Ruby ecosystem.

https://github.com/premailer/premailer

Preflight for HTML email
https://github.com/premailer/premailer

Keywords

css inline mail nokogiri premailer ruby

Keywords from Contributors

activerecord activejob mvc rubygems rubocop css-parser rack code-formatter static-code-analysis crash-reporting

Last synced: about 2 hours ago
JSON representation

Repository metadata

Preflight for HTML email

README.md

Premailer README CI Gem Version

What is this?

For the best HTML e-mail delivery results, CSS should be inline. This is a
huge pain and a simple newsletter becomes un-managable very quickly. This
gem is a solution.

  • CSS styles are converted to inline style attributes
    • Checks style and link[rel=stylesheet] tags and preserves existing inline attributes
  • Relative paths are converted to absolute paths
    • Checks links in href, src and CSS url('')
  • CSS properties are checked against e-mail client capabilities
    • Based on the Email Standards Project's guides
  • A plain text version is created (optional)

Installation

gem install premailer

Example

require 'premailer'

premailer = Premailer.new('http://example.com/myfile.html', warn_level: Premailer::Warnings::SAFE)

# Write the plain-text output (must come before to_inline_css)
File.write "output.txt", premailer.to_plain_text

# Write the HTML output
File.write "output.html", premailer.to_inline_css

# Output any CSS warnings
premailer.warnings.each do |w|
  puts "#{w[:message]} (#{w[:level]}) may not render properly in #{w[:clients]}"
end

Adapters

  1. nokogiri (default)
  2. nokogiri_fast (20x speed, more memory)
  3. nokogumbo

(hpricot adapter removed, use ~>1.9.0 version if you need it)

Picking an adapter:

Premailer::Adapter.use = :nokogiri_fast

Ruby Compatibility

See .github/workflows/actions.yml for which ruby versions are tested. JRuby support is close, contributors are welcome.

Premailer-specific CSS

Premailer looks for a few CSS attributes that make working with tables a bit easier.

CSS Attribute Availability
-premailer-width Available on table, th and td elements
-premailer-height Available on table, tr, th and td elements
-premailer-cellpadding Available on table elements
-premailer-cellspacing Available on table elements
-premailer-align Available on table elements
data-premailer="ignore" Available on link and style elements. Premailer will ignore these elements entirely.

Each of these CSS declarations will be copied to appropriate element's attribute.

For example

table { -premailer-cellspacing: 5; -premailer-width: 500; }

will result in

<table cellspacing='5' width='500'>

Plain text version

Premailer can generate a plain text version of your HTML. Links and images will be inlined.

For example

<a href="https://example.com" >
  <img src="https://github.com/premailer.png" alt="Premailer Logo" />
</a>

will become

Premailer Logo ( https://example.com )

To ignore/omit a section of HTML content from the plain text version, wrap it with the following comments.

<!-- start text/html -->
<p>This will be omitted from the plain text version.</p>
<p>
  This is extremely helpful for <strong>removing email headers and footers</strong>
  that aren't needed in the text version.
</p>
<!-- end text/html -->

Configuration options

For example:

Premailer.new(
  html, # html as string
  with_html_string: true,
  drop_unmergeable_css_rules: true
)

available options

Support for CSS variables

The gem does not automatically replace CSS variables with their static values.

For example, if a variable is used to set the font-weight of an h1 element, the result will be

<h1 style="
  font-size:3rem;
  font-weight:var(--bulma-content-heading-weight);">
  Title</h1>

This causes the font-weight value to be the CSS variable call var(--bulma-content-heading-weight); instead of its static value.

Replace CSS variable calls with their static values

The following section instructs how to replace CSS variables with their static value in the context of a Ruby on Rails application.

Install the postcss-css-variables plugin for PostCSS to process the CSS variables.

yarn add postcss postcss-cli postcss-css-variables

To configure the plugin, create the file postcss.config.js in the root directory with the content:

module.exports = {
    plugins: [
        // https://github.com/MadLittleMods/postcss-css-variables to transform the css
      require("postcss-css-variables")({
        preserve: false, // Set to false to replace variables with static values
      }),
    ],
  };

In the package.json file, add the new "build:emails" to the scripts.Replace ./app/assets/stylesheets/emails.css with your file path:

"scripts": {
  "build:emails": "postcss ./app/assets/stylesheets/emails.css -o ./app/assets/builds/emails.css"
}

The previous script processes and overwrites the file at ./app/assets/stylesheets/emails.css with PostCSS using its postcss-css-variables plugin, replacing the CSS variables with their static value.

If the file to be processed is not .css, but .scss, it needs to be converted first to .css, then have its variables replaced. The script would then be

"scripts": {
  "build:emails": "sass ./app/assets/stylesheets/emails.scss:./app/assets/builds/emails.css --no-source-map --load-path=node_modules && postcss ./app/assets/builds/emails.css -o ./app/assets/builds/emails.css"
}

Next, to execute the script when running bin/dev, add the following line in the file Procfile.dev

emails_css: yarn build:emails --watch

The srcipt can also be executed separately with the command

yarn build:emails

Caveat

The variables must be declared before use. Otherwise, their values when called will be set to undefined.

Contributions

Contributions are most welcome.
Premailer was rotting away in a private SVN repository for too long and could use some TLC.
Fork and patch to your heart's content.
Please don't increment the version numbers.

A few areas that are particularly in need of love:

  • Improved test coverage
  • Move un-repeated background images defined in CSS for Outlook

Credits and code

Thanks to all the wonderful contributors for their updates.

Thanks to Greenhood + Company for sponsoring some of the 1.5.6 updates,
and to Campaign Monitor for supporting the web interface.

The source code can be found on GitHub.

Copyright by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-2017. See LICENSE.md for license details.


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 3 days ago

Total Commits: 647
Total Committers: 123
Avg Commits per committer: 5.26
Development Distribution Score (DDS): 0.728

Commits in past year: 11
Committers in past year: 3
Avg Commits per committer in past year: 3.667
Development Distribution Score (DDS) in past year: 0.455

Name Email Commits
Alex Dunae a****x@d****a 176
Akzhan Abdulin a****n@g****m 109
Michael Grosser m****l@g****t 97
Anthony McLin g****t@a****m 21
ju1ius j****e@l****t 10
Geremia Taglialatela t****v@g****m 9
Curt Howard c****t@p****m 9
Mark Edmondson m****k@g****m 9
Aaron a****i@g****m 7
Anton Rieder 1****r 6
hradu h****u@u****m 6
Aaron Breckenridge a****e@g****m 5
Matthew Landauer m****r@g****m 5
Stefan Hoffmann s****n@n****e 5
shields s****s@t****m 5
Wolfram Nikolas Müller w****m@f****m 4
Paul Sokolik s****k@s****m 4
Dave Weir d****r@i****o 4
Michael Bianco i****y@g****m 4
Orien Madgwick 4****n 4
Jason Berlinsky j****y@g****m 3
Johan Brook j****b@g****m 3
ryanscottaudio i****l@g****m 3
William Johnston w****m@j****s 3
Tommy Crumrine t****y@t****m 3
Mark Edmondson m****n@g****m 3
Odin Dutton o****n@g****m 3
James Matsuba j****a@g****m 3
Bragadeesh b****y@g****m 3
epinault-ttc e****t@t****m 3
and 93 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 4 days ago

Total issues: 61
Total pull requests: 96
Average time to close issues: over 1 year
Average time to close pull requests: 3 months
Total issue authors: 57
Total pull request authors: 45
Average comments per issue: 3.43
Average comments per pull request: 1.63
Merged pull request: 68
Bot issues: 0
Bot pull requests: 0

Past year issues: 4
Past year pull requests: 7
Past year average time to close issues: 1 day
Past year average time to close pull requests: 2 days
Past year issue authors: 4
Past year pull request authors: 4
Past year average comments per issue: 1.75
Past year average comments per pull request: 1.86
Past year merged pull request: 4
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/premailer/premailer

Top Issue Authors

  • tagliala (4)
  • dorianmariefr (2)
  • sampatbadhe (1)
  • ragesoss (1)
  • jherdman (1)
  • pravi (1)
  • dark-panda (1)
  • romanbsd (1)
  • jamesryanbell (1)
  • BenMorel (1)
  • jahvi (1)
  • seanhinton (1)
  • Mickyliu (1)
  • Spica2 (1)
  • GregOriol (1)

Top Pull Request Authors

  • grosser (17)
  • tagliala (14)
  • sokolikp (3)
  • orien (3)
  • wnm (3)
  • dorianmariefr (2)
  • internethostage (2)
  • searls (2)
  • aried3r (2)
  • garyhtou (2)
  • eflorit (2)
  • flipsasser (2)
  • composerinteralia (2)
  • ryanscottaudio (2)
  • johnnyshields (2)

Top Issue Labels

Top Pull Request Labels


Package metadata

gem.coop: premailer

Improve the rendering of HTML emails by making CSS inline, converting links and warning about unsupported code.

  • Homepage: https://github.com/premailer/premailer
  • Documentation: http://www.rubydoc.info/gems/premailer/
  • Licenses: BSD-3-Clause
  • Latest release: 1.28.0 (published 7 days ago)
  • Last Synced: 2026-03-02T05:32:28.794Z (1 day ago)
  • Versions: 51
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 117,066,177 Total
  • Docker Downloads: 454,578,523
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.115%
    • Downloads: 0.219%
    • Docker downloads count: 0.242%
  • Maintainers (2)
rubygems.org: premailer

Improve the rendering of HTML emails by making CSS inline, converting links and warning about unsupported code.

  • Homepage: https://github.com/premailer/premailer
  • Documentation: http://www.rubydoc.info/gems/premailer/
  • Licenses: BSD-3-Clause
  • Latest release: 1.28.0 (published 7 days ago)
  • Last Synced: 2026-03-02T00:02:50.978Z (1 day ago)
  • Versions: 51
  • Dependent Packages: 51
  • Dependent Repositories: 5,079
  • Downloads: 117,059,179 Total
  • Docker Downloads: 454,578,523
  • Rankings:
    • Downloads: 0.23%
    • Docker downloads count: 0.301%
    • Dependent repos count: 0.444%
    • Dependent packages count: 0.539%
    • Average: 0.643%
    • Stargazers count: 1.025%
    • Forks count: 1.317%
  • Maintainers (2)
proxy.golang.org: github.com/premailer/premailer

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/premailer/premailer#section-documentation
  • Licenses: other
  • Latest release: v1.27.0 (published over 1 year ago)
  • Last Synced: 2026-02-24T09:13:01.694Z (7 days ago)
  • Versions: 41
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent packages count: 8.686%
    • Average: 9.241%
    • Dependent repos count: 9.796%
ubuntu-23.10: ruby-premailer

  • Homepage: https://premailer.github.io/premailer/
  • Licenses:
  • Latest release: 1.14.2-1 (published 18 days ago)
  • Last Synced: 2026-02-13T18:29:52.587Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.04: ruby-premailer

  • Homepage: https://premailer.github.io/premailer/
  • Licenses:
  • Latest release: 1.22.0-1 (published 25 days ago)
  • Last Synced: 2026-02-06T15:46:49.653Z (25 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
ubuntu-23.04: ruby-premailer

  • Homepage: https://premailer.github.io/premailer/
  • Licenses:
  • Latest release: 1.14.2-1 (published 20 days ago)
  • Last Synced: 2026-02-11T06:46:58.060Z (20 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-20.04: ruby-premailer

  • Homepage: https://premailer.github.io/premailer/
  • Licenses:
  • Latest release: 1.11.1-2 (published 18 days ago)
  • Last Synced: 2026-02-13T07:20:12.087Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-11: ruby-premailer

  • Homepage: https://premailer.github.io/premailer/
  • Documentation: https://packages.debian.org/bullseye/ruby-premailer
  • Licenses:
  • Latest release: 1.14.2-1 (published 21 days ago)
  • Last Synced: 2026-02-13T08:23:28.794Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.10: ruby-premailer

  • Homepage: https://premailer.github.io/premailer/
  • Licenses:
  • Latest release: 1.22.0-1 (published 18 days ago)
  • Last Synced: 2026-02-13T09:54:13.184Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
ubuntu-22.04: ruby-premailer

  • Homepage: https://premailer.github.io/premailer/
  • Licenses:
  • Latest release: 1.14.2-1 (published 18 days ago)
  • Last Synced: 2026-02-13T13:23:09.652Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-12: ruby-premailer

  • Homepage: https://premailer.github.io/premailer/
  • Documentation: https://packages.debian.org/bookworm/ruby-premailer
  • Licenses:
  • Latest release: 1.14.2-1 (published 19 days ago)
  • Last Synced: 2026-02-12T23:37:36.703Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:

Dependencies

Gemfile rubygems
  • pry >= 0 development
  • jruby-openssl >= 0
Gemfile.lock rubygems
  • addressable 2.8.0
  • bump 0.10.0
  • coderay 1.1.3
  • coveralls 0.8.23
  • crack 0.4.5
  • css_parser 1.11.0
  • docile 1.4.0
  • ffi 1.15.4
  • hashdiff 1.0.1
  • htmlentities 4.3.4
  • jruby-openssl 0.11.0
  • json 2.6.1
  • maxitest 4.1.0
  • method_source 1.0.0
  • mini_portile2 2.8.0
  • minitest 5.14.4
  • nokogiri 1.13.4
  • premailer 1.16.0
  • pry 0.14.1
  • public_suffix 4.0.6
  • racc 1.6.0
  • rake 13.0.6
  • redcarpet 3.5.1
  • rexml 3.2.5
  • simplecov 0.16.1
  • simplecov-html 0.10.2
  • spoon 0.0.6
  • sync 0.5.0
  • term-ansicolor 1.7.1
  • thor 1.1.0
  • tins 1.29.1
  • webmock 3.14.0
premailer.gemspec rubygems
  • bump >= 0 development
  • bundler >= 1.3 development
  • coveralls >= 0 development
  • maxitest >= 0 development
  • nokogiri ~> 1.13 development
  • rake > 0.8, != 0.9.0 development
  • redcarpet ~> 3.0 development
  • webmock >= 0 development
  • addressable >= 0
  • css_parser >= 1.6.0
  • htmlentities >= 4.0.0
.github/workflows/actions.yml actions
  • actions/checkout v2 composite
  • ruby/setup-ruby v1 composite

Score: 33.49260421507827