pwim-docomo_css 0.0.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/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.swp
2
+ pkg/*
3
+ rdoc/*
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 milk1000cc
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,59 @@
1
+ = DocomoCss
2
+
3
+ docomo_css is a CSS in-liner.
4
+
5
+ Most handsets for the Japanese cell-phone carrier DoCoMo cannot use external
6
+ style sheets, such as
7
+
8
+ <link rel="stylesheet" /> style css, only can use in-line CSS.
9
+
10
+ Instead, every element must use its own style attribute, for example
11
+
12
+ <div style="font-size:x-small">
13
+
14
+ docomo_css works around this by inlining all CSS automatically for you.
15
+
16
+ == Install
17
+
18
+ sudo gem install milk1000cc-docomo_css --source=http://gems.github.com
19
+
20
+ == Usage
21
+
22
+ # app/controllers/articles_controller.rb
23
+ class ArticlesController < ApplicationController
24
+ docomo_filter # please add this
25
+ ...
26
+ end
27
+
28
+ # app/views/articles/index.html.erb
29
+ <html>
30
+ <head>
31
+ <%= stylesheet_link_tag 'foo', :media => 'handheld, tty' %>
32
+ </head>
33
+ <body>
34
+ <div class="title">bar</div>
35
+ </body>
36
+ </html>
37
+
38
+ # public/stylesheets/foo.css
39
+ .title {
40
+ color: red;
41
+ }
42
+
43
+ # result
44
+ <html>
45
+ <head>
46
+ <%= stylesheet_link_tag 'foo', :media => 'handheld, tty' %>
47
+ </head>
48
+ <body>
49
+ <div class="title" style="color:red">bar</div>
50
+ </body>
51
+ </html>
52
+
53
+ == Author
54
+
55
+ Copyright (c) 2008 milk1000cc, released under the MIT license
56
+
57
+ milk1000cc <mailto:info@milk1000.cc>
58
+
59
+ Gem and refactorings by Paul McMahon <mailto:paul@mobalean.com>
data/Rakefile ADDED
@@ -0,0 +1,38 @@
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 'milk1000cc-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 ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,54 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{docomo_css}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["milk1000cc", "Paul McMahon"]
9
+ s.date = %q{2009-06-11}
10
+ s.description = %q{Inlines CSS so that you can use external CSS with docomo handsets.}
11
+ s.email = %q{info@milk1000.cc}
12
+ s.extra_rdoc_files = [
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".gitignore",
17
+ "MIT-LICENSE",
18
+ "README.rdoc",
19
+ "Rakefile",
20
+ "VERSION",
21
+ "docomo_css.gemspec",
22
+ "init.rb",
23
+ "install.rb",
24
+ "lib/docomo_css.rb",
25
+ "rails/init.rb",
26
+ "test/docomo_css_test.rb",
27
+ "uninstall.rb"
28
+ ]
29
+ s.has_rdoc = true
30
+ s.homepage = %q{http://www.milk1000.cc/}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.1}
34
+ s.summary = %q{CSS inliner}
35
+ s.test_files = [
36
+ "test/docomo_css_test.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 2
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<hpricot>, [">= 0"])
45
+ s.add_runtime_dependency(%q<milk1000cc-tiny_css>, [">= 0"])
46
+ else
47
+ s.add_dependency(%q<hpricot>, [">= 0"])
48
+ s.add_dependency(%q<milk1000cc-tiny_css>, [">= 0"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<hpricot>, [">= 0"])
52
+ s.add_dependency(%q<milk1000cc-tiny_css>, [">= 0"])
53
+ end
54
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'docomo_css'
2
+ ActionController::Base.send :include, DocomoCss
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
data/lib/docomo_css.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'hpricot'
2
+ require 'tiny_css'
3
+
4
+ module DocomoCss
5
+
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def docomo_filter
12
+ after_filter DocomoCssFilter.new
13
+ end
14
+ end
15
+
16
+ class DocomoCssFilter
17
+ def after(controller)
18
+ content = controller.response.body
19
+
20
+ content.gsub! /&#(\d+);/, 'HTMLCSSINLINERESCAPE\1::::::::'
21
+
22
+ doc = Hpricot(content)
23
+
24
+ linknodes = doc/'//link[@rel="stylesheet"]'
25
+ linknodes.each do |linknode|
26
+ href = linknode['href'] or next
27
+
28
+ cssfile = File.join(RAILS_ROOT, 'public', href)
29
+ cssfile.gsub! /\?.+/, ''
30
+ css = TinyCss.new.read(cssfile)
31
+
32
+ pseudo_selectors = css.style.keys.reject { |v|
33
+ v !~ /a:(link|focus|visited)/
34
+ }
35
+ unless pseudo_selectors.empty?
36
+ style_style = TinyCss.new
37
+ pseudo_selectors.each do |v|
38
+ style_style.style[v] = css.style[v]
39
+ css.style.delete v
40
+ end
41
+
42
+ style = %(<style type="text/css">#{ style_style.write_string }</style>)
43
+ (doc/('head')).append style
44
+ end
45
+
46
+ css.style.each do |selector, style|
47
+ (doc/(selector)).each do |element|
48
+ style_attr = element[:style]
49
+ style_attr = (!style_attr) ? stringify_style(style) :
50
+ [style_attr, stringify_style(style)].join(';')
51
+ element[:style] = style_attr
52
+ end
53
+ end
54
+ end
55
+
56
+ content = doc.to_html
57
+
58
+ content.gsub! /HTMLCSSINLINERESCAPE(\d+)::::::::/, '&#\1;'
59
+
60
+ controller.response.body = content
61
+ end
62
+
63
+ private
64
+ def stringify_style(style)
65
+ style.map { |k, v| "#{ k }:#{ v }" }.join ';'
66
+ end
67
+ end
68
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'docomo_css'
2
+ ActionController::Base.send :include, DocomoCss
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'action_controller'
4
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'docomo_css')
5
+
6
+ class TestController < ActionController::Base
7
+ include DocomoCss
8
+ docomo_filter
9
+ end
10
+
11
+ class DocomoCssTest < Test::Unit::TestCase
12
+ def test_dependencies
13
+ assert true
14
+ end
15
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pwim-docomo_css
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - milk1000cc
8
+ - Paul McMahon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-06-11 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: hpricot
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: milk1000cc-tiny_css
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ version:
36
+ description: Inlines CSS so that you can use external CSS with docomo handsets.
37
+ email: info@milk1000.cc
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.rdoc
44
+ files:
45
+ - .gitignore
46
+ - MIT-LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - docomo_css.gemspec
51
+ - init.rb
52
+ - install.rb
53
+ - lib/docomo_css.rb
54
+ - rails/init.rb
55
+ - test/docomo_css_test.rb
56
+ - uninstall.rb
57
+ has_rdoc: true
58
+ homepage: http://www.milk1000.cc/
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.2.0
80
+ signing_key:
81
+ specification_version: 2
82
+ summary: CSS inliner
83
+ test_files:
84
+ - test/docomo_css_test.rb