jpmobile 3.0.3 → 3.0.4

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.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 3
3
3
  :minor: 0
4
- :patch: 3
4
+ :patch: 4
5
5
  :build:
data/jpmobile.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jpmobile}
8
- s.version = "3.0.3"
8
+ s.version = "3.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yoji Shidara", "Shin-ichiro OGAWA"]
data/lib/jpmobile.rb CHANGED
@@ -22,14 +22,19 @@ module Jpmobile
22
22
  autoload :Emobile, 'jpmobile/mobile/emobile'
23
23
  autoload :Willcom, 'jpmobile/mobile/willcom'
24
24
  autoload :Ddipocket, 'jpmobile/mobile/ddipocket'
25
+
25
26
  autoload :SmartPhone, 'jpmobile/mobile/smart_phone'
26
27
  autoload :Iphone, 'jpmobile/mobile/iphone'
27
28
  autoload :Android, 'jpmobile/mobile/android'
28
29
  autoload :WindowsPhone, 'jpmobile/mobile/windows_phone'
29
30
 
31
+ autoload :Tablet, 'jpmobile/mobile/tablet'
32
+ autoload :AndroidTablet, 'jpmobile/mobile/android_tablet'
33
+ autoload :Ipad, 'jpmobile/mobile/ipad'
34
+
30
35
  autoload :Display, 'jpmobile/mobile/display'
31
36
 
32
- DEFAULT_CARRIERS = %w(Docomo Au Softbank Vodafone Emobile Willcom Ddipocket Iphone Android WindowsPhone)
37
+ DEFAULT_CARRIERS = %w(Docomo Au Softbank Vodafone Emobile Willcom Ddipocket Ipad AndroidTablet Iphone Android WindowsPhone)
33
38
 
34
39
  def self.carriers
35
40
  @carriers ||= DEFAULT_CARRIERS.dup
@@ -29,16 +29,6 @@ module Jpmobile::Mobile
29
29
  # 端末を識別する文字列があれば返す。
30
30
  def ident_device; nil; end
31
31
 
32
- # 当該キャリアのIPアドレス帯域からのアクセスであれば +true+ を返す。
33
- # そうでなければ +false+ を返す。
34
- # IP空間が定義されていない場合は +nil+ を返す。
35
- def self.valid_ip? remote_addr
36
- @ip_list ||= ip_address_class
37
- return false unless @ip_list
38
-
39
- @ip_list.valid_ip?(remote_addr)
40
- end
41
-
42
32
  def valid_ip?
43
33
  @__valid_ip ||= self.class.valid_ip? @request.ip
44
34
  end
@@ -60,6 +50,11 @@ module Jpmobile::Mobile
60
50
  false
61
51
  end
62
52
 
53
+ # tablet かどうか
54
+ def tablet?
55
+ false
56
+ end
57
+
63
58
  # Jpmobile::Rack::Filter を適用するかどうか
64
59
  def apply_filter?
65
60
  true
@@ -90,6 +85,7 @@ module Jpmobile::Mobile
90
85
  gsub(/Jpmobile::/, '').
91
86
  gsub(/AbstractMobile::/, '').
92
87
  gsub(/Mobile::SmartPhone/, 'smart_phone').
88
+ gsub(/Mobile::Tablet/, 'tablet').
93
89
  gsub(/::/, '_').
94
90
  gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
95
91
  gsub(/([a-z\d])([A-Z])/, '\1_\2').
@@ -97,8 +93,10 @@ module Jpmobile::Mobile
97
93
  klass =~ /abstract/ ? "mobile" : klass
98
94
  end
99
95
 
100
- if @_variants.include?("smart_phone")
101
- @_variants = @_variants.reject{|v| v == "mobile"}.map{|v| v.gsub(/mobile/, "smart_phone")}
96
+ if @_variants.include?('tablet')
97
+ @_variants = @_variants.reject{|v| v == "mobile"}.map{|v| v.gsub(/mobile_/, "tablet_")}
98
+ elsif @_variants.include?("smart_phone")
99
+ @_variants = @_variants.reject{|v| v == "mobile"}.map{|v| v.gsub(/mobile_/, "smart_phone_")}
102
100
  end
103
101
 
104
102
  @_variants || []
