jpmobile 6.0.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +8 -3
- data/.onkcop-config.yml +4 -31
- data/.rubocop.yml +67 -3
- data/.ruby-version +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +152 -158
- data/README.md +5 -20
- data/jpmobile.gemspec +6 -3
- data/lib/jpmobile/configuration.rb +7 -3
- data/lib/jpmobile/docomo_guid.rb +4 -4
- data/lib/jpmobile/email.rb +2 -4
- data/lib/jpmobile/emoticon.rb +10 -17
- data/lib/jpmobile/filter.rb +2 -2
- data/lib/jpmobile/hook_action_view.rb +3 -3
- data/lib/jpmobile/hook_template_details_requested.rb +12 -0
- data/lib/jpmobile/hook_test_request.rb +1 -1
- data/lib/jpmobile/mail.rb +4 -4
- data/lib/jpmobile/mailer.rb +2 -2
- data/lib/jpmobile/mobile/abstract_mobile.rb +1 -1
- data/lib/jpmobile/mobile/android.rb +1 -1
- data/lib/jpmobile/mobile/android_tablet.rb +1 -1
- data/lib/jpmobile/mobile/au.rb +2 -2
- data/lib/jpmobile/mobile/black_berry.rb +1 -1
- data/lib/jpmobile/mobile/ddipocket.rb +1 -1
- data/lib/jpmobile/mobile/docomo.rb +6 -8
- data/lib/jpmobile/mobile/emobile.rb +2 -2
- data/lib/jpmobile/mobile/ipad.rb +1 -1
- data/lib/jpmobile/mobile/iphone.rb +1 -1
- data/lib/jpmobile/mobile/softbank.rb +2 -2
- data/lib/jpmobile/mobile/vodafone.rb +2 -2
- data/lib/jpmobile/mobile/willcom.rb +2 -2
- data/lib/jpmobile/mobile/windows_phone.rb +1 -1
- data/lib/jpmobile/path_set.rb +10 -36
- data/lib/jpmobile/rack/params_filter.rb +5 -4
- data/lib/jpmobile/rails.rb +9 -41
- data/lib/jpmobile/resolver.rb +44 -6
- data/lib/jpmobile/session/active_record_store.rb +1 -1
- data/lib/jpmobile/session/mem_cache_store.rb +1 -1
- data/lib/jpmobile/template_details.rb +38 -0
- data/lib/jpmobile/trans_sid.rb +2 -2
- data/lib/jpmobile/util.rb +3 -4
- data/lib/jpmobile/version.rb +1 -1
- data/lib/jpmobile/view_selector.rb +25 -0
- data/lib/jpmobile.rb +14 -0
- data/lib/tasks/jpmobile_tasks.rake +4 -3
- data/spec/rack/jpmobile/emoticon_spec.rb +48 -48
- data/spec/rack/jpmobile/mobile_by_ua_spec.rb +1 -0
- data/spec/rack_helper.rb +1 -5
- data/spec/unit/email_spec.rb +1 -1
- data/spec/unit/receive_mail_spec.rb +1 -1
- data/test/rails/overrides/Gemfile.jpmobile +5 -1
- data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/template_path_controller.rb +3 -0
- data/test/rails/overrides/app/views/mobile_spec/mobile_not_exist.html.erb +3 -0
- data/test/rails/overrides/config/routes.rb +1 -1
- data/test/rails/overrides/db/migrate/{20190419005447_create_active_storage_tables.active_storage.rb → 20201111033056_create_active_storage_tables.active_storage.rb} +14 -5
- data/test/rails/overrides/db/migrate/{20190419005448_create_action_mailbox_tables.action_mailbox.rb → 20201111033057_create_action_mailbox_tables.action_mailbox.rb} +0 -0
- data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +2 -2
- data/test/rails/overrides/spec/controllers/mobile_spec_controller_spec.rb +3 -3
- data/test/rails/overrides/spec/rails_helper.rb +1 -1
- data/test/rails/overrides/spec/requests/filter_spec.rb +106 -0
- data/test/rails/overrides/spec/requests/template_path_spec.rb +1 -1
- data/test/rails/overrides/spec/requests/trans_sid_spec.rb +9 -9
- data/test/rails/overrides/spec/{features → system}/admin/top_spec.rb +2 -2
- data/test/rails/overrides/spec/{features → system}/filter_spec.rb +2 -7
- data/test/rails/overrides/spec/system/support/cuprite_setup.rb +14 -0
- data/test/rails/overrides/spec/system_helper.rb +3 -0
- metadata +44 -21
- data/test/rails/overrides/app/views/mobile_spec/no_mobile.html.erb +0 -3
data/jpmobile.gemspec
CHANGED
@@ -13,16 +13,19 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.license = 'MIT'
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
16
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|system)/})
|
17
17
|
gem.require_paths = ['lib']
|
18
18
|
|
19
|
+
gem.required_ruby_version = '>= 3.0.0'
|
20
|
+
|
19
21
|
gem.add_dependency 'mail', '~> 2.7.0'
|
20
|
-
gem.
|
22
|
+
gem.add_dependency 'rexml'
|
23
|
+
gem.add_dependency 'scanf'
|
21
24
|
gem.add_development_dependency 'geokit'
|
22
25
|
gem.add_development_dependency 'git'
|
23
26
|
gem.add_development_dependency 'hpricot'
|
24
27
|
gem.add_development_dependency 'pry'
|
25
|
-
gem.add_development_dependency 'rails', '~>
|
28
|
+
gem.add_development_dependency 'rails', '~> 7.0.0.alpha2'
|
26
29
|
gem.add_development_dependency 'rspec'
|
27
30
|
gem.add_development_dependency 'rspec-its'
|
28
31
|
gem.add_development_dependency 'rspec-rails'
|
@@ -2,9 +2,7 @@ module Jpmobile
|
|
2
2
|
class Configuration
|
3
3
|
include Singleton
|
4
4
|
|
5
|
-
attr_accessor :form_accept_charset_conversion
|
6
|
-
attr_accessor :smart_phone_emoticon_compatibility
|
7
|
-
attr_accessor :fallback_view_selector
|
5
|
+
attr_accessor :form_accept_charset_conversion, :smart_phone_emoticon_compatibility, :fallback_view_selector
|
8
6
|
|
9
7
|
def initialize
|
10
8
|
@form_accept_charset_conversion = false
|
@@ -23,5 +21,11 @@ module Jpmobile
|
|
23
21
|
def mount_session_store
|
24
22
|
@session_store && @session_store.call
|
25
23
|
end
|
24
|
+
|
25
|
+
module RailsConfiguration
|
26
|
+
def jpmobile
|
27
|
+
@jpmobile ||= ::Jpmobile.config
|
28
|
+
end
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
data/lib/jpmobile/docomo_guid.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# DoCoMoの時guid=onの付与
|
2
|
-
class ActionController::Base
|
2
|
+
class ActionController::Base # :nodoc:
|
3
3
|
class_attribute :docomo_guid_mode
|
4
4
|
|
5
5
|
class << self
|
@@ -10,7 +10,7 @@ class ActionController::Base #:nodoc:
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
module Jpmobile::DocomoGuid
|
13
|
+
module Jpmobile::DocomoGuid # :nodoc:
|
14
14
|
protected
|
15
15
|
|
16
16
|
def default_url_options
|
@@ -30,8 +30,8 @@ module Jpmobile::DocomoGuid #:nodoc:
|
|
30
30
|
return false unless request.mobile.is_a?(Jpmobile::Mobile::Docomo)
|
31
31
|
return false if not_apply_guid_user_agent?
|
32
32
|
|
33
|
-
if docomo_guid_mode == :valid_ip
|
34
|
-
return false
|
33
|
+
if docomo_guid_mode == :valid_ip && !request.mobile.valid_ip?
|
34
|
+
return false
|
35
35
|
end
|
36
36
|
|
37
37
|
true
|
data/lib/jpmobile/email.rb
CHANGED
@@ -20,7 +20,7 @@ module Jpmobile
|
|
20
20
|
Mobile.carriers.each do |const|
|
21
21
|
c = Mobile.const_get(const)
|
22
22
|
if c::MAIL_ADDRESS_REGEXP &&
|
23
|
-
header.match(/(\S+@[A-Za-z0-9
|
23
|
+
header.match(/(\S+@[A-Za-z0-9\-._]+)/) &&
|
24
24
|
Regexp.last_match(1).match(/^#{c::MAIL_ADDRESS_REGEXP}$/)
|
25
25
|
return c
|
26
26
|
end
|
@@ -33,14 +33,12 @@ module Jpmobile
|
|
33
33
|
nil
|
34
34
|
end
|
35
35
|
|
36
|
-
attr_writer :japanese_mail_address_regexp
|
36
|
+
attr_writer :japanese_mail_address_regexp, :converting_content_type
|
37
37
|
|
38
38
|
def japanese_mail?(header)
|
39
39
|
@japanese_mail_address_regexp and header.match(@japanese_mail_address_regexp)
|
40
40
|
end
|
41
41
|
|
42
|
-
attr_writer :converting_content_type
|
43
|
-
|
44
42
|
def converting_content_type
|
45
43
|
@converting_content_type ||= ['text/plain', 'text/html']
|
46
44
|
end
|
data/lib/jpmobile/emoticon.rb
CHANGED
@@ -96,20 +96,15 @@ module Jpmobile
|
|
96
96
|
unicodes = match.unpack('U*')
|
97
97
|
unicodes = unicodes.first if unicodes.size == 1
|
98
98
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
when GETA_CODE
|
104
|
-
GETA
|
105
|
-
when Integer
|
106
|
-
'&#x%04x;' % emoticon
|
107
|
-
when String
|
108
|
-
emoticon
|
109
|
-
end
|
110
|
-
else
|
111
|
-
# 変換できなければ〓に
|
99
|
+
emoticon = UNICODE_EMOTICON_TO_CARRIER_EMOTICON[unicodes]
|
100
|
+
case emoticon
|
101
|
+
when GETA_CODE, nil
|
102
|
+
# 〓が指定されているか変換できなければ〓に
|
112
103
|
GETA
|
104
|
+
when Integer
|
105
|
+
'&#x%04x;' % emoticon
|
106
|
+
when String
|
107
|
+
emoticon
|
113
108
|
end
|
114
109
|
end
|
115
110
|
end
|
@@ -122,15 +117,13 @@ module Jpmobile
|
|
122
117
|
|
123
118
|
emoticon = GOOGLE_EMOTICON_TO_CARRIER_EMOTICON[unicodes]
|
124
119
|
case emoticon
|
125
|
-
when GETA_CODE
|
120
|
+
when GETA_CODE, nil
|
121
|
+
# 〓が指定されているか変換できなければ〓に
|
126
122
|
GETA
|
127
123
|
when Integer
|
128
124
|
'&#x%04x;' % emoticon
|
129
125
|
when String
|
130
126
|
emoticon
|
131
|
-
else
|
132
|
-
# 変換できなければ〓に
|
133
|
-
GETA
|
134
127
|
end
|
135
128
|
end
|
136
129
|
end
|
data/lib/jpmobile/filter.rb
CHANGED
@@ -54,8 +54,8 @@ module Jpmobile
|
|
54
54
|
private
|
55
55
|
|
56
56
|
def replace_chars(str, table)
|
57
|
-
@regexp_cache ||= {}
|
58
|
-
str.gsub(@regexp_cache[table
|
57
|
+
@regexp_cache ||= {}.compare_by_identity
|
58
|
+
str.gsub(@regexp_cache[table] ||= Regexp.union(table.keys), table)
|
59
59
|
end
|
60
60
|
|
61
61
|
def han_to_zen_table
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# :stopdoc:
|
2
2
|
# helperを追加
|
3
3
|
# ActionView で trans_sid を有効にする
|
4
4
|
ActionView::Base.class_eval do
|
@@ -6,7 +6,7 @@ ActionView::Base.class_eval do
|
|
6
6
|
|
7
7
|
delegate :default_url_options, to: :controller unless respond_to?(:default_url_options)
|
8
8
|
end
|
9
|
-
|
9
|
+
# :startdoc:
|
10
10
|
|
11
11
|
# :stopdoc:
|
12
12
|
# accept-charset に charset を変更できるようにする
|
@@ -19,4 +19,4 @@ module Jpmobile
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
# :startdoc:
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Jpmobile
|
2
|
+
module HookTemplateDetailsRequested
|
3
|
+
attr_reader :mobile, :mobile_idx
|
4
|
+
|
5
|
+
def initialize(locale:, handlers:, formats:, variants:, mobile:)
|
6
|
+
super(locale: locale, handlers: handlers, formats: formats, variants: variants)
|
7
|
+
|
8
|
+
@mobile = mobile.map(&:to_sym)
|
9
|
+
@mobile_idx = build_idx_hash(@mobile)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'action_controller/test_case'
|
2
|
-
ActionController::TestRequest.
|
2
|
+
ActionController::TestRequest.include Jpmobile::RequestWithMobileTesting
|
data/lib/jpmobile/mail.rb
CHANGED
@@ -456,17 +456,17 @@ module Mail
|
|
456
456
|
|
457
457
|
def decoded_with_jpmobile
|
458
458
|
if @mobile
|
459
|
-
return value unless value =~
|
459
|
+
return value unless value =~ /=\?[^?]+\?([QB])\?[^?]*?\?=/mi
|
460
460
|
|
461
461
|
Encodings.collapse_adjacent_encodings(value).each {|line|
|
462
|
-
line.gsub!(
|
462
|
+
line.gsub!(/=\?[^?]+\?([QB])\?[^?]*?\?=/mi) do |string|
|
463
463
|
case Regexp.last_match(1)
|
464
464
|
when 'B', 'b' then decode_b_value_for_mobile(string)
|
465
465
|
when 'Q', 'q' then Encodings.q_value_decode(string)
|
466
466
|
else line
|
467
467
|
end
|
468
468
|
end
|
469
|
-
}.join
|
469
|
+
}.join
|
470
470
|
else
|
471
471
|
decoded_without_jpmobile
|
472
472
|
end
|
@@ -479,7 +479,7 @@ module Mail
|
|
479
479
|
alias_method :decoded, :decoded_with_jpmobile
|
480
480
|
|
481
481
|
def decode_b_value_for_mobile(str)
|
482
|
-
match = str.match(
|
482
|
+
match = str.match(/=\?(.+)?\?[Bb]\?(.*)\?=/m)
|
483
483
|
if match
|
484
484
|
charset = match[1]
|
485
485
|
str = Ruby19.decode_base64(match[2])
|
data/lib/jpmobile/mailer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'jpmobile/mail'
|
2
2
|
require 'jpmobile/lookup_context'
|
3
3
|
|
4
|
-
Jpmobile::Email.japanese_mail_address_regexp = Regexp.new(/\.jp(?:[^a-zA-Z
|
4
|
+
Jpmobile::Email.japanese_mail_address_regexp = Regexp.new(/\.jp(?:[^a-zA-Z.\-]|$)/)
|
5
5
|
|
6
6
|
module Jpmobile
|
7
7
|
module Mailer
|
@@ -37,7 +37,7 @@ module Jpmobile
|
|
37
37
|
class << self
|
38
38
|
protected
|
39
39
|
|
40
|
-
def set_payload_for_mail(payload, mail)
|
40
|
+
def set_payload_for_mail(payload, mail) # :nodoc:
|
41
41
|
super
|
42
42
|
|
43
43
|
payload[:mail] = Jpmobile::Util.ascii_8bit(mail.encoded).gsub(/\r\n/, "\n")
|
@@ -6,6 +6,6 @@ module Jpmobile::Mobile
|
|
6
6
|
include Jpmobile::Mobile::GoogleEmoticon
|
7
7
|
|
8
8
|
# 対応するUser-Agentの正規表現
|
9
|
-
USER_AGENT_REGEXP = Regexp.union(
|
9
|
+
USER_AGENT_REGEXP = Regexp.union(/^(?!.+Mobile).+(?=Android).+$/, /Android.+SC-01C/)
|
10
10
|
end
|
11
11
|
end
|
data/lib/jpmobile/mobile/au.rb
CHANGED
@@ -6,9 +6,9 @@ module Jpmobile::Mobile
|
|
6
6
|
class Au < AbstractMobile
|
7
7
|
# 対応するUser-Agentの正規表現
|
8
8
|
# User-Agent文字列中に "UP.Browser" を含むVodafoneの端末があるので注意が必要
|
9
|
-
USER_AGENT_REGEXP = %r{^(?:KDDI|UP.Browser/.+?)-(.+?) }
|
9
|
+
USER_AGENT_REGEXP = %r{^(?:KDDI|UP.Browser/.+?)-(.+?) }
|
10
10
|
# 対応するメールアドレスの正規表現
|
11
|
-
MAIL_ADDRESS_REGEXP = /.+@ezweb\.ne\.jp
|
11
|
+
MAIL_ADDRESS_REGEXP = /.+@ezweb\.ne\.jp/
|
12
12
|
# 簡易位置情報取得に対応していないデバイスID
|
13
13
|
# http://www.au.kddi.com/ezfactory/tec/spec/eznavi.html
|
14
14
|
LOCATION_UNSUPPORTED_DEVICE_ID = %w[PT21 TS25 KCTE TST9 KCU1 SYT5 KCTD TST8 TST7 KCTC SYT4 KCTB KCTA TST6 KCT9 TST5 TST4 KCT8 SYT3 KCT7 MIT1 MAT3 KCT6 TST3 KCT5 KCT4 SYT2 MAT1 MAT2 TST2 KCT3 KCT2 KCT1 TST1 SYT1].freeze
|
@@ -4,7 +4,7 @@ module Jpmobile::Mobile
|
|
4
4
|
# スーパクラスはWillcom。
|
5
5
|
class Ddipocket < Willcom
|
6
6
|
# 対応するUser-Agentの正規表現
|
7
|
-
USER_AGENT_REGEXP = %r{^Mozilla/3.0\(DDIPOCKET}
|
7
|
+
USER_AGENT_REGEXP = %r{^Mozilla/3.0\(DDIPOCKET}
|
8
8
|
|
9
9
|
MAIL_ADDRESS_REGEXP = nil # DdipocketはEmail判定だとWillcomと判定させたい
|
10
10
|
end
|
@@ -4,9 +4,9 @@ module Jpmobile::Mobile
|
|
4
4
|
# ==DoCoMo携帯電話
|
5
5
|
class Docomo < AbstractMobile
|
6
6
|
# 対応するUser-Agentの正規表現
|
7
|
-
USER_AGENT_REGEXP = /^DoCoMo
|
7
|
+
USER_AGENT_REGEXP = /^DoCoMo/
|
8
8
|
# 対応するメールアドレスの正規表現
|
9
|
-
MAIL_ADDRESS_REGEXP = /.+@docomo\.ne\.jp
|
9
|
+
MAIL_ADDRESS_REGEXP = /.+@docomo\.ne\.jp/
|
10
10
|
# メールのデフォルトのcharset
|
11
11
|
MAIL_CHARSET = 'Shift_JIS'.freeze
|
12
12
|
# テキスト部分の content-transfer-encoding
|
@@ -44,9 +44,8 @@ module Jpmobile::Mobile
|
|
44
44
|
# 端末製造番号があれば返す。無ければ +nil+ を返す。
|
45
45
|
def serial_number
|
46
46
|
case @env['HTTP_USER_AGENT']
|
47
|
-
when /ser([0-9a-zA-Z]{11})
|
48
|
-
|
49
|
-
when /ser([0-9a-zA-Z]{15});/ # FOMA
|
47
|
+
when /ser([0-9a-zA-Z]{11})$/, # mova
|
48
|
+
/ser([0-9a-zA-Z]{15});/ # FOMA
|
50
49
|
Regexp.last_match(1)
|
51
50
|
else
|
52
51
|
nil
|
@@ -160,9 +159,8 @@ module Jpmobile::Mobile
|
|
160
159
|
# モデル名を返す。
|
161
160
|
def model_name
|
162
161
|
case @env['HTTP_USER_AGENT']
|
163
|
-
when %r{^DoCoMo/2.0 (.+)\(}
|
164
|
-
|
165
|
-
when %r{^DoCoMo/1.0/(.+?)/}
|
162
|
+
when %r{^DoCoMo/2.0 (.+)\(},
|
163
|
+
%r{^DoCoMo/1.0/(.+?)/}
|
166
164
|
Regexp.last_match(1)
|
167
165
|
else
|
168
166
|
nil
|
@@ -3,9 +3,9 @@
|
|
3
3
|
module Jpmobile::Mobile
|
4
4
|
# ==EMOBILE携帯電話
|
5
5
|
class Emobile < AbstractMobile
|
6
|
-
USER_AGENT_REGEXP = %r{^emobile/|^Mozilla/5.0 \(H11T; like Gecko; OpenBrowser\) NetFront/3.4$|^Mozilla/4.0 \(compatible; MSIE 6.0; Windows CE; IEMobile 7.7\) S11HT$}
|
6
|
+
USER_AGENT_REGEXP = %r{^emobile/|^Mozilla/5.0 \(H11T; like Gecko; OpenBrowser\) NetFront/3.4$|^Mozilla/4.0 \(compatible; MSIE 6.0; Windows CE; IEMobile 7.7\) S11HT$}
|
7
7
|
# 対応するメールアドレスの正規表現
|
8
|
-
MAIL_ADDRESS_REGEXP = /.+@emnet\.ne\.jp
|
8
|
+
MAIL_ADDRESS_REGEXP = /.+@emnet\.ne\.jp/
|
9
9
|
# EMnet対応端末から通知されるユニークなユーザIDを取得する。
|
10
10
|
def em_uid
|
11
11
|
@request.env['HTTP_X_EM_UID']
|
data/lib/jpmobile/mobile/ipad.rb
CHANGED
@@ -5,9 +5,9 @@ module Jpmobile::Mobile
|
|
5
5
|
# Vodafoneのスーパクラス。
|
6
6
|
class Softbank < AbstractMobile
|
7
7
|
# 対応するuser-agentの正規表現
|
8
|
-
USER_AGENT_REGEXP = /^(?:SoftBank|Semulator)
|
8
|
+
USER_AGENT_REGEXP = /^(?:SoftBank|Semulator)/
|
9
9
|
# 対応するメールアドレスの正規表現 ディズニーモバイル対応
|
10
|
-
MAIL_ADDRESS_REGEXP = /.+@(?:softbank\.ne\.jp|disney\.ne\.jp)
|
10
|
+
MAIL_ADDRESS_REGEXP = /.+@(?:softbank\.ne\.jp|disney\.ne\.jp)/
|
11
11
|
# メールのデフォルトのcharset
|
12
12
|
MAIL_CHARSET = 'Shift_JIS'.freeze
|
13
13
|
# テキスト部分の content-transfer-encoding
|
@@ -4,9 +4,9 @@ module Jpmobile::Mobile
|
|
4
4
|
# スーパクラスはSoftbank。
|
5
5
|
class Vodafone < Softbank
|
6
6
|
# 対応するUser-Agentの正規表現
|
7
|
-
USER_AGENT_REGEXP = /^(Vodafone|Vemulator)
|
7
|
+
USER_AGENT_REGEXP = /^(Vodafone|Vemulator)/
|
8
8
|
# 対応するメールアドレスの正規表現
|
9
|
-
MAIL_ADDRESS_REGEXP = /.+@[dhtcrknsq]\.vodafone\.ne\.jp
|
9
|
+
MAIL_ADDRESS_REGEXP = /.+@[dhtcrknsq]\.vodafone\.ne\.jp/
|
10
10
|
|
11
11
|
# cookieに対応しているか?
|
12
12
|
def supports_cookie?
|
@@ -4,9 +4,9 @@ module Jpmobile::Mobile
|
|
4
4
|
# Ddipocketのスーパクラス。
|
5
5
|
class Willcom < AbstractMobile
|
6
6
|
# 対応するUser-Agentの正規表現
|
7
|
-
USER_AGENT_REGEXP = %r{^Mozilla/3.0\(WILLCOM}
|
7
|
+
USER_AGENT_REGEXP = %r{^Mozilla/3.0\(WILLCOM}
|
8
8
|
# 対応するメールアドレスの正規表現
|
9
|
-
MAIL_ADDRESS_REGEXP = /.+@((.+\.)?pdx\.ne\.jp|willcom\.com)
|
9
|
+
MAIL_ADDRESS_REGEXP = /.+@((.+\.)?pdx\.ne\.jp|willcom\.com)/
|
10
10
|
|
11
11
|
# 位置情報があれば Position のインスタンスを返す。無ければ +nil+ を返す。
|
12
12
|
def position
|
data/lib/jpmobile/path_set.rb
CHANGED
@@ -1,41 +1,15 @@
|
|
1
1
|
module Jpmobile
|
2
|
-
class PathSet <
|
3
|
-
|
4
|
-
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
5
|
-
def #{method}(*args)
|
6
|
-
super
|
7
|
-
typecast!
|
8
|
-
end
|
9
|
-
METHOD
|
10
|
-
end
|
2
|
+
class PathSet < ActionView::PathSet
|
3
|
+
private
|
11
4
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
each do |resolver|
|
21
|
-
templates = resolver.find_all(*args)
|
22
|
-
return templates unless templates.empty?
|
23
|
-
end
|
24
|
-
[]
|
25
|
-
end
|
26
|
-
|
27
|
-
def exists?(*args)
|
28
|
-
find_all(*args).any?
|
29
|
-
end
|
30
|
-
|
31
|
-
protected
|
32
|
-
|
33
|
-
def typecast!
|
34
|
-
each_with_index do |path, i|
|
35
|
-
path = path.to_s if path.is_a?(Pathname)
|
36
|
-
next unless path.is_a?(String)
|
37
|
-
|
38
|
-
self[i] = Jpmobile::Resolver.new(path)
|
5
|
+
def typecast(paths)
|
6
|
+
paths.map do |path|
|
7
|
+
case path
|
8
|
+
when Pathname, String
|
9
|
+
Jpmobile::Resolver.new path.to_s
|
10
|
+
else
|
11
|
+
super(paths)
|
12
|
+
end
|
39
13
|
end
|
40
14
|
end
|
41
15
|
end
|
@@ -10,10 +10,11 @@ module Jpmobile
|
|
10
10
|
if (mobile = env['rack.jpmobile']) && mobile.apply_params_filter?
|
11
11
|
# パラメータをkey, valueに分解
|
12
12
|
# form_params
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
if env['REQUEST_METHOD'] != 'GET' &&
|
14
|
+
env['REQUEST_METHOD'] != 'HEAD' &&
|
15
|
+
!env['CONTENT_TYPE'].match?(%r{application/json|application/xml})
|
16
|
+
|
17
|
+
env['rack.input'] = StringIO.new(parse_query(env['rack.input'].read, mobile))
|
17
18
|
end
|
18
19
|
|
19
20
|
# query_params
|
data/lib/jpmobile/rails.rb
CHANGED
@@ -4,26 +4,28 @@ ActiveSupport.on_load(:action_controller) do
|
|
4
4
|
require 'jpmobile/helpers'
|
5
5
|
require 'jpmobile/trans_sid'
|
6
6
|
require 'jpmobile/hook_test_request'
|
7
|
-
ActionDispatch::Request.
|
8
|
-
ActionDispatch::Request.
|
9
|
-
ActionController::Base.
|
10
|
-
ActionController::Base.
|
7
|
+
ActionDispatch::Request.prepend Jpmobile::Encoding
|
8
|
+
ActionDispatch::Request.include Jpmobile::RequestWithMobile
|
9
|
+
ActionController::Base.prepend Jpmobile::FallbackViewSelector
|
10
|
+
ActionController::Base.prepend Jpmobile::TransSidRedirecting
|
11
11
|
end
|
12
12
|
|
13
13
|
ActiveSupport.on_load(:action_view) do
|
14
14
|
require 'jpmobile/hook_action_view'
|
15
|
+
require 'jpmobile/hook_template_details_requested'
|
15
16
|
|
16
17
|
self.prepend Jpmobile::HtmlOptionsWithAcceptCharset
|
18
|
+
ActionView::TemplateDetails::Requested.prepend Jpmobile::HookTemplateDetailsRequested
|
17
19
|
end
|
18
20
|
|
19
21
|
ActiveSupport.on_load(:after_initialize) do
|
20
22
|
case Rails.application.config.session_store.to_s
|
21
23
|
when 'ActionDispatch::Session::MemCacheStore'
|
22
24
|
require 'jpmobile/session/mem_cache_store'
|
23
|
-
ActionDispatch::Session::MemCacheStore.
|
25
|
+
ActionDispatch::Session::MemCacheStore.prepend Jpmobile::ParamsOverCookie
|
24
26
|
when 'ActionDispatch::Session::ActiveRecordStore'
|
25
27
|
require 'jpmobile/session/active_record_store'
|
26
|
-
ActionDispatch::Session::AbstractStore.
|
28
|
+
ActionDispatch::Session::AbstractStore.prepend Jpmobile::ParamsOverCookie
|
27
29
|
else
|
28
30
|
Rails.application.config.jpmobile.mount_session_store
|
29
31
|
end
|
@@ -33,39 +35,5 @@ ActiveSupport.on_load(:before_configuration) do
|
|
33
35
|
# MobileCarrierのみデフォルトで有効
|
34
36
|
config.middleware.insert_after ActionDispatch::Flash, ::Jpmobile::MobileCarrier
|
35
37
|
|
36
|
-
|
37
|
-
class Application
|
38
|
-
class Configuration
|
39
|
-
def jpmobile
|
40
|
-
@jpmobile ||= ::Jpmobile.config
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
module Jpmobile
|
48
|
-
module ViewSelector
|
49
|
-
def self.included(base)
|
50
|
-
base.class_eval do
|
51
|
-
before_action :register_mobile
|
52
|
-
|
53
|
-
self._view_paths = self._view_paths.dup
|
54
|
-
self.view_paths.unshift(*self.view_paths.map {|resolver| Jpmobile::Resolver.new(resolver.to_path) })
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def register_mobile
|
59
|
-
if request.mobile
|
60
|
-
# register mobile
|
61
|
-
self.lookup_context.mobile = request.mobile.variants
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def disable_mobile_view!
|
66
|
-
self.lookup_context.mobile = []
|
67
|
-
end
|
68
|
-
|
69
|
-
private :register_mobile, :disable_mobile_view!
|
70
|
-
end
|
38
|
+
Rails::Application::Configuration.include Jpmobile::Configuration::RailsConfiguration
|
71
39
|
end
|
data/lib/jpmobile/resolver.rb
CHANGED
@@ -1,14 +1,52 @@
|
|
1
1
|
module Jpmobile
|
2
2
|
class Resolver < ::ActionView::FileSystemResolver
|
3
|
-
|
4
|
-
|
3
|
+
def initialize(path)
|
4
|
+
super(path)
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
@path_parser = Jpmobile::Resolver::PathParser.new
|
7
|
+
end
|
8
8
|
|
9
|
+
def clear_cache
|
9
10
|
super
|
10
|
-
|
11
|
-
@
|
11
|
+
|
12
|
+
@path_parser = Jpmobile::Resolver::PathParser.new
|
13
|
+
end
|
14
|
+
|
15
|
+
class PathParser < ::ActionView::Resolver::PathParser
|
16
|
+
def build_path_regex
|
17
|
+
handlers = ::ActionView::Template::Handlers.extensions.map {|x| Regexp.escape(x) }.join('|')
|
18
|
+
formats = ::ActionView::Template::Types.symbols.map {|x| Regexp.escape(x) }.join('|')
|
19
|
+
locales = '[a-z]{2}(?:-[A-Z]{2})?'
|
20
|
+
variants = '[^.]*'
|
21
|
+
mobile = Jpmobile::Mobile.all_variants.map {|x| Regexp.escape(x) }.join('|')
|
22
|
+
|
23
|
+
%r{
|
24
|
+
\A
|
25
|
+
(?:(?<prefix>.*)/)?
|
26
|
+
(?<partial>_)?
|
27
|
+
(?<action>.*?)
|
28
|
+
(?:_(?<mobile>#{mobile}))??
|
29
|
+
(?:\.(?<locale>#{locales}))??
|
30
|
+
(?:\.(?<format>#{formats}))??
|
31
|
+
(?:\+(?<variant>#{variants}))??
|
32
|
+
(?:\.(?<handler>#{handlers}))?
|
33
|
+
\z
|
34
|
+
}x
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse(path)
|
38
|
+
@regex ||= build_path_regex
|
39
|
+
match = @regex.match(path)
|
40
|
+
path = ActionView::TemplatePath.build(match[:action], match[:prefix] || '', !!match[:partial])
|
41
|
+
details = Jpmobile::TemplateDetails.new(
|
42
|
+
match[:locale]&.to_sym,
|
43
|
+
match[:handler]&.to_sym,
|
44
|
+
match[:format]&.to_sym,
|
45
|
+
match[:variant]&.to_sym,
|
46
|
+
match[:mobile]&.to_sym,
|
47
|
+
)
|
48
|
+
ParsedPath.new(path, details)
|
49
|
+
end
|
12
50
|
end
|
13
51
|
end
|
14
52
|
end
|