docomo_css 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/docomo_css.gemspec +15 -9
- data/lib/docomo_css.rb +8 -1
- data/test/actual.css +4 -0
- data/test/actual.html +13 -0
- data/test/docomo_css_test.rb +27 -2
- data/test/expected.html +27 -0
- metadata +9 -6
data/Rakefile
CHANGED
@@ -31,7 +31,7 @@ begin
|
|
31
31
|
s.homepage = "http://www.milk1000.cc/"
|
32
32
|
s.authors = ["milk1000cc", "Paul McMahon"]
|
33
33
|
s.add_dependency 'hpricot'
|
34
|
-
s.add_dependency '
|
34
|
+
s.add_dependency 'tiny_css'
|
35
35
|
end
|
36
36
|
rescue LoadError
|
37
37
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.2
|
data/docomo_css.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{docomo_css}
|
5
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["milk1000cc", "Paul McMahon"]
|
9
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-09-15}
|
10
13
|
s.description = %q{Inlines CSS so that you can use external CSS with docomo handsets.}
|
11
14
|
s.email = %q{info@milk1000.cc}
|
12
15
|
s.extra_rdoc_files = [
|
@@ -22,13 +25,15 @@ Gem::Specification.new do |s|
|
|
22
25
|
"init.rb",
|
23
26
|
"lib/docomo_css.rb",
|
24
27
|
"rails/init.rb",
|
28
|
+
"test/actual.css",
|
29
|
+
"test/actual.html",
|
25
30
|
"test/docomo_css_test.rb",
|
31
|
+
"test/expected.html"
|
26
32
|
]
|
27
|
-
s.has_rdoc = true
|
28
33
|
s.homepage = %q{http://www.milk1000.cc/}
|
29
34
|
s.rdoc_options = ["--charset=UTF-8"]
|
30
35
|
s.require_paths = ["lib"]
|
31
|
-
s.rubygems_version = %q{1.3.
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
32
37
|
s.summary = %q{CSS inliner}
|
33
38
|
s.test_files = [
|
34
39
|
"test/docomo_css_test.rb"
|
@@ -36,17 +41,18 @@ Gem::Specification.new do |s|
|
|
36
41
|
|
37
42
|
if s.respond_to? :specification_version then
|
38
43
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
39
|
-
s.specification_version =
|
44
|
+
s.specification_version = 3
|
40
45
|
|
41
|
-
if Gem::Version.new(Gem::
|
42
|
-
s.add_runtime_dependency(%q<
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<hpricot>, [">= 0"])
|
43
48
|
s.add_runtime_dependency(%q<tiny_css>, [">= 0"])
|
44
49
|
else
|
45
|
-
s.add_dependency(%q<
|
50
|
+
s.add_dependency(%q<hpricot>, [">= 0"])
|
46
51
|
s.add_dependency(%q<tiny_css>, [">= 0"])
|
47
52
|
end
|
48
53
|
else
|
49
|
-
s.add_dependency(%q<
|
54
|
+
s.add_dependency(%q<hpricot>, [">= 0"])
|
50
55
|
s.add_dependency(%q<tiny_css>, [">= 0"])
|
51
56
|
end
|
52
57
|
end
|
58
|
+
|
data/lib/docomo_css.rb
CHANGED
@@ -15,8 +15,9 @@ module DocomoCss
|
|
15
15
|
|
16
16
|
class DocomoCssFilter
|
17
17
|
def after(controller)
|
18
|
-
return unless controller.response.content_type
|
18
|
+
return unless controller.response.content_type =~ /application\/xhtml\+xml/
|
19
19
|
return unless controller.request.user_agent =~ /docomo/i
|
20
|
+
return if docomo_2_0_browser?(controller)
|
20
21
|
body = escape_numeric_character_reference controller.response.body
|
21
22
|
body = embed_css remove_xml_declare(body)
|
22
23
|
controller.response.body = unescape_numeric_character_reference body
|
@@ -105,5 +106,11 @@ module DocomoCss
|
|
105
106
|
def pseudo_selectors(css)
|
106
107
|
css.style.keys.grep(/a:(link|focus|visited)/)
|
107
108
|
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def docomo_2_0_browser?(controller)
|
113
|
+
controller.request.user_agent =~ /DoCoMo\/2\.0 [^(]*\(c(\d+);/ && $1.to_i >= 500
|
114
|
+
end
|
108
115
|
end
|
109
116
|
end
|
data/test/actual.css
ADDED
data/test/actual.html
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
<?xml version="1.0" encoding="Shift_JIS"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.3) 1.0//EN" "i-xhtml_4ja_10.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=Shift_JIS" />
|
6
|
+
<link rel="stylesheet" href="/actual.css" />
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<div class="content">
|
10
|
+
<a href="/">TOP</a>
|
11
|
+
</div>
|
12
|
+
</body>
|
13
|
+
</html>
|
data/test/docomo_css_test.rb
CHANGED
@@ -155,15 +155,40 @@ a:visited { color: blue; }
|
|
155
155
|
assert_equal '', @filter.remove_xml_declare('<?xml?>')
|
156
156
|
end
|
157
157
|
|
158
|
-
def
|
158
|
+
def test_output_with_docomo_1_0_browser
|
159
|
+
request = stub('request', :user_agent => 'DoCoMo/2.0 D905i(c100;TB;W24H17)')
|
159
160
|
response = stub("response") do
|
160
161
|
expects(:content_type).returns('application/xhtml+xml')
|
161
162
|
expects(:body).returns(File.open(File.join(File.dirname(__FILE__), 'actual.html'), 'rb'){ |f| f.read })
|
162
163
|
expects(:body=).with(File.open(File.join(File.dirname(__FILE__), 'expected.html'), 'rb'){ |f| f.read })
|
163
164
|
end
|
164
|
-
controller = stub("controller", :response => response)
|
165
|
+
controller = stub("controller", :response => response, :request => request)
|
165
166
|
@filter.stubs(:css_path).returns(File.join(File.dirname(__FILE__), 'actual.css'))
|
166
167
|
|
167
168
|
@filter.after(controller)
|
168
169
|
end
|
170
|
+
|
171
|
+
def test_output_with_docomo_1_0_browser_and_utf8_charset
|
172
|
+
request = stub('request', :user_agent => 'DoCoMo/2.0 D905i(c100;TB;W24H17)')
|
173
|
+
response = stub("response") do
|
174
|
+
expects(:content_type).returns('application/xhtml+xml; charset=utf-8')
|
175
|
+
expects(:body).returns(File.open(File.join(File.dirname(__FILE__), 'actual.html'), 'rb'){ |f| f.read })
|
176
|
+
expects(:body=).with(File.open(File.join(File.dirname(__FILE__), 'expected.html'), 'rb'){ |f| f.read })
|
177
|
+
end
|
178
|
+
controller = stub("controller", :response => response, :request => request)
|
179
|
+
@filter.stubs(:css_path).returns(File.join(File.dirname(__FILE__), 'actual.css'))
|
180
|
+
|
181
|
+
@filter.after(controller)
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_output_with_docomo_2_0_browser
|
185
|
+
request = stub('request', :user_agent => 'DoCoMo/2.0 N03B(c500;TB;W24H16)')
|
186
|
+
response = stub("response") do
|
187
|
+
expects(:content_type).returns('application/xhtml+xml')
|
188
|
+
expects(:body).never
|
189
|
+
end
|
190
|
+
controller = stub("controller", :response => response, :request => request)
|
191
|
+
|
192
|
+
@filter.after(controller)
|
193
|
+
end
|
169
194
|
end
|
data/test/expected.html
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.0" encoding="Shift_JIS"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.3) 1.0//EN" "i-xhtml_4ja_10.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=Shift_JIS" />
|
6
|
+
<link rel="stylesheet" href="/actual.css" />
|
7
|
+
<style type="text/css">
|
8
|
+
<![CDATA[
|
9
|
+
a:visited {
|
10
|
+
color: blue;
|
11
|
+
}
|
12
|
+
a:link {
|
13
|
+
color: red;
|
14
|
+
}
|
15
|
+
a:focus {
|
16
|
+
color: green;
|
17
|
+
}
|
18
|
+
|
19
|
+
]]>
|
20
|
+
</style>
|
21
|
+
</head>
|
22
|
+
<body>
|
23
|
+
<div class="content" style="background-color:#999">
|
24
|
+
<a href="/">TOP</a>
|
25
|
+
</div>
|
26
|
+
</body>
|
27
|
+
</html>
|
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: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- milk1000cc
|
@@ -16,11 +16,11 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2010-09-15 00:00:00 +09:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
|
-
name:
|
23
|
+
name: hpricot
|
24
24
|
prerelease: false
|
25
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
@@ -65,7 +65,10 @@ files:
|
|
65
65
|
- init.rb
|
66
66
|
- lib/docomo_css.rb
|
67
67
|
- rails/init.rb
|
68
|
+
- test/actual.css
|
69
|
+
- test/actual.html
|
68
70
|
- test/docomo_css_test.rb
|
71
|
+
- test/expected.html
|
69
72
|
has_rdoc: true
|
70
73
|
homepage: http://www.milk1000.cc/
|
71
74
|
licenses: []
|
@@ -98,7 +101,7 @@ requirements: []
|
|
98
101
|
rubyforge_project:
|
99
102
|
rubygems_version: 1.3.7
|
100
103
|
signing_key:
|
101
|
-
specification_version:
|
104
|
+
specification_version: 3
|
102
105
|
summary: CSS inliner
|
103
106
|
test_files:
|
104
107
|
- test/docomo_css_test.rb
|