inline_styles 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -2
- data/VERSION +1 -1
- data/inline_styles.gemspec +2 -6
- data/lib/inline_styles.rb +37 -28
- metadata +6 -7
data/README.markdown
CHANGED
@@ -15,7 +15,7 @@ class Mailer < ActionMailer::Base
|
|
15
15
|
subject "Looks nice, eh?"
|
16
16
|
html = render(:file => "message.html",
|
17
17
|
:layout => "email_layout.html")
|
18
|
-
body InlineStyles::Page.new(html).
|
18
|
+
body InlineStyles::Page.new.with_html(html).with_css(stylesheet_content).apply
|
19
19
|
end
|
20
20
|
|
21
21
|
protected
|
@@ -27,7 +27,7 @@ end
|
|
27
27
|
</pre>
|
28
28
|
|
29
29
|
## Requirements
|
30
|
-
InlineStyles uses the [css_parser](http://github.com/DanaDanger/css_parser) and [
|
30
|
+
InlineStyles uses the [css_parser](http://github.com/DanaDanger/css_parser) and [Hpricot](http://github.com/hpricot/hpricot) gems
|
31
31
|
|
32
32
|
### Copyright
|
33
33
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
data/inline_styles.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{inline_styles}
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jack Danger Canty"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-06-15}
|
13
13
|
s.description = %q{To make your HTML display properly when stylesheet support isn't available (e.g. Gmail) this lets you attach all your CSS to the 'style' attribute of each element.}
|
14
14
|
s.email = %q{gitcommit@6brand.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,10 +30,6 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.require_paths = ["lib"]
|
31
31
|
s.rubygems_version = %q{1.4.2}
|
32
32
|
s.summary = %q{Squish a CSS stylesheet into any semantic HTML}
|
33
|
-
s.test_files = [
|
34
|
-
"test/helper.rb",
|
35
|
-
"test/test_inline_styles.rb"
|
36
|
-
]
|
37
33
|
|
38
34
|
if s.respond_to? :specification_version then
|
39
35
|
s.specification_version = 3
|
data/lib/inline_styles.rb
CHANGED
@@ -1,36 +1,54 @@
|
|
1
|
+
require 'css_parser'
|
2
|
+
require 'nokogiri'
|
1
3
|
|
2
4
|
module InlineStyles
|
3
5
|
class Page
|
4
6
|
attr_accessor :html
|
5
7
|
|
6
|
-
def initialize(html)
|
8
|
+
def initialize(html = nil)
|
7
9
|
@html = html
|
8
10
|
end
|
9
11
|
|
10
|
-
def
|
11
|
-
|
12
|
+
def with_css(css)
|
13
|
+
@css = css
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def with_html(html)
|
18
|
+
@html = html
|
19
|
+
self
|
20
|
+
end
|
12
21
|
|
13
|
-
|
14
|
-
|
22
|
+
def selectors
|
23
|
+
@selectors ||= begin
|
24
|
+
parser = CssParser::Parser.new
|
25
|
+
parser.add_block! @css
|
15
26
|
|
16
|
-
|
27
|
+
stable_sorter = 0
|
28
|
+
selectors = []
|
17
29
|
|
18
|
-
|
19
|
-
|
30
|
+
# extracting selectors via the API rather than
|
31
|
+
# just reaching in and grabbing @selectors
|
32
|
+
parser.each_selector do |selector, declarations, specificity|
|
33
|
+
selectors << [selector, declarations, specificity]
|
34
|
+
end
|
20
35
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
36
|
+
# stable-sort the selectors so that we get them sorted
|
37
|
+
# by specificity but also keeping their rough
|
38
|
+
# original order. This is how CSS selectors are applied
|
39
|
+
# in a browser
|
40
|
+
selectors.sort_by do |selector|
|
41
|
+
[selector.last, stable_sorter += 1]
|
42
|
+
end
|
25
43
|
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def apply(stylesheet_content = nil)
|
47
|
+
with_css(stylesheet_content) if stylesheet_content
|
48
|
+
|
49
|
+
tree = Nokogiri::HTML(@html)
|
26
50
|
|
27
|
-
|
28
|
-
# by specificity but also keeping their rough
|
29
|
-
# original order. This is how CSS selectors are applied
|
30
|
-
# in a browser
|
31
|
-
selectors.sort_by do |selector|
|
32
|
-
[selector.last, stable_sorter += 1]
|
33
|
-
end.each do |selector, declarations, spec|
|
51
|
+
selectors.each do |selector, declarations, spec|
|
34
52
|
# Find each element matching the given slector
|
35
53
|
(tree.css selector).each do |element|
|
36
54
|
|
@@ -47,15 +65,6 @@ module InlineStyles
|
|
47
65
|
|
48
66
|
tree.to_s
|
49
67
|
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
|
53
|
-
def require_dependencies
|
54
|
-
gem 'css_parser'
|
55
|
-
require 'css_parser'
|
56
|
-
gem 'nokogiri'
|
57
|
-
require 'nokogiri'
|
58
|
-
end
|
59
68
|
end
|
60
69
|
|
61
70
|
# taken from http://moserei.de/index.php/17/stable-array-sorting-in-ruby
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inline_styles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 2
|
10
|
+
version: 1.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jack Danger Canty
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-15 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -112,6 +112,5 @@ rubygems_version: 1.4.2
|
|
112
112
|
signing_key:
|
113
113
|
specification_version: 3
|
114
114
|
summary: Squish a CSS stylesheet into any semantic HTML
|
115
|
-
test_files:
|
116
|
-
|
117
|
-
- test/test_inline_styles.rb
|
115
|
+
test_files: []
|
116
|
+
|