docomo_css 0.2.2 → 0.2.3
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/VERSION +1 -1
- data/docomo_css.gemspec +8 -5
- data/lib/docomo_css/stylesheet.rb +21 -0
- data/lib/docomo_css.rb +6 -6
- data/test/docomo_css/stylesheet_test.rb +24 -0
- data/test/docomo_css_test.rb +0 -7
- metadata +8 -5
- /data/test/{actual.css → public/actual.css} +0 -0
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/docomo_css.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{docomo_css}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["milk1000cc", "Paul McMahon"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-21}
|
13
13
|
s.description = %q{Inlines CSS so that you can use external CSS with docomo handsets.}
|
14
14
|
s.email = %q{info@milk1000.cc}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,11 +24,13 @@ Gem::Specification.new do |s|
|
|
24
24
|
"docomo_css.gemspec",
|
25
25
|
"init.rb",
|
26
26
|
"lib/docomo_css.rb",
|
27
|
+
"lib/docomo_css/stylesheet.rb",
|
27
28
|
"rails/init.rb",
|
28
|
-
"test/actual.css",
|
29
29
|
"test/actual.html",
|
30
|
+
"test/docomo_css/stylesheet_test.rb",
|
30
31
|
"test/docomo_css_test.rb",
|
31
|
-
"test/expected.html"
|
32
|
+
"test/expected.html",
|
33
|
+
"test/public/actual.css"
|
32
34
|
]
|
33
35
|
s.homepage = %q{http://www.milk1000.cc/}
|
34
36
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -36,7 +38,8 @@ Gem::Specification.new do |s|
|
|
36
38
|
s.rubygems_version = %q{1.3.7}
|
37
39
|
s.summary = %q{CSS inliner}
|
38
40
|
s.test_files = [
|
39
|
-
"test/
|
41
|
+
"test/docomo_css/stylesheet_test.rb",
|
42
|
+
"test/docomo_css_test.rb"
|
40
43
|
]
|
41
44
|
|
42
45
|
if s.respond_to? :specification_version then
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DocomoCss
|
2
|
+
class Stylesheet
|
3
|
+
attr_reader :path
|
4
|
+
|
5
|
+
def initialize(href)
|
6
|
+
@path = href && path_from_href(href)
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid?
|
10
|
+
path && FileTest.exist?(path)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def path_from_href(href)
|
16
|
+
base_path = href.gsub("http://#{ActionController::Base.asset_host}", '').
|
17
|
+
gsub(/\?\d+/, '')
|
18
|
+
File.join(Rails.root, 'public', base_path)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/docomo_css.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'tiny_css'
|
3
|
+
require 'docomo_css/stylesheet'
|
3
4
|
|
4
5
|
module DocomoCss
|
5
6
|
|
@@ -27,10 +28,9 @@ module DocomoCss
|
|
27
28
|
doc = Nokogiri::HTML(body)
|
28
29
|
|
29
30
|
stylesheet_link_node(doc).each do |linknode|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
css = TinyCss.new.read(css_path(href))
|
31
|
+
stylesheet = DocomoCss::Stylesheet.new(linknode['href'])
|
32
|
+
next unless stylesheet.valid?
|
33
|
+
css = TinyCss.new.read(stylesheet.path)
|
34
34
|
embed_pseudo_style(doc, extract_pseudo_style(css))
|
35
35
|
embed_style(doc, css)
|
36
36
|
end
|
@@ -78,8 +78,8 @@ module DocomoCss
|
|
78
78
|
document.xpath '//link[@rel="stylesheet"]'
|
79
79
|
end
|
80
80
|
|
81
|
-
def css_path(
|
82
|
-
|
81
|
+
def css_path(stylesheet)
|
82
|
+
stylesheet.path
|
83
83
|
end
|
84
84
|
|
85
85
|
def extract_pseudo_style(css)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join File.dirname(__FILE__), '..', '..', 'lib', 'docomo_css', 'stylesheet'
|
3
|
+
|
4
|
+
module ActionController; module Base; def self.asset_host; "assets.example.com"; end; end; end
|
5
|
+
|
6
|
+
class DocomoCss::StylesheetTest < Test::Unit::TestCase
|
7
|
+
def test_css_path
|
8
|
+
href = "/stylesheets/all.css?1274411517"
|
9
|
+
stylesheet = DocomoCss::Stylesheet.new(href)
|
10
|
+
assert_equal "#{Rails.root}/public/stylesheets/all.css", stylesheet.path
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_css_path_with_asset_host
|
14
|
+
href = "http://assets.example.com/stylesheets/all.css?1274411517"
|
15
|
+
stylesheet = DocomoCss::Stylesheet.new(href)
|
16
|
+
assert_equal "#{Rails.root}/public/stylesheets/all.css", stylesheet.path
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_valid
|
20
|
+
assert !DocomoCss::Stylesheet.new(nil).valid?
|
21
|
+
assert !DocomoCss::Stylesheet.new("/all.css?1274411517").valid?
|
22
|
+
assert DocomoCss::Stylesheet.new("/actual.css?1274411517").valid?
|
23
|
+
end
|
24
|
+
end
|
data/test/docomo_css_test.rb
CHANGED
@@ -51,11 +51,6 @@ a:visited { color: FF00FF; }
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def test_css_path
|
55
|
-
href = "/stylesheets/all.css?1274411517"
|
56
|
-
assert_equal "#{Rails.root}/public/stylesheets/all.css", @filter.css_path(href)
|
57
|
-
end
|
58
|
-
|
59
54
|
def test_extract_pseudo_style
|
60
55
|
css = TinyCss.new.read_string <<-CSS
|
61
56
|
a:link { color: red; }
|
@@ -163,7 +158,6 @@ a:visited { color: blue; }
|
|
163
158
|
expects(:body=).with(File.open(File.join(File.dirname(__FILE__), 'expected.html'), 'rb'){ |f| f.read })
|
164
159
|
end
|
165
160
|
controller = stub("controller", :response => response, :request => request)
|
166
|
-
@filter.stubs(:css_path).returns(File.join(File.dirname(__FILE__), 'actual.css'))
|
167
161
|
|
168
162
|
@filter.after(controller)
|
169
163
|
end
|
@@ -176,7 +170,6 @@ a:visited { color: blue; }
|
|
176
170
|
expects(:body=).with(File.open(File.join(File.dirname(__FILE__), 'expected.html'), 'rb'){ |f| f.read })
|
177
171
|
end
|
178
172
|
controller = stub("controller", :response => response, :request => request)
|
179
|
-
@filter.stubs(:css_path).returns(File.join(File.dirname(__FILE__), 'actual.css'))
|
180
173
|
|
181
174
|
@filter.after(controller)
|
182
175
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docomo_css
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- milk1000cc
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-09-
|
19
|
+
date: 2010-09-21 00:00:00 +09:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -64,11 +64,13 @@ files:
|
|
64
64
|
- docomo_css.gemspec
|
65
65
|
- init.rb
|
66
66
|
- lib/docomo_css.rb
|
67
|
+
- lib/docomo_css/stylesheet.rb
|
67
68
|
- rails/init.rb
|
68
|
-
- test/actual.css
|
69
69
|
- test/actual.html
|
70
|
+
- test/docomo_css/stylesheet_test.rb
|
70
71
|
- test/docomo_css_test.rb
|
71
72
|
- test/expected.html
|
73
|
+
- test/public/actual.css
|
72
74
|
has_rdoc: true
|
73
75
|
homepage: http://www.milk1000.cc/
|
74
76
|
licenses: []
|
@@ -104,4 +106,5 @@ signing_key:
|
|
104
106
|
specification_version: 3
|
105
107
|
summary: CSS inliner
|
106
108
|
test_files:
|
109
|
+
- test/docomo_css/stylesheet_test.rb
|
107
110
|
- test/docomo_css_test.rb
|
File without changes
|