docomo_css 0.2.5 → 0.3.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/README.rdoc CHANGED
@@ -17,7 +17,10 @@ docomo_css works around this by inlining all CSS automatically for you.
17
17
 
18
18
  sudo gem install docomo_css
19
19
 
20
- libxml 2.7 or later is required
20
+ == Requirements
21
+
22
+ * libxml 2.7 or later is required
23
+ * Rails 3
21
24
 
22
25
  == Usage
23
26
 
@@ -52,13 +55,6 @@ libxml 2.7 or later is required
52
55
  </body>
53
56
  </html>
54
57
 
55
- In addition to the basic usage, you may also provide the css inliner with additional directive by adding a docomo_css attribute to the style tag.
56
-
57
- Options for the value of this docomo_css are
58
-
59
- * ignore - this stylesheet will not be inlined
60
- * remove_after_inline - remove the link to this stylesheet after processing it
61
-
62
58
  == Author
63
59
 
64
60
  Copyright (c) 2008 milk1000cc, released under the MIT license
@@ -0,0 +1,5 @@
1
+ class DocomoCss::Railtie < Rails::Railtie
2
+ initializer "docomo_css.extend.action_controller" do
3
+ ActionController::Base.send :include, DocomoCss
4
+ end
5
+ end
@@ -13,7 +13,7 @@ module DocomoCss
13
13
  private
14
14
 
15
15
  def path_from_href(href)
16
- base_path = href.gsub(ActionController::Base.asset_host, '').
16
+ base_path = href.gsub(ActionController::Base.asset_host.to_s, '').
17
17
  gsub(/\?\d+/, '')
18
18
  File.join(Rails.root, 'public', base_path)
19
19
  end
@@ -0,0 +1,3 @@
1
+ class DocomoCss
2
+ Version = "0.3.0"
3
+ end
data/lib/docomo_css.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'nokogiri'
2
2
  require 'tiny_css'
3
3
  require 'docomo_css/stylesheet'
4
+ require 'docomo_css/railtie'
4
5
 
5
6
  module DocomoCss
6
7
 
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: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 5
10
- version: 0.2.5
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
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: 2010-09-29 00:00:00 +09:00
19
+ date: 2010-11-24 00:00:00 +09:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
- name: hpricot
23
+ name: nokogiri
24
24
  prerelease: false
25
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
@@ -53,24 +53,15 @@ executables: []
53
53
 
54
54
  extensions: []
55
55
 
56
- extra_rdoc_files:
57
- - README.rdoc
56
+ extra_rdoc_files: []
57
+
58
58
  files:
59
- - .gitignore
60
59
  - MIT-LICENSE
61
60
  - README.rdoc
62
- - Rakefile
63
- - VERSION
64
- - docomo_css.gemspec
65
- - init.rb
66
- - lib/docomo_css.rb
61
+ - lib/docomo_css/railtie.rb
67
62
  - lib/docomo_css/stylesheet.rb
68
- - rails/init.rb
69
- - test/actual.html
70
- - test/docomo_css/stylesheet_test.rb
71
- - test/docomo_css_test.rb
72
- - test/expected.html
73
- - test/public/actual.css
63
+ - lib/docomo_css/version.rb
64
+ - lib/docomo_css.rb
74
65
  has_rdoc: true
75
66
  homepage: http://www.milk1000.cc/
76
67
  licenses: []
@@ -94,17 +85,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
85
  requirements:
95
86
  - - ">="
96
87
  - !ruby/object:Gem::Version
97
- hash: 3
88
+ hash: 23
98
89
  segments:
99
- - 0
100
- version: "0"
90
+ - 1
91
+ - 3
92
+ - 6
93
+ version: 1.3.6
101
94
  requirements: []
102
95
 
103
- rubyforge_project:
96
+ rubyforge_project: docomo_css
104
97
  rubygems_version: 1.3.7
105
98
  signing_key:
106
99
  specification_version: 3
