css_inliner 0.1.0 → 0.1.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/.gemtest +0 -0
- data/.gitignore +2 -0
- data/LICENSE +20 -20
- data/README +42 -7
- data/Rakefile +16 -11
- data/css_inliner.gemspec +3 -2
- data/lib/css_inliner/extractor.rb +1 -1
- data/lib/css_inliner/inliner.rb +4 -2
- data/lib/css_inliner/version.rb +1 -1
- data/lib/css_inliner.rb +6 -0
- data/test/test_css_inliner.rb +18 -0
- data/test/test_extractor.rb +26 -1
- metadata +41 -11
data/.gemtest
ADDED
File without changes
|
data/.gitignore
CHANGED
data/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2011, KITAITI Makoto
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011,2012 KITAITI Makoto
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
SOFTWARE.
|
data/README
CHANGED
@@ -1,6 +1,32 @@
|
|
1
1
|
= CSS Inliner
|
2
2
|
CSS Inliner is a command-line tools to inline CSS into style attribute of each HTML element.
|
3
3
|
|
4
|
+
HTML here...
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>Sample HTML</title>
|
9
|
+
<style type="text/css">
|
10
|
+
body {color: black;}
|
11
|
+
p {line-height: 2em;}
|
12
|
+
</style>
|
13
|
+
</head>
|
14
|
+
<body>
|
15
|
+
<p>This is sample HTML document. In this paragraph, text is black and line has double height of font size.</p>
|
16
|
+
</body>
|
17
|
+
</html>
|
18
|
+
|
19
|
+
... becomes like this:
|
20
|
+
|
21
|
+
<html>
|
22
|
+
<head>
|
23
|
+
<title>Sample HTML</title>
|
24
|
+
</head>
|
25
|
+
<body style="color: black;">
|
26
|
+
<p style="line-height: 2em;">This is sample HTML document. In paragraph, text is black and line height is twice of font size.</p>
|
27
|
+
</body>
|
28
|
+
</html>
|
29
|
+
|
4
30
|
= INSTALL
|
5
31
|
== As a RubyGem
|
6
32
|
$ gem install css_inliner
|
@@ -17,11 +43,11 @@ Note that options are not stable.
|
|
17
43
|
$ css-inliner --help
|
18
44
|
|
19
45
|
$ css-inliner file1.html(output to stdout)
|
20
|
-
$ css-inliner file2.html
|
21
|
-
$ css-inliner file3.html
|
22
|
-
$ css-inliner file4.html --element
|
23
|
-
$ css-inliner file5.html --in-place(overwrite
|
24
|
-
$ css-inliner
|
46
|
+
$ css-inliner file2.html > result2.html
|
47
|
+
$ css-inliner file3.html --output=result3.html
|
48
|
+
$ css-inliner file4.html --element=body(output only body element)
|
49
|
+
$ css-inliner file5.html --in-place(overwrite file5.html)
|
50
|
+
$ css-inliner file6.html --in-place=.bak(create a backup file as file6.html.bak)
|
25
51
|
|
26
52
|
=== css-inliner-multifile
|
27
53
|
$ css-inliner --help
|
@@ -32,7 +58,16 @@ Note that options are not stable.
|
|
32
58
|
$ css-inliner-multifile ./dir4/*.html --in-place=.bak
|
33
59
|
|
34
60
|
== As a Library
|
35
|
-
|
61
|
+
Note that this is <b>not stable at all</b>.
|
62
|
+
|
63
|
+
require 'css_inliner'
|
64
|
+
|
65
|
+
html = File.read(sample.html)
|
66
|
+
|
67
|
+
CSSInliner.process html, '.' # => CSS-inlined HTML
|
68
|
+
CSSInliner.process html, '.', 'body' # => body element(<body> ... </body>)
|
69
|
+
CSSInliner.process html, '.', 'article' # => The first article element
|
70
|
+
CSSInliner.process html, 'http://example.net/stylesheets' # Passed URI will be used as base directory when resolving relative URI of CSS
|
36
71
|
|
37
72
|
== Note
|
38
73
|
Note that
|
@@ -42,5 +77,5 @@ and
|
|
42
77
|
will be removed in process.
|
43
78
|
|
44
79
|
= LICENSE
|
45
|
-
CSS Inliner is copyright (c) 2011 KITAITI Makoto.
|
80
|
+
CSS Inliner is copyright (c) 2011, 2012 KITAITI Makoto.
|
46
81
|
Distribued under the MIT license, see LISENCE file for the term.
|
data/Rakefile
CHANGED
@@ -2,22 +2,27 @@ require 'rake/testtask'
|
|
2
2
|
require 'yard'
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
|
5
|
-
task :default => [:
|
5
|
+
task :default => ['coverage:console']
|
6
6
|
|
7
7
|
Rake::TestTask.new
|
8
8
|
YARD::Rake::YardocTask.new
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
task :
|
13
|
-
|
14
|
-
|
15
|
-
CoverMe
|
16
|
-
rescue LoadError
|
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
|
17
16
|
end
|
17
|
+
CoverMe.complete!
|
18
18
|
end
|
19
|
-
end
|
20
19
|
|
21
|
-
|
22
|
-
|
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
|
23
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 = "http://gitorious.org/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
|
@@ -19,11 +19,12 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ["lib"]
|
22
|
-
s.has_rdoc = false
|
23
22
|
|
24
23
|
s.add_runtime_dependency "nokogiri", '~> 1'
|
25
24
|
s.add_runtime_dependency "css_parser", '~> 1'
|
25
|
+
s.add_runtime_dependency "sass", '~> 3'
|
26
26
|
|
27
27
|
s.add_development_dependency "test-unit", '~> 2'
|
28
28
|
s.add_development_dependency "cover_me", '~> 1'
|
29
|
+
s.add_development_dependency "yard"
|
29
30
|
end
|
@@ -21,7 +21,7 @@ module CSSInliner
|
|
21
21
|
begin
|
22
22
|
open(File.join(basedir, link['href'])) {|f| sources << f.read}
|
23
23
|
rescue Errno::ENOENT
|
24
|
-
warn File.join(basedir, link['href']) + 'not found'
|
24
|
+
warn File.join(basedir, link['href']) + ' not found'
|
25
25
|
end
|
26
26
|
link.remove if remove_link_element
|
27
27
|
sources
|
data/lib/css_inliner/inliner.rb
CHANGED
@@ -4,8 +4,10 @@ require 'css_inliner/extractor'
|
|
4
4
|
|
5
5
|
module CSSInliner
|
6
6
|
class Inliner
|
7
|
-
|
8
|
-
|
7
|
+
# @param [Nokogiri::XML::Document] document
|
8
|
+
# @param [String] basedir
|
9
|
+
def initialize(document, basedir)
|
10
|
+
@document = document
|
9
11
|
@basedir = basedir
|
10
12
|
@extractor = Extractor.new @document, @basedir
|
11
13
|
end
|
data/lib/css_inliner/version.rb
CHANGED
data/lib/css_inliner.rb
CHANGED
@@ -6,7 +6,13 @@ require 'css_inliner/inliner'
|
|
6
6
|
|
7
7
|
module CSSInliner
|
8
8
|
class << self
|
9
|
+
# @param [Nokogiri::XML::Document, String] html
|
10
|
+
# @param [String] basedir Base directory or URI to traverse relative URI for images
|
11
|
+
# @param [String] element Element name to be returned.
|
12
|
+
# Returns whole document when nil
|
13
|
+
# @return [String] HTML source
|
9
14
|
def process(html, basedir = '.', element = nil)
|
15
|
+
doc = html.instance_of? Nokogiri::XML::Document ? html : Nokogiri.HTML(html)
|
10
16
|
doc = Inliner.new(html, basedir).inline
|
11
17
|
doc = doc.css(element)[0] if element
|
12
18
|
doc.to_s
|
data/test/test_css_inliner.rb
CHANGED
@@ -7,14 +7,32 @@ class CSSInlinerTest < CSSInlinerTestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_process_without_inline_style
|
10
|
+
pend
|
11
|
+
|
10
12
|
assert_equal *process(@sample1_dir)
|
11
13
|
end
|
12
14
|
|
13
15
|
def test_process_with_inline_style
|
16
|
+
pend
|
17
|
+
|
14
18
|
assert_equal *process(@sample2_dir)
|
15
19
|
end
|
16
20
|
|
21
|
+
def test_process_with_style_attribute
|
22
|
+
pend
|
23
|
+
|
24
|
+
assert_equal *process(@sample3_dir)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_process_with_inline_style_and_style_attibute
|
28
|
+
pend
|
29
|
+
|
30
|
+
assert_equal *process(@sample4_dir)
|
31
|
+
end
|
32
|
+
|
17
33
|
def process(basedir)
|
34
|
+
pend
|
35
|
+
|
18
36
|
source = File.read(File.join(basedir, 'index.html'))
|
19
37
|
inlined = File.read(File.join(basedir, 'index.inlined.html'))
|
20
38
|
[inlined, CSSInliner.process(source, basedir)]
|
data/test/test_extractor.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative 'helper'
|
2
2
|
require 'nokogiri'
|
3
3
|
|
4
|
-
class
|
4
|
+
class TestExtractor < CSSInlinerTestCase
|
5
5
|
def setup
|
6
6
|
super
|
7
7
|
@extractor1 = Extractor.new @doc1, @sample1_dir
|
@@ -51,4 +51,29 @@ class ExtractorTest < CSSInlinerTestCase
|
|
51
51
|
@extractor3.extract_from_style(false)
|
52
52
|
assert_equal expected, @doc3.css('style').to_s
|
53
53
|
end
|
54
|
+
|
55
|
+
def test_integrate_basic
|
56
|
+
sources = [
|
57
|
+
'
|
58
|
+
h2 {
|
59
|
+
color: gray;
|
60
|
+
}',
|
61
|
+
'
|
62
|
+
h2 p {
|
63
|
+
color: blue;
|
64
|
+
}
|
65
|
+
',
|
66
|
+
'
|
67
|
+
a {
|
68
|
+
text-decoration: none;
|
69
|
+
}
|
70
|
+
'
|
71
|
+
]
|
72
|
+
expected = {
|
73
|
+
'h2' => CssParser::RuleSet.new(nil, 'color: gray;'),
|
74
|
+
'h2 p' => CssParser::RuleSet.new(nil, 'color:blue'),
|
75
|
+
'a' => CssParser::RuleSet.new(nil, 'text-decoration: none;')
|
76
|
+
}
|
77
|
+
assert_equal expected.to_s, @extractor1.integrate(sources).to_s
|
78
|
+
end
|
54
79
|
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.1.
|
4
|
+
version: 0.1.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:
|
12
|
+
date: 2012-01-05 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &18228900 !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: *18228900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: css_parser
|
27
|
-
requirement: &
|
27
|
+
requirement: &17749120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,21 @@ dependencies:
|
|
32
32
|
version: '1'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *17749120
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: sass
|
38
|
+
requirement: &17735720 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *17735720
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: test-unit
|
38
|
-
requirement: &
|
49
|
+
requirement: &17738800 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ~>
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '2'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *17738800
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: cover_me
|
49
|
-
requirement: &
|
60
|
+
requirement: &17741120 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ~>
|
@@ -54,7 +65,18 @@ dependencies:
|
|
54
65
|
version: '1'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *17741120
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: &17743320 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *17743320
|
58
80
|
description: ! "\n inline CSS from external file(s) and/or style elment(s) in head
|
59
81
|
element\n into style attibute of HTML elements\n "
|
60
82
|
email:
|
@@ -65,6 +87,7 @@ executables:
|
|
65
87
|
extensions: []
|
66
88
|
extra_rdoc_files: []
|
67
89
|
files:
|
90
|
+
- .gemtest
|
68
91
|
- .gitignore
|
69
92
|
- Gemfile
|
70
93
|
- LICENSE
|
@@ -207,7 +230,7 @@ files:
|
|
207
230
|
- test/helper.rb
|
208
231
|
- test/test_css_inliner.rb
|
209
232
|
- test/test_extractor.rb
|
210
|
-
homepage:
|
233
|
+
homepage: http://gitorious.org/css_inliner
|
211
234
|
licenses: []
|
212
235
|
post_install_message:
|
213
236
|
rdoc_options: []
|
@@ -219,12 +242,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
219
242
|
- - ! '>='
|
220
243
|
- !ruby/object:Gem::Version
|
221
244
|
version: '0'
|
245
|
+
segments:
|
246
|
+
- 0
|
247
|
+
hash: 1616189382576311129
|
222
248
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
249
|
none: false
|
224
250
|
requirements:
|
225
251
|
- - ! '>='
|
226
252
|
- !ruby/object:Gem::Version
|
227
253
|
version: '0'
|
254
|
+
segments:
|
255
|
+
- 0
|
256
|
+
hash: 1616189382576311129
|
228
257
|
requirements: []
|
229
258
|
rubyforge_project:
|
230
259
|
rubygems_version: 1.8.8
|
@@ -232,3 +261,4 @@ signing_key:
|
|
232
261
|
specification_version: 3
|
233
262
|
summary: inline CSS into HTML attribute of elements
|
234
263
|
test_files: []
|
264
|
+
has_rdoc:
|