@@ -174,10 +172,47 @@ module Jpmobile::Mobile
174
172
  @decorated
175
173
  end
176
174
 
177
- # リクエストがこのクラスに属するか調べる
178
- # メソッド名に関して非常に不安
179
- def self.check_carrier(env)
180
- self::USER_AGENT_REGEXP && env['HTTP_USER_AGENT'] =~ self::USER_AGENT_REGEXP
175
+ class << self
176
+ # 当該キャリアのIPアドレス帯域からのアクセスであれば +true+ を返す。
177
+ # そうでなければ +false+ を返す。
178
+ # IP空間が定義されていない場合は +nil+ を返す。
179
+ def valid_ip? remote_addr
180
+ @ip_list ||= ip_address_class
181
+ return false unless @ip_list
182
+
183
+ @ip_list.valid_ip?(remote_addr)
184
+ end
185
+
186
+ # リクエストがこのクラスに属するか調べる
187
+ # メソッド名に関して非常に不安
188
+ def check_carrier(env)
189
+ user_agent_regexp && user_agent_regexp.match(env['HTTP_USER_AGENT'])
190
+ end
191
+
192
+ def user_agent_regexp
193
+ @_user_agent_regexp ||= self::USER_AGENT_REGEXP
194
+ end
195
+
196
+ def add_user_agent_regexp(regexp)
197
+ @_user_agent_regexp = Regexp.union(user_agent_regexp, regexp)
198
+ end
199
+
200
+ def carrier(env)
201
+ ::Jpmobile::Mobile.carriers.each do |const|
202
+ c = ::Jpmobile::Mobile.const_get(const)
203
+ if c.check_carrier(env)
204
+ res = ::Rack::Request.new(env)
205
+ return c.new(env, res)
206
+ end
207
+ end
208
+
209
+ nil
210
+ end
211
+
212
+ #
213
+ def ip_address_class
214
+ eval("::Jpmobile::Mobile::IpAddresses::#{self.to_s.split(/::/).last}").new rescue nil
215
+ end
181
216
  end
182
217
 
183
218
  #XXX: lib/jpmobile.rbのautoloadで先に各キャリアの定数を定義しているから動くのです
@@ -190,18 +225,6 @@ module Jpmobile::Mobile
190
225
  end
191
226
  end
192
227
 
193
- def self.carrier(env)
194
- ::Jpmobile::Mobile.carriers.each do |const|
195
- c = ::Jpmobile::Mobile.const_get(const)
196
- if c.check_carrier(env)
197
- res = ::Rack::Request.new(env)
198
- return c.new(env, res)
199
- end
200
- end
201
-
202
- nil
203
- end
204
-
205
228
  private
206
229
  # リクエストのパラメータ。
207
230
  def params
@@ -211,10 +234,5 @@ module Jpmobile::Mobile
211
234
  @request.params
212
235
  end
213
236
  end
214
-
215
- #
216
- def self.ip_address_class
217
- eval("::Jpmobile::Mobile::IpAddresses::#{self.to_s.split(/::/).last}").new rescue nil
218
- end
219
237
  end
220
238
  end
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ # =Android
3
+
4
+ module Jpmobile::Mobile
5
+ # ==AndroidTablet
6
+ class AndroidTablet < Tablet
7
+ # 対応するUser-Agentの正規表現
8
+ USER_AGENT_REGEXP = Regexp.union(/(?!Android.+Mobile)Android/, /Android.+SC-01C/)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ # =Android
3
+
4
+ module Jpmobile::Mobile
5
+ # ==iPad
6
+ class Ipad < Tablet
7
+ # 対応するUser-Agentの正規表現
8
+ USER_AGENT_REGEXP = /iPad/
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+ # =タブレットの親クラス
3
+
4
+ module Jpmobile::Mobile
5
+ class Tablet < SmartPhone
6
+ # smartphone なので true
7
+ def smart_phone?
8
+ true
9
+ end
10
+
11
+ # tablet なので true
12
+ def tablet?
13
+ true
14
+ end
15
+ end
16
+ end
@@ -19,8 +19,11 @@ describe Jpmobile::Rack::MobileCarrier do
19
19
  [ Jpmobile::Mobile::Iphone , 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; ja-jp) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16' ],
