css_inliner 0.3.0 → 0.3.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/.travis.yml +3 -0
- data/README.rdoc +7 -0
- data/Rakefile +1 -21
- data/css_inliner.gemspec +1 -2
- data/lib/css_inliner.rb +1 -1
- data/lib/css_inliner/csspool.rb +2 -2
- data/lib/css_inliner/extractor.rb +1 -1
- data/lib/css_inliner/version.rb +1 -1
- data/test/helper.rb +0 -1
- data/test/test_css_inliner.rb +98 -18
- metadata +20 -30
data/.travis.yml
ADDED
data/README.rdoc
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
= CSS Inliner
|
2
|
+
{<img src="https://secure.travis-ci.org/KitaitiMakoto/css_inliner.png?branch=master" alt="Build Status" />}[http://travis-ci.org/KitaitiMakoto/css_inliner]
|
3
|
+
|
2
4
|
CSS Inliner is a command-line tools to inline CSS into style attribute of each HTML element.
|
3
5
|
|
4
6
|
HTML here...
|
@@ -70,6 +72,11 @@ Note that this is <b>not stable at all</b>.
|
|
70
72
|
CSSInliner.process html, 'http://example.net/stylesheets' # Passed URI will be used as base directory when resolving relative URI of CSS
|
71
73
|
|
72
74
|
== History
|
75
|
+
=== 0.3.1 / 2012-07-17
|
76
|
+
* [BUG FIX]Fix an error which occurs when parsing non-XHTML documents
|
77
|
+
* Change homepage: Gitorious -> GitHub
|
78
|
+
* Reimplement some tests which have pended
|
79
|
+
|
73
80
|
=== 0.3.0 / 2012-05-28
|
74
81
|
* Group external CSS files refered by <link> element by "title" attribute.
|
75
82
|
* Work on progress: CSSPool::CSS::Declaration#expand_dimension
|
data/Rakefile
CHANGED
@@ -2,27 +2,7 @@ require 'rake/testtask'
|
|
2
2
|
require 'yard'
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
|
5
|
-
task :default =>
|
5
|
+
task :default => :test
|
6
6
|
|
7
7
|
Rake::TestTask.new
|
8
8
|
YARD::Rake::YardocTask.new
|
9
|
-
|
10
|
-
namespace :coverage do
|
11
|
-
desc "Generates and outputs code coverage report."
|
12
|
-
task :console => :test do
|
13
|
-
require 'cover_me'
|
14
|
-
CoverMe.config do |conf|
|
15
|
-
conf.formatter = CoverMe::ConsoleFormatter
|
16
|
-
end
|
17
|
-
CoverMe.complete!
|
18
|
-
end
|
19
|
-
|
20
|
-
desc "Generates and opens code coverage report."
|
21
|
-
task :html => :test do
|
22
|
-
require 'cover_me'
|
23
|
-
CoverMe.config do |conf|
|
24
|
-
conf.formatter = CoverMe::HtmlFormatter
|
25
|
-
end
|
26
|
-
CoverMe.complete!
|
27
|
-
end
|
28
|
-
end
|
data/css_inliner.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.version = CSSInliner::VERSION
|
7
7
|
s.authors = ["KITAITI Makoto"]
|
8
8
|
s.email = ["KitaitiMakoto@gmail.com"]
|
9
|
-
s.homepage = "
|
9
|
+
s.homepage = "https://github.com/KitaitiMakoto/css_inliner"
|
10
10
|
s.summary = %q{inline CSS into HTML attribute of elements}
|
11
11
|
s.description = %q{
|
12
12
|
inline CSS from external file(s) and/or style elment(s) in head element
|
@@ -24,7 +24,6 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_runtime_dependency "bsearch"
|
25
25
|
|
26
26
|
s.add_development_dependency "test-unit-full"
|
27
|
-
s.add_development_dependency "cover_me", '~> 1'
|
28
27
|
s.add_development_dependency "yard"
|
29
28
|
s.add_development_dependency "pry"
|
30
29
|
s.add_development_dependency "pry-doc"
|
data/lib/css_inliner.rb
CHANGED
@@ -14,7 +14,7 @@ module CSSInliner
|
|
14
14
|
# @param [String] format Format to output, html or xhtml
|
15
15
|
# @return [String] HTML source
|
16
16
|
def process(html, basedir = '.', element = nil, format = 'html')
|
17
|
-
doc = html.instance_of?(Nokogiri::XML::Document) ? html : Nokogiri.
|
17
|
+
doc = html.instance_of?(Nokogiri::XML::Document) ? html : Nokogiri.HTML(html)
|
18
18
|
doc = Inliner.new(doc, basedir).inline
|
19
19
|
doc = doc.css(element)[0] if element
|
20
20
|
case format
|
data/lib/css_inliner/csspool.rb
CHANGED
@@ -73,9 +73,9 @@ module CSSPool
|
|
73
73
|
return [self] unless expanded_properties
|
74
74
|
|
75
75
|
expansion_map = EXPANSION_INDICES[expressions.length]
|
76
|
-
raise InvalidExpressionCountError, "has #{expressions.length}
|
76
|
+
raise InvalidExpressionCountError, "has #{expressions.length} expressions" unless expansion_map
|
77
77
|
|
78
|
-
expanded_properties.
|
78
|
+
expanded_properties.map.with_index {|prop, i|
|
79
79
|
expression = expressions[expansion_map[i]]
|
80
80
|
Declaration.new(prop, expression, important, rule_set)
|
81
81
|
}
|
@@ -47,7 +47,7 @@ module CSSInliner
|
|
47
47
|
def extract_from_link(remove_link_element = true)
|
48
48
|
group = nil
|
49
49
|
@document.css('link').inject([]) do |sources, link|
|
50
|
-
next unless link['rel'] == 'stylesheet'
|
50
|
+
next sources unless link['rel'] == 'stylesheet'
|
51
51
|
title = link['title']
|
52
52
|
if title
|
53
53
|
if group.nil?
|
data/lib/css_inliner/version.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/test_css_inliner.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'helper'
|
2
|
+
require 'tmpdir'
|
2
3
|
require 'css_inliner'
|
3
4
|
|
4
5
|
class CSSInlinerTest < CSSInlinerTestCase
|
@@ -7,32 +8,111 @@ class CSSInlinerTest < CSSInlinerTestCase
|
|
7
8
|
end
|
8
9
|
|
9
10
|
def test_process_without_inline_style
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
html = <<EOH
|
12
|
+
<html>
|
13
|
+
<head>
|
14
|
+
<title>Without Inline Style</title>
|
15
|
+
<link rel="stylesheet" type="text/css" href="./style.css">
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
<p>This is a blue line.</p>
|
19
|
+
</body>
|
20
|
+
</html>
|
21
|
+
EOH
|
22
|
+
css = <<EOC
|
23
|
+
p {
|
24
|
+
color: blue;
|
25
|
+
}
|
26
|
+
EOC
|
27
|
+
inlined = process(html, css)
|
28
|
+
doc = Nokogiri.HTML(inlined)
|
29
|
+
style = doc.search('p').first['style'].strip
|
30
|
+
assert_equal 'color: blue;', style
|
13
31
|
end
|
14
32
|
|
15
33
|
def test_process_with_inline_style
|
16
|
-
|
17
|
-
|
18
|
-
|
34
|
+
html = <<EOH
|
35
|
+
<html>
|
36
|
+
<head>
|
37
|
+
<title>With Inline Style</title>
|
38
|
+
<link rel="stylesheet" type="text/css" href="./style.css">
|
39
|
+
</head>
|
40
|
+
<body>
|
41
|
+
<p style="font-weight: bold;">This is a bold blue line.</p>
|
42
|
+
</body>
|
43
|
+
</html>
|
44
|
+
EOH
|
45
|
+
css = <<EOC
|
46
|
+
p {
|
47
|
+
color: blue;
|
48
|
+
}
|
49
|
+
EOC
|
50
|
+
inlined = process(html, css)
|
51
|
+
doc = Nokogiri.HTML(inlined)
|
52
|
+
style = doc.search('p').first['style'].strip.gsub(/ +/, '')
|
53
|
+
assert_equal 'color:blue;font-weight:bold;', style
|
19
54
|
end
|
20
55
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
56
|
+
def test_process_with_style_elem
|
57
|
+
html = <<EOH
|
58
|
+
<html>
|
59
|
+
<head>
|
60
|
+
<title>With Style Attribute</title>
|
61
|
+
<link rel="stylesheet" type="text/css" href="./style.css">
|
62
|
+
<style type="text/css">
|
63
|
+
p {font-style: oblique;}
|
64
|
+
</style>
|
65
|
+
</head>
|
66
|
+
<body>
|
67
|
+
<p>This is a oblique blue line.</p>
|
68
|
+
</body>
|
69
|
+
</html>
|
70
|
+
EOH
|
71
|
+
css = <<EOC
|
72
|
+
p {
|
73
|
+
color: blue;
|
74
|
+
}
|
75
|
+
EOC
|
76
|
+
inlined = process(html, css)
|
77
|
+
doc = Nokogiri.HTML(inlined)
|
78
|
+
style = doc.search('p').first['style'].strip.gsub(/ +/, '')
|
79
|
+
assert_equal 'color:blue;font-style:oblique;', style
|
25
80
|
end
|
26
81
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
82
|
+
def test_process_with_inline_style_and_style_elem
|
83
|
+
html = <<EOH
|
84
|
+
<html>
|
85
|
+
<head>
|
86
|
+
<title>With Inline Style and Style Attribute</title>
|
87
|
+
<link rel="stylesheet" type="text/css" href="./style.css">
|
88
|
+
<style type="text/css">
|
89
|
+
p {font-style: oblique;}
|
90
|
+
</style>
|
91
|
+
</head>
|
92
|
+
<body>
|
93
|
+
<p style="font-weight: bold;">This is a bold oblique blue line.</p>
|
94
|
+
</body>
|
95
|
+
</html>
|
96
|
+
EOH
|
97
|
+
css = <<EOC
|
98
|
+
p {
|
99
|
+
color: blue;
|
100
|
+
}
|
101
|
+
EOC
|
102
|
+
inlined = process(html, css)
|
103
|
+
doc = Nokogiri.HTML(inlined)
|
104
|
+
style = doc.search('p').first['style'].strip.gsub(/ +/, '')
|
105
|
+
assert_equal 'color:blue;font-style:oblique;font-weight:bold;', style
|
31
106
|
end
|
32
107
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
108
|
+
private
|
109
|
+
|
110
|
+
def process(html, css)
|
111
|
+
Dir.mktmpdir('css_inliner') do |dir|
|
112
|
+
File.open("#{dir}/style.css", 'w') do |f|
|
113
|
+
f.write css
|
114
|
+
end
|
115
|
+
CSSInliner.process(html, dir)
|
116
|
+
end
|
37
117
|
end
|
38
118
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: css_inliner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-16 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &7998240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *7998240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: csspool
|
27
|
-
requirement: &
|
27
|
+
requirement: &7997400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *7997400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bsearch
|
38
|
-
requirement: &
|
38
|
+
requirement: &7996520 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *7996520
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: test-unit-full
|
49
|
-
requirement: &
|
49
|
+
requirement: &7442420 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,21 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
name: cover_me
|
60
|
-
requirement: &12139920 !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
|
-
requirements:
|
63
|
-
- - ~>
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: '1'
|
66
|
-
type: :development
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: *12139920
|
57
|
+
version_requirements: *7442420
|
69
58
|
- !ruby/object:Gem::Dependency
|
70
59
|
name: yard
|
71
|
-
requirement: &
|
60
|
+
requirement: &7439740 !ruby/object:Gem::Requirement
|
72
61
|
none: false
|
73
62
|
requirements:
|
74
63
|
- - ! '>='
|
@@ -76,10 +65,10 @@ dependencies:
|
|
76
65
|
version: '0'
|
77
66
|
type: :development
|
78
67
|
prerelease: false
|
79
|
-
version_requirements: *
|
68
|
+
version_requirements: *7439740
|
80
69
|
- !ruby/object:Gem::Dependency
|
81
70
|
name: pry
|
82
|
-
requirement: &
|
71
|
+
requirement: &7438740 !ruby/object:Gem::Requirement
|
83
72
|
none: false
|
84
73
|
requirements:
|
85
74
|
- - ! '>='
|
@@ -87,10 +76,10 @@ dependencies:
|
|
87
76
|
version: '0'
|
88
77
|
type: :development
|
89
78
|
prerelease: false
|
90
|
-
version_requirements: *
|
79
|
+
version_requirements: *7438740
|
91
80
|
- !ruby/object:Gem::Dependency
|
92
81
|
name: pry-doc
|
93
|
-
requirement: &
|
82
|
+
requirement: &7437580 !ruby/object:Gem::Requirement
|
94
83
|
none: false
|
95
84
|
requirements:
|
96
85
|
- - ! '>='
|
@@ -98,7 +87,7 @@ dependencies:
|
|
98
87
|
version: '0'
|
99
88
|
type: :development
|
100
89
|
prerelease: false
|
101
|
-
version_requirements: *
|
90
|
+
version_requirements: *7437580
|
102
91
|
description: ! "\n inline CSS from external file(s) and/or style elment(s) in head
|
103
92
|
element\n into style attibute of HTML elements\n "
|
104
93
|
email:
|
@@ -111,6 +100,7 @@ extra_rdoc_files: []
|
|
111
100
|
files:
|
112
101
|
- .gemtest
|
113
102
|
- .gitignore
|
103
|
+
- .travis.yml
|
114
104
|
- Gemfile
|
115
105
|
- LICENSE
|
116
106
|
- README.rdoc
|
@@ -257,7 +247,7 @@ files:
|
|
257
247
|
- test/test_css_inliner.rb
|
258
248
|
- test/test_csspool.rb
|
259
249
|
- test/test_extractor.rb
|
260
|
-
homepage:
|
250
|
+
homepage: https://github.com/KitaitiMakoto/css_inliner
|
261
251
|
licenses: []
|
262
252
|
post_install_message:
|
263
253
|
rdoc_options: []
|
@@ -271,7 +261,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
271
261
|
version: '0'
|
272
262
|
segments:
|
273
263
|
- 0
|
274
|
-
hash:
|
264
|
+
hash: -3751475647972594840
|
275
265
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
276
266
|
none: false
|
277
267
|
requirements:
|
@@ -280,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
280
270
|
version: '0'
|
281
271
|
segments:
|
282
272
|
- 0
|
283
|
-
hash:
|
273
|
+
hash: -3751475647972594840
|
284
274
|
requirements: []
|
285
275
|
rubyforge_project:
|
286
276
|
rubygems_version: 1.8.8
|