107
100
  summary: CSS inliner
108
- test_files:
109
- - test/docomo_css/stylesheet_test.rb
110
- - test/docomo_css_test.rb
101
+ test_files: []
102
+
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- *.swp
2
- pkg/*
3
- rdoc/*
data/Rakefile DELETED
@@ -1,38 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- desc 'Default: run unit tests.'
6
- task :default => :test
7
-
8
- desc 'Test the docomo_css plugin.'
9
- Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
13
- end
14
-
15
- desc 'Generate documentation for the docomo_css plugin.'
16
- Rake::RDocTask.new(:rdoc) do |rdoc|
17
- rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = 'DocomoCss'
19
- rdoc.options << '--line-numbers' << '--inline-source'
20
- rdoc.rdoc_files.include('README.rdoc')
21
- rdoc.rdoc_files.include('lib/**/*.rb')
22
- end
23
-
24
- begin
25
- require 'jeweler'
26
- Jeweler::Tasks.new do |s|
27
- s.name = "docomo_css"
28
- s.summary = "CSS inliner"
29
- s.description = "Inlines CSS so that you can use external CSS with docomo handsets."
30
- s.email = "info@milk1000.cc"
31
- s.homepage = "http://www.milk1000.cc/"
32
- s.authors = ["milk1000cc", "Paul McMahon"]
33
- s.add_dependency 'hpricot'
34
- s.add_dependency 'tiny_css'
35
- end
36
- rescue LoadError
37
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
38
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.5
data/docomo_css.gemspec DELETED
@@ -1,60 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{docomo_css}
8
- s.version = "0.2.5"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["milk1000cc", "Paul McMahon"]
12
- s.date = %q{2010-09-29}
13
- s.description = %q{Inlines CSS so that you can use external CSS with docomo handsets.}
14
- s.email = %q{info@milk1000.cc}
15
- s.extra_rdoc_files = [
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- ".gitignore",
20
- "MIT-LICENSE",
21
- "README.rdoc",
22
- "Rakefile",
23
- "VERSION",
24
- "docomo_css.gemspec",
25
- "init.rb",
26
- "lib/docomo_css.rb",
27
- "lib/docomo_css/stylesheet.rb",
28
- "rails/init.rb",
29
- "test/actual.html",
30
- "test/docomo_css/stylesheet_test.rb",
31
- "test/docomo_css_test.rb",
32
- "test/expected.html",
33
- "test/public/actual.css"
34
- ]
35
- s.homepage = %q{http://www.milk1000.cc/}
36
- s.rdoc_options = ["--charset=UTF-8"]
37
- s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.3.7}
39
- s.summary = %q{CSS inliner}
40
- s.test_files = [
41
- "test/docomo_css/stylesheet_test.rb",
42
- "test/docomo_css_test.rb"
43
- ]
44
-
45
- if s.respond_to? :specification_version then
46
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
- s.specification_version = 3
48
-
49
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
- s.add_runtime_dependency(%q<hpricot>, [">= 0"])
51
- s.add_runtime_dependency(%q<tiny_css>, [">= 0"])
52
- else
53
- s.add_dependency(%q<hpricot>, [">= 0"])
54
- s.add_dependency(%q<tiny_css>, [">= 0"])
55
- end
56
- else
57
- s.add_dependency(%q<hpricot>, [">= 0"])
58
- s.add_dependency(%q<tiny_css>, [">= 0"])
59
- end
60
- end
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require File.join File.dirname(__FILE__), 'rails', 'init'
data/rails/init.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'docomo_css'
2
- ActionController::Base.send :include, DocomoCss
data/test/actual.html DELETED
@@ -1,13 +0,0 @@
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>
@@ -1,24 +0,0 @@
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; "http://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
@@ -1,189 +0,0 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
- require 'mocha'
4
- require File.join File.dirname(__FILE__), '..', 'lib', 'docomo_css'
5
-
6
- Rails = Mocha::Mockery.instance.unnamed_mock
7
- Rails.stubs(:root => File.dirname(__FILE__))
8
-
9
- class DocomoCssTest < Test::Unit::TestCase
10
- def setup
11
- @filter = DocomoCss::DocomoCssFilter.new
12
- end
13
-
14
- def test_invalid_response_content_type
15
- response = mock("invalid_response") do
16
- expects(:content_type).returns('text/html').once
17
- expects(:body).never
18
- end
19
- controller = stub("invalid_controller", :response => response)
20
- @filter.after(controller)
21
- end
22
-
23
- def test_escape_numeric_character_reference
24
- assert_equal "HTMLCSSINLINERESCAPE123456789::::::::", @filter.escape_numeric_character_reference("&#123456789;")
25
- assert_equal "HTMLCSSINLINERESCAPEx123def::::::::", @filter.escape_numeric_character_reference("&#x123def;")
26
- end
27
-
28
- def test_unescape_numeric_character_reference
29
- assert_equal "&#123456789;", @filter.unescape_numeric_character_reference("HTMLCSSINLINERESCAPE123456789::::::::")
30
- assert_equal "&#x123def;", @filter.unescape_numeric_character_reference("HTMLCSSINLINERESCAPEx123def::::::::")
31
- end
32
-
33
- def test_pseudo_selectors
34
- css = TinyCss.new.read_string(<<-CSS)
35
- a:visited { color: FF00FF; }
36
- CSS
37
- assert_equal ["a:visited"], @filter.pseudo_selectors(css)
38
-
39
- css = TinyCss.new.read_string(<<-CSS)
40
- .purple { color: FF00FF; }
41
- CSS
42
- assert_equal [], @filter.pseudo_selectors(css)
43
- end
44
-
45
- def test_stylesheet_link_node
46
- doc = Nokogiri::HTML(<<-HTML)
47
- <link href="a.css"/>
48
- <link href="b.css" rel="stylesheet"/>
49
- HTML
50
-
51
- @filter.stylesheet_link_node(doc).each do |node|
52
- assert_equal 'b.css', node['href']
53
- end
54
- end
55
-
56
- def test_extract_pseudo_style
57
- css = TinyCss.new.read_string <<-CSS
58
- a:link { color: red; }
59
- a:focus { color: green; }
60
- a:visited { color: blue; }
61
- div.title { background-color: #999 }
62
- CSS
63
-
64
- pseudo_style = @filter.extract_pseudo_style css
65
- assert_equal('red', pseudo_style.style['a:link']['color'])
66
- assert_equal('green', pseudo_style.style['a:focus']['color'])
67
- assert_equal('blue', pseudo_style.style['a:visited']['color'])
68
- assert_equal('#999', css.style['div.title']['background-color'])
69
- end
70
-
71
- def test_embed_pseudo_style
72
- css = TinyCss.new
73
- assert_equal nil, @filter.embed_pseudo_style(nil, css)
74
-
75
- css = TinyCss.new.read_string <<-CSS
76
- a:link { color: red; }
77
- a:focus { color: green; }
78
- a:visited { color: blue; }
79
- CSS
80
-
81
- doc = Nokogiri::HTML <<-HTML
82
- <html>
83
- <head></head>
84
- <body></body>
85
- </html>
86
- HTML
87
- doc = @filter.embed_pseudo_style doc, css
88
- assert_match %r'<style .*?/style>'m, doc.to_xhtml
89
-
90
- doc = Nokogiri::HTML <<-HTML
91
- <html>
92
- <body></body>
93
- </html>
94
- HTML
95
- assert_raise RuntimeError do
96
- @filter.embed_pseudo_style doc, css
97
- end
98
- end
99
-
100
- def test_embed_style
101
- css = TinyCss.new.read_string <<-CSS
102
- .title { color: red; }
103
- CSS
104
-
105
- doc = Nokogiri::HTML <<-HTML
106
- <html>
107
- <body>
108
- <div class="title">bar</div>
109
- </body>
110
- </html>
111
- HTML
112
- @filter.embed_style doc, css
113
- assert_match %r'style="color:red"', doc.to_xhtml
114
-
115
- doc = Nokogiri::HTML <<-HTML
116
- <html>
117
- <body>
118
- <div class="title" style="background-color:black">bar</div>
119
- </body>
120
- </html>
121
- HTML
122
- @filter.embed_style doc, css
123
- assert_match %r'style="background-color:black;color:red"', doc.to_xhtml
124
-
125
- doc = Nokogiri::HTML <<-HTML
126
- <html>
127
- <body>
128
- <div class="title" style="background-color:silver;">bar</div>
129
- </body>
130
- </html>
131
- HTML
132
- @filter.embed_style doc, css
133
- assert_match %r'style="background-color:silver;color:red"', doc.to_xhtml
134
- end
135
-
136
- def test_xml_declare
137
- doc = stub("doc", :encoding => "Shift_JIS")
138
- assert_equal <<-XML, @filter.xml_declare(doc)
139
- <?xml version="1.0" encoding="Shift_JIS"?>
140
- XML
141
-
142
- doc = stub("doc", :encoding => "UTF-8")
143
- assert_equal <<-XML, @filter.xml_declare(doc)
144
- <?xml version="1.0" encoding="UTF-8"?>
145
- XML
146
- end
147
-
148
- def test_remove_xml_declare
149
- assert_equal '', @filter.remove_xml_declare('<?xml version="1.0"?>')
150
- assert_equal '', @filter.remove_xml_declare('<?xml encoding="Shift_JIS"?>')
151
- assert_equal '', @filter.remove_xml_declare('<?xml version="1.0" encoding="Shift_JIS" ?>')
152
- assert_equal '', @filter.remove_xml_declare('<?xml?>')
153
- end
154
-
155
- def test_output_with_docomo_1_0_browser
156
- request = stub('request', :user_agent => 'DoCoMo/2.0 D905i(c100;TB;W24H17)')
157
- response = stub("response") do
158
- expects(:content_type).returns('application/xhtml+xml')
159
- expects(:body).returns(File.open(File.join(File.dirname(__FILE__), 'actual.html'), 'rb'){ |f| f.read })
160
- expects(:body=).with(File.open(File.join(File.dirname(__FILE__), 'expected.html'), 'rb'){ |f| f.read })
161
- end
162
- controller = stub("controller", :response => response, :request => request)
163
-
164
- @filter.after(controller)
165
- end
166
-
167
- def test_output_with_docomo_1_0_browser_and_utf8_charset
168
- request = stub('request', :user_agent => 'DoCoMo/2.0 D905i(c100;TB;W24H17)')
169
- response = stub("response") do
170
- expects(:content_type).returns('application/xhtml+xml; charset=utf-8')
171
- expects(:body).returns(File.open(File.join(File.dirname(__FILE__), 'actual.html'), 'rb'){ |f| f.read })
172
- expects(:body=).with(File.open(File.join(File.dirname(__FILE__), 'expected.html'), 'rb'){ |f| f.read })
173
- end
174
- controller = stub("controller", :response => response, :request => request)
175
-
176
- @filter.after(controller)
177
- end
178
-
179
- def test_output_with_docomo_2_0_browser
180
- request = stub('request', :user_agent => 'DoCoMo/2.0 N03B(c500;TB;W24H16)')
181
- response = stub("response") do
182
- expects(:content_type).returns('application/xhtml+xml')
183
- expects(:body).never
184
- end
185
- controller = stub("controller", :response => response, :request => request)
186
-
187
- @filter.after(controller)
188
- end
189
- end
data/test/expected.html DELETED
@@ -1,27 +0,0 @@
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>
@@ -1,4 +0,0 @@
1
- a:link { color: red; }
2
- a:focus { color: green; }
3
- a:visited { color: blue; }
4
- div.content { background-color: #999 }