20
20
  [ Jpmobile::Mobile::Android , 'Mozilla/5.0 (Linux; U; Android 1.6; ja-jp; SonyEriccsonSO-01B Build/R1EA018) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' ],
21
21
  [ Jpmobile::Mobile::WindowsPhone , 'Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.1 T-01A_6.5; Windows Phone 6.5)' ],
22
+ [ Jpmobile::Mobile::Ipad , 'Mozilla/5.0 (iPad; U; CPU OS 4_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F191 Safari/6533.18.5'],
23
+ [ Jpmobile::Mobile::AndroidTablet, 'Mozilla/5.0 (Linux; U; Android 2.2; ja-jp; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'],
24
+ [ Jpmobile::Mobile::AndroidTablet, 'Mozilla/5.0 (Linux; U; Android 3.2; ja-jp; Sony Tablet S Build/THMAS11002) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'],
22
25
  ].each do |carrier, user_agent|
23
- it '#mobile should return #{carrier} when take #{user_agent} as UserAgent' do
26
+ it "#mobile should return #{carrier} when take #{user_agent} as UserAgent" do
24
27
  res = Rack::MockRequest.env_for(
25
28
  'http://jpmobile-rails.org/',
26
29
  'HTTP_USER_AGENT' => user_agent)
@@ -16,5 +16,14 @@ class TemplatePathController < ApplicationController
16
16
 
17
17
  def full_path_partial
18
18
  end
19
+
20
+ def smart_phone_only
21
+ end
22
+
23
+ def with_tblt
24
+ end
25
+
26
+ def with_ipd
27
+ end
19
28
  end
20
29
 
@@ -0,0 +1 @@
1
+ <h1>smart_phone_only.html.erb</h1>
@@ -0,0 +1 @@
1
+ <h1>smart_phone_only_smart_phone.html.erb</h1>
@@ -0,0 +1 @@
1
+ <h1>with_ipd.html.erb</h1>
@@ -0,0 +1 @@
1
+ <h1>with_ipd_tablet_ipad.html.erb</h1>
@@ -0,0 +1 @@
1
+ <h1>with_tblt.html.erb</h1>
@@ -0,0 +1 @@
1
+ <h1>with_tblt_tablet.html.erb</h1>
@@ -169,6 +169,78 @@ describe TemplatePathController, "integrated_views" do
169
169
  end
170
170
  end
171
171
 
172
+ context 'only smart_phone view' do
173
+ context 'iPadからのアクセスの場合' do
174
+ before do
175
+ @user_agent = 'Mozilla/5.0 (iPad; U; CPU OS 4_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F191 Safari/6533.18.5'
176
+ end
177
+ it 'smart_phone_only.html.erbが使用されること' do
178
+ get '/template_path/smart_phone_only', {}, {'HTTP_USER_AGENT' => @user_agent}
179
+
180
+ response.should have_tag('h1', :content => 'smart_phone_only_smart_phone.html.erb')
181
+ end
182
+ end
183
+
184
+ context 'Android Tabletからのアクセスの場合' do
185
+ before do
186
+ @user_agent = 'Mozilla/5.0 (Linux; U; Android 2.2; ja-jp; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
187
+ end
188
+ it 'smart_phone_only.html.erbが使用されること' do
189
+ get '/template_path/smart_phone_only', {}, {'HTTP_USER_AGENT' => @user_agent}
190
+
191
+ response.should have_tag('h1', :content => 'smart_phone_only_smart_phone.html.erb')
192
+ end
193
+ end
194
+ end
195
+
196
+ context 'with_tblt view' do
197
+ context 'iPadからのアクセスの場合' do
198
+ before do
199
+ @user_agent = 'Mozilla/5.0 (iPad; U; CPU OS 4_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F191 Safari/6533.18.5'
200
+ end
201
+ it 'with_tblt_tablet.html.erbが使用されること' do
202
+ get '/template_path/with_tblt', {}, {'HTTP_USER_AGENT' => @user_agent}
203
+
204
+ response.should have_tag('h1', :content => 'with_tblt_tablet.html.erb')
205
+ end
206
+ end
207
+
208
+ context 'Android Tabletからのアクセスの場合' do
209
+ before do
210
+ @user_agent = 'Mozilla/5.0 (Linux; U; Android 2.2; ja-jp; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
211
+ end
212
+ it 'with_tblt_tablet.html.erbが使用されること' do
213
+ get '/template_path/with_tblt', {}, {'HTTP_USER_AGENT' => @user_agent}
214
+
215
+ response.should have_tag('h1', :content => 'with_tblt_tablet.html.erb')
216
+ end
217
+ end
218
+ end
219
+
220
+ context 'with_ipd view' do
221
+ context 'iPadからのアクセスの場合' do
222
+ before do
223
+ @user_agent = 'Mozilla/5.0 (iPad; U; CPU OS 4_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F191 Safari/6533.18.5'
224
+ end
225
+ it 'with_ipd_tablet_ipad.html.erbが使用されること' do
226
+ get '/template_path/with_ipd', {}, {'HTTP_USER_AGENT' => @user_agent}
227
+
228
+ response.should have_tag('h1', :content => 'with_ipd_tablet_ipad.html.erb')
229
+ end
230
+ end
231
+
232
+ context 'Android Tabletからのアクセスの場合' do
233
+ before do
234
+ @user_agent = 'Mozilla/5.0 (Linux; U; Android 2.2; ja-jp; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
235
+ end
236
+ it 'with_ipd.html.erbが使用されること' do
237
+ get '/template_path/with_ipd', {}, {'HTTP_USER_AGENT' => @user_agent}
238
+
239
+ response.should have_tag('h1', :content => 'with_ipd.html.erb')
240
+ end
241
+ end
242
+ end
243
+
172
244
  context "partial" do
