inlinestyler - Making Styled HTML Email Easy

Version: 0.2.4
Download:http://pypi.python.org/pypi/inlinestyler/
Source:http://github.com/dlanger/inlinestyler/
Keywords:inline, HTML, CSS, email, preflight

inlinestyler is an easy way to locally inline CSS into an HTML email message.

Styling HTML email is a black art. CSS works, but only when it's been placed inline on the individual elements (and event then, not always) - which makes development frustrating, and iteration slow.

The general solution is to use an inlining service, which takes a message with the CSS placed externally, and rewrites it so that all CSS is applied to the individual elements. The most widely used of these services - and as far as I can tell, the one that powers CampaignMonitor - is Premailer. It's a great service, and the guys behind it put a lot of work into keeping it up to date with the most recent discoveries in what works and what doesn't.

inlinestyler takes (most) of the functionality of Premailer, and makes it available locally, accessible without having call a remote service.

To see what inline-styler can do, check out this demo.

History

Dave Cranwell wrote the original inline-styler single-app Django project, and (graciously) released it. inlinestyler is a refactor of that project into a free-standing package usable outside of Django.

Requirements

inlinestyler requires the following packages in order to run:

  • cssutils
  • lxml

It also requires a css_complaiance.csv file, which indicates the compatibility of various email clients with certain CSS features. This is included with the package, but can be updated manually from Campaign Monitor's spreadsheet.

Usage

from inlinestyler.utils import inline_css
message_inline_css = inline_css(message_external_css)

message_external_css must be a string containing the message to be inlined, with the CSS presented in the HTML as one of:

  • an absolute link <link rel="stylesheet" href="http://mysite.com/styles.css" />
  • a <style> block in the <head>, without the use of @import.

The code will also calculate an estimate for how compatible your message is with various clients (using the css_compliance.csv file), but this number isn't yet exposed.

Contributions

All development happens at github: http://github.com/dlanger/inlinestyler.

To get yourself started:

  1. Clone this repo somewhere
  2. make init to install the right dependencies
  3. make test to run the test suite

Contributions are always more than welcome. If you see something missing, add it in and send me a pull request.

NOTE: Ubuntu 12.04 (and some other distros) include libxslt version 1.1.26, which changes the now-empty <head> tag to <head/> - which isn't valid HTML 5. To see which version of libxslt was used to build your libxml, examine the output of make init and look for the line that looks like Using build configuration of libxslt 1.1.XX; if that says 26, some test failures are expected (at which point, you can rely on TravisCI to run your tests for you).

You could also install your own version of libxslt from source, but you're probably going to have a bad time.

License

This distribution is licensed under the New BSD License. Please see the LICENSE file for a full copy of the license text.

As far as I can tell, Dave Cranwell released the underlying inline-styler project into the public domain:

I'm [...] releasing it to the public after many requests for the source.


inlinestyler - Making Styled HTML Email Easy

Version: 0.2.4
Download:http://pypi.python.org/pypi/inlinestyler/
Source:http://github.com/dlanger/inlinestyler/
Keywords:inline, HTML, CSS, email, preflight

inlinestyler是将CSS本地内联到HTML电子邮件的简单方法。

样式HTML电子邮件是黑色艺术。 CSS工作,但只有当它被放置 内联单个元素(事件然后,不总是) - 这使得 发展令人沮丧,迭代缓慢。

一般的解决方案是使用一个内联服务,它带有一个消息 CSS放在外部,并重写它,以便将所有CSS应用于 个人元素这些服务中最广泛使用的 - 就我而言 可以告诉您,CampaignMonitor的权限是 Premailer 。这是一个伟大的 服务,而背后的家伙则把很多工作保持在最新状态 最新的发现是什么,什么不起作用。

内部消费者采用(大部分)Premailer的功能,并使其成为可能 在本地可用,无需拨打远程服务即可访问。

要查看内置样式器可以执行的操作,请查看此演示

历史

Dave Cranwell 写了原始的内联样式单应用程序Django项目, 和(慷慨的)释放它。 inlinestyler是该项目的重构 一个可以在Django之外使用的独立软件包。

要求

inlinestyler需要以下包才能运行:

  • cssutils
  • lxml

它还需要一个 css_complaiance.csv 文件,它指示 各种电子邮件客户端与某些CSS功能的兼容性。这个 包含在包中,但可以手动更新 Campaign Monitor 的试算表。

用法

from inlinestyler.utils import inline_css
message_inline_css = inline_css(message_external_css)

message_external_css 必须是一个包含要内联的消息的字符串, CSS中呈现的CSS是以下之一:

代码还将计算您的消息与您的消息的兼容性的估计 各种客户端(使用 css_compliance.csv 文件),但是这个数字不是 但暴露。

贡献

所有开发都发生在github: http://github.com/dlanger/inlinestyler

要开始自己:

  1. Clone this repo somewhere
  2. make init to install the right dependencies
  3. make test to run the test suite
贡献总是比较受欢迎。如果你看到一些缺失的东西,添加它 进来,并发送一个拉请求。

注意:Ubuntu 12.04(和其他一些发行版)包括 libxslt 版本 1.1.26 ,它将现在的&lt; head&gt; 标签更改为&lt; head /&gt; - 无效HTML 5.查看哪个版本的 libxslt 用于构建 您的 libxml ,检查 make init 的输出并查找 这行看起来像使用libxslt 1.1.XX的构建配置;如果 说 26 ,预计会出现一些测试失败(在这一点上,你 可以依靠 TravisCI 为您运行测试。)

您也可以从源代码安装您自己的 libxslt 版本 你可能会有一个糟糕的时间。

许可证

此发行版根据新BSD许可证许可。请看 LICENSE 文件,以获取许可证文本的完整副本。

据我所知,Dave Cranwell 发布了基础内联样式器 项目进入公共领域:

I'm […] releasing it to the public after many requests for the source.




相关问题推荐