sexxy-emails 0.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.
@@ -0,0 +1,40 @@
1
+ require 'nokogiri'
2
+ require 'css_parser'
3
+
4
+ module SexxyEmails::Css
5
+ include CssParser
6
+
7
+ class << self
8
+ # Takes a string of HTML and inlines any css blocks in it.
9
+ def inline(html, options = {})
10
+ Nokogiri::HTML(html).tap do |doc|
11
+ css_parser = CssParser::Parser.new
12
+ # Collect the style and remove from the html tree
13
+ doc.css('style').each do |style|
14
+ css_parser.add_block!(style.content)
15
+ style.remove
16
+ end
17
+
18
+ # Each selector
19
+ css_parser.each_selector do |selector, declaration|
20
+ doc.css(selector).each do |node|
21
+ node['style'] = merge_rules(node, selector, declaration)
22
+ end
23
+ end
24
+ end.to_s
25
+ end
26
+
27
+ protected
28
+ # Let existing styles be at the top of the cascade
29
+ def merge_rules(node, selector, declaration)
30
+ if node['style'].nil?
31
+ declaration
32
+ else
33
+ CssParser.merge(
34
+ RuleSet.new(nil, declaration),
35
+ RuleSet.new(nil, node['style'])).declarations_to_s
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,32 @@
1
+ module SexxyEmails
2
+ extend ActiveSupport::Autoload
3
+ extend ActiveSupport::Concern
4
+
5
+ autoload :Css
6
+
7
+ included do |base|
8
+ base.instance_eval do
9
+ helper SexxyEmails::MailerHelper
10
+ end
11
+ end
12
+
13
+ module MailerHelper
14
+ def stylesheet_include_tag(css)
15
+ path = css.match(/\.css/) ? s : "#{css}.css"
16
+ content_tag(:style) do
17
+ File.open(File.join(Rails.root, 'public', 'stylesheets', path)).read
18
+ end
19
+ end
20
+ end
21
+
22
+ # module ClassMethods
23
+ # # Some day we'll use ClassMethods
24
+ # end
25
+
26
+ module InstanceMethods
27
+ protected
28
+ def render(*args)
29
+ SexxyEmails::Css.inline(super(*args))
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ describe TestMailer do
4
+
5
+ it "should inline the css on render" do
6
+ SexxyEmails::Css.expects(:inline).once
7
+ TestMailer.basic_css
8
+ end
9
+
10
+ it "should properly style the paragraph tags" do
11
+ style = /<p style="font-size: 36px; font-family: Helvetica, sans-serif;">/
12
+ assert_match style, TestMailer.basic_css.to_s
13
+ end
14
+
15
+ it "should add tracking parameters to inbound links"
16
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ describe SexxyEmails::Css do
4
+ it "should respond to #inline(html, options)" do
5
+ html = "<html><head></head><body></body></html>"
6
+ SexxyEmails::Css.expects(:inline).once.with(html)
7
+ SexxyEmails::Css.inline(html)
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'pry'
3
+ require 'minitest/autorun'
4
+ require 'mocha'
5
+
6
+ # Load the example app
7
+ require File.expand_path('../../example_app/config/environment', __FILE__)
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sexxy-emails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Craig McNamara
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-11-10 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: css_parser
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: nokogiri
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rails
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 7
58
+ segments:
59
+ - 3
60
+ - 0
61
+ - 0
62
+ version: 3.0.0
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: rdoc
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: rake
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: minitest
95
+ prerelease: false
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ type: :development
106
+ version_requirements: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ name: mocha
109
+ prerelease: false
110
+ requirement: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ type: :development
120
+ version_requirements: *id007
121
+ description: Adds inline css support to action mailer so you can use a stylesheet to tame your email templates.
122
+ email: craig.mcnamara@gmail.com
123
+ executables: []
124
+
125
+ extensions: []
126
+
127
+ extra_rdoc_files: []
128
+
129
+ files:
130
+ - lib/sexxy_emails.rb
131
+ - lib/sexxy_emails/css.rb
132
+ - test/sexxy_emails/basic_mailer_test.rb
133
+ - test/sexxy_emails/css_test.rb
134
+ - test/test_helper.rb
135
+ has_rdoc: true
136
+ homepage: https://github.com/craigmcnamara/sexxy-emails
137
+ licenses: []
138
+
139
+ post_install_message:
140
+ rdoc_options:
141
+ - --all
142
+ - --inline-source
143
+ - --line-numbers
144
+ - --charset
145
+ - utf-8
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ hash: 3
154
+ segments:
155
+ - 0
156
+ version: "0"
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
165
+ version: "0"
166
+ requirements: []
167
+
168
+ rubyforge_project:
169
+ rubygems_version: 1.6.2
170
+ signing_key:
171
+ specification_version: 3
172
+ summary: Make your email templates sexxy. The name was inspired by General David H. Petraeus.
173
+ test_files:
174
+ - test/test_helper.rb