173
245
  context "PCからのアクセスの場合" do
174
246
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpmobile
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-20 00:00:00.000000000 Z
13
+ date: 2012-05-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jeweler
@@ -325,13 +325,16 @@ files:
325
325
  - lib/jpmobile/mailer.rb
326
326
  - lib/jpmobile/mobile/abstract_mobile.rb
327
327
  - lib/jpmobile/mobile/android.rb
328
+ - lib/jpmobile/mobile/android_tablet.rb
328
329
  - lib/jpmobile/mobile/au.rb
329
330
  - lib/jpmobile/mobile/ddipocket.rb
330
331
  - lib/jpmobile/mobile/docomo.rb
331
332
  - lib/jpmobile/mobile/emobile.rb
333
+ - lib/jpmobile/mobile/ipad.rb
332
334
  - lib/jpmobile/mobile/iphone.rb
333
335
  - lib/jpmobile/mobile/smart_phone.rb
334
336
  - lib/jpmobile/mobile/softbank.rb
337
+ - lib/jpmobile/mobile/tablet.rb
335
338
  - lib/jpmobile/mobile/vodafone.rb
336
339
  - lib/jpmobile/mobile/willcom.rb
337
340
  - lib/jpmobile/mobile/windows_phone.rb
@@ -461,6 +464,12 @@ files:
461
464
  - test/rails/overrides/app/views/template_path/partial.html.erb
462
465
  - test/rails/overrides/app/views/template_path/show_mobile.html.erb
463
466
  - test/rails/overrides/app/views/template_path/show_mobile_docomo.html.erb
467
+ - test/rails/overrides/app/views/template_path/smart_phone_only.html.erb
468
+ - test/rails/overrides/app/views/template_path/smart_phone_only_smart_phone.html.erb
469
+ - test/rails/overrides/app/views/template_path/with_ipd.html.erb
470
+ - test/rails/overrides/app/views/template_path/with_ipd_tablet_ipad.html.erb
471
+ - test/rails/overrides/app/views/template_path/with_tblt.html.erb
472
+ - test/rails/overrides/app/views/template_path/with_tblt_tablet.html.erb
464
473
  - test/rails/overrides/autotest/discover.rb
465
474
  - test/rails/overrides/config/initializers/jpmobile_generator.rb
466
475
  - test/rails/overrides/config/routes.rb
@@ -531,7 +540,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
531
540
  version: '0'
532
541
  requirements: []
533
542
  rubyforge_project:
534
- rubygems_version: 1.8.21
543
+ rubygems_version: 1.8.24
535
544
  signing_key:
536
545
  specification_version: 3
537
546
  summary: A Rails plugin for Japanese mobile-phones