galakei 0.6.1 → 0.6.2
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/lib/galakei/docomo_css/stylesheet.rb +2 -0
- data/lib/galakei/filter/non_standard_char.rb +2 -1
- data/lib/galakei/filter/recode.rb +17 -0
- data/lib/galakei/railtie.rb +1 -1
- data/lib/galakei/version.rb +1 -1
- data/lib/galakei.rb +2 -1
- data/spec/acceptance/recode_spec.rb +15 -0
- data/spec/galakei/docomo_css/stylesheet_spec.rb +34 -6
- metadata +5 -3
@@ -6,7 +6,8 @@ class Galakei::Filter::NonStandardChar < Galakei::Filter::Base
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def condition?
|
9
|
-
response.content_type =~ %r{text/html|application/xhtml+xml}
|
9
|
+
response.content_type =~ %r{text/html|application/xhtml+xml} &&
|
10
|
+
(response.charset || Rails.application.config.encoding).downcase == "utf-8"
|
10
11
|
end
|
11
12
|
|
12
13
|
def filter
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Takes care of recoding pages to Shift-JIS for some handsets when required
|
2
|
+
class Galakei::Filter::Recode < Galakei::Filter::Base
|
3
|
+
def self.inject(klass)
|
4
|
+
this_class = self
|
5
|
+
klass.after_filter self, :if => lambda {|c| this_class.condition?(c) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def condition?
|
9
|
+
request.ssl? && request.au?
|
10
|
+
end
|
11
|
+
|
12
|
+
def filter
|
13
|
+
doc = Nokogiri::HTML(response.body)
|
14
|
+
response.body = doc.serialize(:encoding => 'Shift_JIS')
|
15
|
+
response.charset = "Shift_JIS"
|
16
|
+
end
|
17
|
+
end
|
data/lib/galakei/railtie.rb
CHANGED
@@ -4,7 +4,7 @@ module Galakei
|
|
4
4
|
initializer "galakei.extend.action_controller" do |app|
|
5
5
|
ActiveSupport.on_load :action_controller do
|
6
6
|
include Galakei::HelperMethods
|
7
|
-
filters = %w[Views ContentType NonStandardChar]
|
7
|
+
filters = %w[Views ContentType Recode NonStandardChar]
|
8
8
|
filters << :Haml if defined?(Haml)
|
9
9
|
filters.each {|f| Galakei::Filter.const_get(f).inject(self) }
|
10
10
|
end
|
data/lib/galakei/version.rb
CHANGED
data/lib/galakei.rb
CHANGED
@@ -18,7 +18,8 @@ module Galakei
|
|
18
18
|
autoload :Base, "galakei/filter/base"
|
19
19
|
autoload :ContentType, "galakei/filter/content_type"
|
20
20
|
autoload :Haml, "galakei/filter/haml"
|
21
|
-
autoload :Views, "galakei/filter/views"
|
22
21
|
autoload :NonStandardChar, "galakei/filter/non_standard_char"
|
22
|
+
autoload :Recode, "galakei/filter/recode"
|
23
|
+
autoload :Views, "galakei/filter/views"
|
23
24
|
end
|
24
25
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
|
3
|
+
|
4
|
+
class RecodeController < ApplicationController
|
5
|
+
def index
|
6
|
+
render :layout => true, :inline => "Test"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
feature 'recode' do
|
11
|
+
scenario 'au SSL', :driver => :au do
|
12
|
+
visit 'https://www.example.com/recode/index'
|
13
|
+
page.find(:xpath, '//head/meta')['content'].should == "text/html; charset=Shift_JIS"
|
14
|
+
end
|
15
|
+
end
|
@@ -79,7 +79,7 @@ EOD
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
((1..6).map {|i| "h#{i}"} + %w[p]).each do |tag|
|
82
|
+
((1..6).map {|i| "h#{i}"} + %w[p td]).each do |tag|
|
83
83
|
context "style applied to #{tag}" do
|
84
84
|
before do
|
85
85
|
parser = CssParser::Parser.new
|
@@ -110,20 +110,48 @@ EOD
|
|
110
110
|
doc.at("//#{tag}").to_s.should == %Q{<#{tag} class="fontsize"><span style="font-size: x-small;">foo<br>bar</span></#{tag}>}
|
111
111
|
end
|
112
112
|
|
113
|
+
it "should applied css of tag omitted" do
|
114
|
+
doc = Nokogiri::HTML("<#{tag} class='classonly'>foo</#{tag}>")
|
115
|
+
@stylesheet.apply(doc)
|
116
|
+
doc.at("//#{tag}").to_s.should == %Q{<#{tag} class="classonly" style="line-height: 1px;">foo</#{tag}>}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
((1..6).map {|i| "h#{i}"} + %w[p]).each do |tag|
|
123
|
+
context "style applied to #{tag}" do
|
124
|
+
before do
|
125
|
+
parser = CssParser::Parser.new
|
126
|
+
parser.add_block!(<<-EOD)
|
127
|
+
#{tag}.backgroundcolor { background-color: blue; }
|
128
|
+
EOD
|
129
|
+
@stylesheet = described_class.new(parser)
|
130
|
+
end
|
113
131
|
it "should wrap element in div for background-color" do
|
114
132
|
doc = Nokogiri::HTML("<#{tag} class='backgroundcolor'>foo</#{tag}>")
|
115
133
|
@stylesheet.apply(doc)
|
116
134
|
doc.at("//div").to_s.should == %Q{<div style="background-color: blue;"><#{tag} class="backgroundcolor">foo</#{tag}></div>}
|
117
135
|
end
|
136
|
+
end
|
137
|
+
end
|
118
138
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
139
|
+
context "style applied to td" do
|
140
|
+
before do
|
141
|
+
parser = CssParser::Parser.new
|
142
|
+
parser.add_block!(<<-EOD)
|
143
|
+
td { background-color: blue; }
|
144
|
+
EOD
|
145
|
+
@stylesheet = described_class.new(parser)
|
146
|
+
end
|
147
|
+
it "should wrap element in div for background-color" do
|
148
|
+
doc = Nokogiri::HTML("<td>foo</td>")
|
149
|
+
@stylesheet.apply(doc)
|
150
|
+
doc.at("//td").to_s.should == %Q{<td style="background-color: blue;">foo</td>}
|
124
151
|
end
|
125
152
|
end
|
126
153
|
|
154
|
+
|
127
155
|
context "style applied to child of h1" do
|
128
156
|
before do
|
129
157
|
parser = CssParser::Parser.new
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 0.6.
|
8
|
+
- 2
|
9
|
+
version: 0.6.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Paul McMahon
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-04-
|
19
|
+
date: 2011-04-19 00:00:00 +09:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/galakei/filter/content_type.rb
|
106
106
|
- lib/galakei/filter/haml.rb
|
107
107
|
- lib/galakei/filter/non_standard_char.rb
|
108
|
+
- lib/galakei/filter/recode.rb
|
108
109
|
- lib/galakei/filter/views.rb
|
109
110
|
- lib/galakei/helper_methods.rb
|
110
111
|
- lib/galakei/input_mode.rb
|
@@ -125,6 +126,7 @@ files:
|
|
125
126
|
- spec/acceptance/handset_detection_spec.rb
|
126
127
|
- spec/acceptance/input_mode_spec.rb
|
127
128
|
- spec/acceptance/non_standard_char_spec.rb
|
129
|
+
- spec/acceptance/recode_spec.rb
|
128
130
|
- spec/acceptance/session_spec.rb
|
129
131
|
- spec/acceptance/support/capybara_ssl_fix.rb
|
130
132
|
- spec/acceptance/support/handsets.rb
|