middleman-inline-style 0.5.1 → 0.6.0

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/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/Gemfile.lock DELETED
@@ -1,55 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- inline-style (0.4.10)
5
- css_parser
6
- facets
7
- maca-fork-csspool
8
- nokogiri
9
-
10
- GEM
11
- remote: http://rubygems.org/
12
- specs:
13
- activesupport (3.0.4)
14
- css_parser (1.1.5)
15
- diff-lcs (1.1.2)
16
- facets (2.9.1)
17
- ffi (1.0.7)
18
- rake (>= 0.8.7)
19
- i18n (0.5.0)
20
- maca-fork-csspool (2.0.2)
21
- ffi
22
- mail (2.2.15)
23
- activesupport (>= 2.3.6)
24
- i18n (>= 0.4.0)
25
- mime-types (~> 1.16)
26
- treetop (~> 1.4.8)
27
- mime-types (1.16)
28
- nokogiri (1.4.4)
29
- polyglot (0.3.1)
30
- rack (1.2.1)
31
- rake (0.8.7)
32
- rspec (2.4.0)
33
- rspec-core (~> 2.4.0)
34
- rspec-expectations (~> 2.4.0)
35
- rspec-mocks (~> 2.4.0)
36
- rspec-core (2.4.0)
37
- rspec-expectations (2.4.0)
38
- diff-lcs (~> 1.1.2)
39
- rspec-mocks (2.4.0)
40
- treetop (1.4.9)
41
- polyglot (>= 0.3.1)
42
-
43
- PLATFORMS
44
- ruby
45
-
46
- DEPENDENCIES
47
- css_parser
48
- facets
49
- inline-style!
50
- maca-fork-csspool
51
- mail
52
- nokogiri
53
- rack
54
- rspec
55
- rspec-core
data/README.rdoc DELETED
@@ -1,127 +0,0 @@
1
- = middleman-inline-style
2
-
3
- https://github.com/trenton42/middleman-inline-style
4
-
5
- Slightly modified version of http://github.com/maca/inline-style to work directly with middleman
6
-
7
-
8
- == Description
9
-
10
- Will take all css in a page (either from linked stylesheet or from style tag) and will embed it in the style attribute for
11
- each refered element taking selector specificity and declarator order.
12
-
13
- With this you can generate your html email templates with middleman without needing to inline all of the styles yourself
14
-
15
- *Note*
16
-
17
- Currently only works with styles specified in <style></style> tags.
18
-
19
-
20
- == Usage (in your config.rb)
21
-
22
- require 'middleman-inline-style'
23
-
24
- activate :inline_style
25
-
26
- index.html contains:
27
-
28
- <style type="text/css" media="screen">
29
- * {
30
- font-family: "Lucida Grande", Lucida, Verdana, sans-serif;
31
- margin: 4px 3px 2px 1px;
32
- padding: 0;
33
- }
34
-
35
- #list {
36
- margin: 10;
37
- }
38
-
39
- #list li {
40
- font-family: Arial;
41
- }
42
-
43
- .element {
44
- padding: 10;
45
- }
46
-
47
- .odd {
48
- background-color: black;
49
- }
50
-
51
- .pair {
52
- background-color: red;
53
- }
54
-
55
- </style>
56
-
57
-
58
- <ul id='number' class='listing inlined' style='background-color: yellow'>
59
- <li class='list-element odd'>
60
- <span>1</span>
61
- </li>
62
- <li class='list-element pair'>
63
- <span>2</span>
64
- </li>
65
- <li class='list-element odd'>
66
- <span>3</span>
67
- </li>
68
- <li class='list-element pair'>
69
- <span>4</span>
70
- </li>
71
- </ul>
72
-
73
- Will become:
74
-
75
- <ul id="number" class="listing inlined" style='font-family: "Lucida Grande", Lucida, Verdana, sans-serif;margin: 4.0px 3.0px 2.0px 1.0px;padding: 0.0;background-color: yellow;'>
76
- <li class="list-element odd" style='font-family: "Lucida Grande", Lucida, Verdana, sans-serif;margin: 4.0px 3.0px 2.0px 1.0px;padding: 0.0;background-color: black;'>
77
- <span style='font-family: "Lucida Grande", Lucida, Verdana, sans-serif;margin: 4.0px 3.0px 2.0px 1.0px;padding: 0.0;'>1</span>
78
- </li>
79
- <li class="list-element pair" style='font-family: "Lucida Grande", Lucida, Verdana, sans-serif;margin: 4.0px 3.0px 2.0px 1.0px;padding: 0.0;background-color: red;'>
80
- <span style='font-family: "Lucida Grande", Lucida, Verdana, sans-serif;margin: 4.0px 3.0px 2.0px 1.0px;padding: 0.0;'>2</span>
81
- </li>
82
- <li class="list-element odd" style='font-family: "Lucida Grande", Lucida, Verdana, sans-serif;margin: 4.0px 3.0px 2.0px 1.0px;padding: 0.0;background-color: black;'>
83
- <span style='font-family: "Lucida Grande", Lucida, Verdana, sans-serif;margin: 4.0px 3.0px 2.0px 1.0px;padding: 0.0;'>3</span>
84
- </li>
85
- <li class="list-element pair" style='font-family: "Lucida Grande", Lucida, Verdana, sans-serif;margin: 4.0px 3.0px 2.0px 1.0px;padding: 0.0;background-color: red;'>
86
- <span style='font-family: "Lucida Grande", Lucida, Verdana, sans-serif;margin: 4.0px 3.0px 2.0px 1.0px;padding: 0.0;'>4</span>
87
- </li>
88
- </ul>
89
-
90
-
91
- == Requirements:
92
-
93
- nokogiri && (css_parser || maca-fork-csspool)
94
-
95
-
96
- == Install:
97
- (in your Gemfile)
98
- gem 'maca-fork-csspool' # Optional requires librcroco to be installed
99
- gem "middleman-inline-style"
100
-
101
- bundle install
102
-
103
-
104
- == License:
105
-
106
- (The MIT License)
107
-
108
- Copyright (c) 2009 Macario Ortega
109
-
110
- Permission is hereby granted, free of charge, to any person obtaining
111
- a copy of this software and associated documentation files (the
112
- 'Software'), to deal in the Software without restriction, including
113
- without limitation the rights to use, copy, modify, merge, publish,
114
- distribute, sublicense, and/or sell copies of the Software, and to
115
- permit persons to whom the Software is furnished to do so, subject to
116
- the following conditions:
117
-
118
- The above copyright notice and this permission notice shall be
119
- included in all copies or substantial portions of the Software.
120
-
121
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
122
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
123
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
124
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
125
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
126
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
127
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/example.rb DELETED
@@ -1,5 +0,0 @@
1
- require 'rubygems'
2
- require "#{ dir = File.dirname(__FILE__) }/lib/middleman-inline-style"
3
-
4
- html = File.read("#{ fixtures = dir + '/spec/fixtures' }/boletin.html")
5
- puts InlineStyle.process(html)
@@ -1,15 +0,0 @@
1
- require 'css_parser'
2
-
3
- class InlineStyle
4
- class CssParserWrapper
5
- attr_accessor :rules
6
-
7
- def initialize(css_code)
8
- parser, @rules = CssParser::Parser.new, []
9
- parser.add_block! css_code
10
- parser.each_rule_set do |rule_set|
11
- rule_set.each_selector { |sel, dec, spec| @rules << Rule.new(sel, dec, '%04d' % spec.to_i) }
12
- end
13
- end
14
- end
15
- end
@@ -1,12 +0,0 @@
1
- class InlineStyle
2
- class CSSPoolWrapper
3
- attr_accessor :rules
4
-
5
- def initialize css_code
6
- parser = CSSPool.CSS css_code
7
- @rules = parser.rule_sets.map do |rule_set|
8
- rule_set.selectors.map { |sel| Rule.new(sel.to_s, sel.declarations.join, "0#{sel.specificity.join}") }
9
- end.flatten
10
- end
11
- end
12
- end
@@ -1,37 +0,0 @@
1
- # A interceptor for +mail+ (https://github.com/mikel/mail) to
2
- # automatically inline the styles of outgoing e-mails. To use:
3
- #
4
- # Mail.register_interceptor \
5
- # InlineStyle::Mail::Interceptor.new(:stylesheets_path => 'public')
6
- #
7
- # Rails 3's ActionMailer wraps around the +mail+ and also supports
8
- # interceptors. Example usage:
9
- #
10
- # ActionMailer::Base.register_interceptor \
11
- # InlineStyle::Mail::Interceptor.new(:stylesheets_path => 'public')
12
- #
13
- module InlineStyle::Mail
14
- class Interceptor
15
- # The mime types we should inline. Basically HTML and XHTML.
16
- # If you have something else you can just push it onto the list
17
- INLINE_MIME_TYPES = %w(text/html application/xhtml+xml)
18
-
19
- # Save the options to later pass to InlineStyle.process
20
- def initialize(options={})
21
- @options = options
22
- end
23
-
24
- # Mail callback where we actually inline the styles
25
- def delivering_email(part)
26
- if part.multipart?
27
- for part in part.parts
28
- delivering_email part
29
- end
30
- elsif INLINE_MIME_TYPES.any? {|m| part.content_type && part.content_type.starts_with?(m)}
31
- part.body = InlineStyle.process(part.body.to_s, @options)
32
- part.content_transfer_encoding = nil
33
- end
34
- end
35
-
36
- end
37
- end
@@ -1,18 +0,0 @@
1
- class InlineStyle
2
- # A simple abstraction of the data we get back from the parsers. CSSPool
3
- # actually already does this for us but CSSParser does not so we need
4
- # to create the abstraction ourselves.
5
- class Rule
6
- DYNAMIC_PSEUDO_CLASSES = %w(link visited active hover focus target enabled disabled checked)
7
- DYNAMIC_PSEUDO_CLASSES_MATCHER = /:(#{DYNAMIC_PSEUDO_CLASSES.join('|')})$/
8
-
9
- attr_reader :selector, :declarations, :specificity, :dynamic_pseudo_class
10
-
11
- def initialize selector, declarations, specificity
12
- @specificity = specificity
13
- @selector, @dynamic_pseudo_class = selector.split DYNAMIC_PSEUDO_CLASSES_MATCHER
14
- @selector.sub! /$^/, '*'
15
- @declarations = declarations.scan /\s*([^:]+):\s*([^;]+);/
16
- end
17
- end
18
- end
@@ -1,90 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe InlineStyle do
4
- shared_examples_for 'inlines styles' do
5
- before do
6
- processed = InlineStyle.process File.read("#{FIXTURES}/boletin.html"), :stylesheets_path => FIXTURES
7
- @processed = Nokogiri.HTML(processed)
8
- end
9
-
10
- it "should extract from linked stylesheet" do
11
- @processed.css('#izq').first['style'].should match_style /margin: 30.0px;/
12
- end
13
-
14
- it "should extract styles from linked stylesheet with no media specified" do
15
- @processed.css('#izq').first['style'].should match_style /color: red;/
16
- end
17
-
18
- it "should extract styles from linked stylesheet with media 'all'" do
19
- @processed.css('#izq').first['style'].should match_style /border: none;/
20
- end
21
-
22
- it "should ignore styles from linked stylesheet with media other than screen" do
23
- @processed.css('#izq').first['style'].should_not match_style /display: none;/
24
- end
25
-
26
- it "should not process pseudo classes" do
27
- @processed.css('a').first['style'].should_not match_style /^:hover \{background-color: #8ae0ea; color: #126b5d;\}$/
28
- end
29
-
30
- it 'should process location-based pseudo classes' do
31
- @processed.at_css('#izq')['style'].should match_style /padding: 1.0px;/
32
- end
33
-
34
- it 'should apply to #A #B' do
35
- @processed.css('#logos #der').first['style'].should match_style /float: right;/
36
- end
37
-
38
- it 'should not override rules defined inline' do
39
- @processed.css('#aviso').first['style'].should match_style /color: green;/
40
- end
41
-
42
- it 'should overwrite rule previously defined' do
43
- @processed.css('#izq').first['style'].should_not match_style /padding: 0.0;/
44
- end
45
-
46
- describe 'Box model' do
47
- before do
48
- @processed = InlineStyle.process(Nokogiri.HTML(File.read("#{FIXTURES}/box-model.html")))
49
- end
50
-
51
- it "should inline style for selector ul" do
52
- @processed.css('ul').first['style'].should match_style /^background: yellow; margin: 12.0px 12.0px 12.0px 12.0px; padding: 3.0px 3.0px 3.0px 3.0px;$/
53
- end
54
-
55
- it "should inline style for selector li" do
56
- @processed.css('li').each do |li|
57
- li['style'].should match_style /^color: white; background: blue; margin: 12.0px 12.0px 12.0px 12.0px; padding: 12.0px 0.0px 12.0px 12.0px; list-style: none/
58
- end
59
- end
60
-
61
- it "should inline style for selector li.withborder" do
62
- @processed.css('li.withborder').first['style'].
63
- should match_style /^color: white; background: blue; margin: 12.0px 12.0px 12.0px 12.0px; padding: 12.0px 0.0px 12.0px 12.0px; list-style: none; border-style: dashed; border-width: medium; border-color: lime;$/
64
- end
65
- end
66
- end
67
-
68
- describe CssParser do
69
- it { InlineStyle::CSSParser.should == InlineStyle::CssParserWrapper }
70
- it_should_behave_like 'inlines styles'
71
- end
72
-
73
- describe CSSPool do
74
- before do
75
- class InlineStyle
76
- remove_const :CSSParser
77
- CSSParser = InlineStyle::CSSPoolWrapper
78
- end
79
- end
80
-
81
- after do
82
- class InlineStyle
83
- remove_const :CSSParser
84
- CSSParser = InlineStyle::CssParserWrapper
85
- end
86
- end
87
- it { InlineStyle::CSSParser.should == InlineStyle::CSSPoolWrapper }
88
- it_should_behave_like 'inlines styles'
89
- end
90
- end
@@ -1,146 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe 'CSS parsing' do
4
- shared_examples_for 'parses css' do
5
- describe 'parsing tag selector' do
6
- before do
7
- @wrapper = subject.new 'p {background-color: black; padding: 0.0 0.0 0.0 0.0}'
8
- end
9
-
10
- it { @wrapper.should have(1).rules }
11
-
12
- describe 'rule' do
13
- before { @rule = @wrapper.rules.first }
14
- it { @rule.specificity.should == '0001' }
15
- it { @rule.declarations.should == [['background-color', 'black'], ['padding', '0.0 0.0 0.0 0.0']] }
16
- it { @rule.selector.should == 'p' }
17
- it { @rule.dynamic_pseudo_class.should be_nil }
18
- end
19
- end
20
-
21
- describe 'parsing body tag selector' do
22
- before do
23
- @wrapper = subject.new 'body {background-color: black; padding: 0.0 0.0 0.0 0.0}'
24
- end
25
-
26
- it { @wrapper.should have(1).rules }
27
-
28
- describe 'rule' do
29
- before { @rule = @wrapper.rules.first }
30
- it { @rule.specificity.should == '0001' }
31
- it { @rule.declarations.should == [['background-color', 'black'], ['padding', '0.0 0.0 0.0 0.0']] }
32
- it { @rule.selector.should == 'body' }
33
- it { @rule.dynamic_pseudo_class.should be_nil }
34
- end
35
- end
36
-
37
- describe 'parsing tag and class selector' do
38
- before do
39
- @wrapper = subject.new 'div.article {background-color: black; padding: 0.0 0.0 0.0 0.0}'
40
- end
41
-
42
- it { @wrapper.should have(1).rules }
43
-
44
- describe 'rule' do
45
- before { @rule = @wrapper.rules.first }
46
- it { @rule.specificity.should == '0011' }
47
- it { @rule.declarations.should == [['background-color', 'black'], ['padding', '0.0 0.0 0.0 0.0']] }
48
- it { @rule.selector.should == 'div.article' }
49
- it { @rule.dynamic_pseudo_class.should be_nil }
50
- end
51
- end
52
-
53
- describe 'parsing tag, class and id selector' do
54
- before do
55
- @wrapper = subject.new 'div#headline.article {background-color: black; padding: 0.0 0.0 0.0 0.0}'
56
- end
57
-
58
- it { @wrapper.should have(1).rules }
59
-
60
- describe 'rule' do
61
- before { @rule = @wrapper.rules.first }
62
- it { @rule.specificity.should == '0111' }
63
- it { @rule.declarations.should == [['background-color', 'black'], ['padding', '0.0 0.0 0.0 0.0']] }
64
- it { @rule.selector.should == 'div#headline.article' }
65
- it { @rule.dynamic_pseudo_class.should be_nil }
66
- end
67
- end
68
-
69
- describe 'parsing tag selector' do
70
- before do
71
- @wrapper = subject.new 'p, div {background-color: black; padding: 0.0 0.0 0.0 0.0}'
72
- end
73
-
74
- it { @wrapper.should have(2).rules }
75
-
76
- describe 'first rule' do
77
- before { @rule = @wrapper.rules.first }
78
- it { @rule.specificity.should == '0001' }
79
- it { @rule.declarations.should == [['background-color', 'black'], ['padding', '0.0 0.0 0.0 0.0']] }
80
- it { @rule.selector.should == 'p' }
81
- it { @rule.dynamic_pseudo_class.should be_nil }
82
- end
83
-
84
- describe 'last rule' do
85
- before { @rule = @wrapper.rules.last }
86
- it { @rule.specificity.should == '0001' }
87
- it { @rule.declarations.should == [['background-color', 'black'], ['padding', '0.0 0.0 0.0 0.0']] }
88
- it { @rule.selector.should == 'div' }
89
- it { @rule.dynamic_pseudo_class.should be_nil }
90
- end
91
- end
92
-
93
- describe 'dynamic pseudo selectors' do
94
- InlineStyle::Rule::DYNAMIC_PSEUDO_CLASSES.each do |pseudo_class|
95
- describe "parsing tag with :#{pseudo_class}" do
96
- before { @dynamic_pseudo_class = pseudo_class }
97
- it_should_behave_like 'parses dynamic pseudo selector'
98
- end
99
- end
100
- end
101
- end
102
-
103
- shared_examples_for 'parses dynamic pseudo selector' do
104
- describe 'with tag' do
105
- before do
106
- @wrapper = subject.new "p:#{@dynamic_pseudo_class} {background-color: black; padding: 0.0 0.0 0.0 0.0}"
107
- end
108
-
109
- it { @wrapper.should have(1).rules }
110
-
111
- describe 'rule' do
112
- before { @rule = @wrapper.rules.first }
113
- # it { @rule.specificity.should == '011' }
114
- it { @rule.declarations.should == [['background-color', 'black'], ['padding', '0.0 0.0 0.0 0.0']] }
115
- it { @rule.selector.should == 'p' }
116
- it { @rule.dynamic_pseudo_class.should == @dynamic_pseudo_class }
117
- end
118
- end
119
-
120
- describe 'without tag' do
121
- before do
122
- @wrapper = subject.new ":#{@dynamic_pseudo_class} {background-color: black; padding: 0.0 0.0 0.0 0.0}"
123
- end
124
-
125
- it { @wrapper.should have(1).rules }
126
-
127
- describe 'rule' do
128
- before { @rule = @wrapper.rules.first }
129
- # it { @rule.specificity.should == '011' }
130
- it { @rule.declarations.should == [['background-color', 'black'], ['padding', '0.0 0.0 0.0 0.0']] }
131
- it { @rule.selector.should == '*' }
132
- it { @rule.dynamic_pseudo_class.should == @dynamic_pseudo_class }
133
- end
134
- end
135
- end
136
-
137
- describe InlineStyle::CssParserWrapper do
138
- subject { InlineStyle::CssParserWrapper }
139
- it_should_behave_like 'parses css'
140
- end
141
-
142
- describe InlineStyle::CssParserWrapper do
143
- subject { InlineStyle::CSSPoolWrapper }
144
- it_should_behave_like 'parses css'
145
- end
146
- end