premailer-rails3 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in premailer-rails3.gemspec
4
+ gemspec
@@ -0,0 +1,13 @@
1
+ # Premailer Rails 3 README
2
+
3
+ This gem is a no config solution for the wonderful [Premailer gem](https://github.com/alexdunae/premailer) to be used with Rails 3.
4
+ It uses interceptors which were introduced in Rails 3 and tweaks all mails which
5
+ receive the `deliver` method and adds a plain text part to it and inlines all CSS rules into the HTML part.
6
+
7
+ Currently it ignores any stylesheets linked within the email in favour of applying the stylesheet found at `public/stylesheets/email.css` or, if you use SASS on Heroku with Hassle, at `tmp/hassle/stylesheets/email.css`.
8
+
9
+ ## Installation
10
+
11
+ Simply add the gem to your Gemfile in your Rails project:
12
+
13
+ gem 'premailer-rails3'
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,6 @@
1
+ require 'premailer'
2
+ require 'hpricot'
3
+ require 'premailer-rails3/premailer'
4
+ require 'premailer-rails3/hook'
5
+
6
+ Mail.register_interceptor(PremailerRails::Hook)
@@ -0,0 +1,19 @@
1
+ module PremailerRails
2
+ class Hook
3
+ def self.delivering_email(message)
4
+ premailer = Premailer.new(message.body.to_s)
5
+
6
+ # reset the body and add two new bodies with appropriate types
7
+ message.body = nil
8
+
9
+ message.html_part do
10
+ content_type "text/html; charset=utf-8"
11
+ body premailer.to_inline_css
12
+ end
13
+
14
+ message.text_part do
15
+ body premailer.to_plain_text
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module PremailerRails
2
+ class Premailer < ::Premailer
3
+ def initialize(html)
4
+ if defined? Hassle and Rails.configuration.middleware.include? Hassle
5
+ css_file = 'tmp/hassle/stylesheets/email.css'
6
+ else
7
+ css_file = 'public/stylesheets/email.css'
8
+ end
9
+
10
+ super(html, :with_html_string => true,
11
+ :adapter => :hpricot,
12
+ :css => css_file)
13
+ end
14
+
15
+ def load_html(string)
16
+ Hpricot(string)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module PremailerRails
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "premailer-rails3/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "premailer-rails3"
7
+ s.version = PremailerRails::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Philipe Fatio"]
10
+ s.email = ["philipe.fatio@gmail.com"]
11
+ s.homepage = "https://github.com/fphilipe/premailer-rails3"
12
+ s.summary = %q{Easily create HTML emails in Rails 3.}
13
+ s.description = %q{This gem brings you the power of the premailer gem to Rails 3
14
+ without any configuration needs. Create HTML emails, include a
15
+ CSS file as you do in a normal HTML document and premailer will
16
+ inline the included CSS.}
17
+
18
+ s.rubyforge_project = "premailer-rails3"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+
25
+ s.add_dependency("premailer", ["~> 1.7"])
26
+ s.add_dependency("hpricot", ["~> 0.8"])
27
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: premailer-rails3
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.1"
6
+ platform: ruby
7
+ authors:
8
+ - Philipe Fatio
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-21 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: premailer
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "1.7"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: hpricot
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "0.8"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: |-
39
+ This gem brings you the power of the premailer gem to Rails 3
40
+ without any configuration needs. Create HTML emails, include a
41
+ CSS file as you do in a normal HTML document and premailer will
42
+ inline the included CSS.
43
+ email:
44
+ - philipe.fatio@gmail.com
45
+ executables: []
46
+
47
+ extensions: []
48
+
49
+ extra_rdoc_files: []
50
+
51
+ files:
52
+ - Gemfile
53
+ - README.md
54
+ - Rakefile
55
+ - lib/premailer-rails3.rb
56
+ - lib/premailer-rails3/hook.rb
57
+ - lib/premailer-rails3/premailer.rb
58
+ - lib/premailer-rails3/version.rb
59
+ - premailer-rails3.gemspec
60
+ has_rdoc: true
61
+ homepage: https://github.com/fphilipe/premailer-rails3
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project: premailer-rails3
84
+ rubygems_version: 1.6.2
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Easily create HTML emails in Rails 3.
88
+ test_files: []
89
+