jpmobile 6.1.0 → 7.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +12 -4
  3. data/.onkcop-config.yml +0 -27
  4. data/.rubocop.yml +64 -1
  5. data/.ruby-version +1 -1
  6. data/Gemfile +4 -2
  7. data/Gemfile.lock +153 -141
  8. data/README.md +4 -20
  9. data/jpmobile.gemspec +5 -4
  10. data/lib/jpmobile/configuration.rb +7 -3
  11. data/lib/jpmobile/docomo_guid.rb +4 -4
  12. data/lib/jpmobile/email.rb +2 -4
  13. data/lib/jpmobile/emoticon.rb +10 -17
  14. data/lib/jpmobile/filter.rb +2 -2
  15. data/lib/jpmobile/hook_action_view.rb +3 -3
  16. data/lib/jpmobile/hook_template_details_requested.rb +12 -0
  17. data/lib/jpmobile/mail.rb +4 -4
  18. data/lib/jpmobile/mailer.rb +2 -2
  19. data/lib/jpmobile/mobile/abstract_mobile.rb +1 -1
  20. data/lib/jpmobile/mobile/android.rb +1 -1
  21. data/lib/jpmobile/mobile/android_tablet.rb +1 -1
  22. data/lib/jpmobile/mobile/au.rb +2 -2
  23. data/lib/jpmobile/mobile/black_berry.rb +1 -1
  24. data/lib/jpmobile/mobile/ddipocket.rb +1 -1
  25. data/lib/jpmobile/mobile/docomo.rb +6 -8
  26. data/lib/jpmobile/mobile/emobile.rb +2 -2
  27. data/lib/jpmobile/mobile/ipad.rb +1 -1
  28. data/lib/jpmobile/mobile/iphone.rb +1 -1
  29. data/lib/jpmobile/mobile/softbank.rb +2 -2
  30. data/lib/jpmobile/mobile/vodafone.rb +2 -2
  31. data/lib/jpmobile/mobile/willcom.rb +2 -2
  32. data/lib/jpmobile/mobile/windows_phone.rb +1 -1
  33. data/lib/jpmobile/path_set.rb +10 -36
  34. data/lib/jpmobile/rack/params_filter.rb +5 -4
  35. data/lib/jpmobile/rails.rb +3 -35
  36. data/lib/jpmobile/resolver.rb +44 -6
  37. data/lib/jpmobile/template_details.rb +38 -0
  38. data/lib/jpmobile/trans_sid.rb +1 -1
  39. data/lib/jpmobile/util.rb +3 -4
  40. data/lib/jpmobile/version.rb +1 -1
  41. data/lib/jpmobile/view_selector.rb +25 -0
  42. data/lib/jpmobile.rb +14 -0
  43. data/lib/tasks/jpmobile_tasks.rake +2 -1
  44. data/spec/rack/jpmobile/mobile_by_ua_spec.rb +1 -0
  45. data/spec/rack_helper.rb +0 -4
  46. data/spec/unit/email_spec.rb +1 -1
  47. data/spec/unit/receive_mail_spec.rb +1 -1
  48. data/test/rails/overrides/Gemfile.jpmobile +5 -1
  49. data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
  50. data/test/rails/overrides/app/controllers/template_path_controller.rb +3 -0
  51. data/test/rails/overrides/app/views/mobile_spec/mobile_not_exist.html.erb +3 -0
  52. data/test/rails/overrides/config/routes.rb +1 -1
  53. data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +2 -2
  54. data/test/rails/overrides/spec/controllers/mobile_spec_controller_spec.rb +3 -3
  55. data/test/rails/overrides/spec/rails_helper.rb +1 -1
  56. data/test/rails/overrides/spec/requests/filter_spec.rb +106 -0
  57. data/test/rails/overrides/spec/requests/template_path_spec.rb +1 -1
  58. data/test/rails/overrides/spec/requests/trans_sid_spec.rb +9 -9
  59. data/test/rails/overrides/spec/{features → system}/admin/top_spec.rb +2 -2
  60. data/test/rails/overrides/spec/{features → system}/filter_spec.rb +2 -7
  61. data/test/rails/overrides/spec/system/support/cuprite_setup.rb +14 -0
  62. data/test/rails/overrides/spec/system_helper.rb +3 -0
  63. metadata +26 -31
  64. data/test/rails/overrides/app/views/mobile_spec/no_mobile.html.erb +0 -3
data/jpmobile.gemspec CHANGED
@@ -13,18 +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|features)/})
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|system)/})
17
17
  gem.require_paths = ['lib']
18
18
 
19
+ gem.required_ruby_version = '>= 2.7.0'
20
+
19
21
  gem.add_dependency 'mail', '~> 2.7.0'
20
- gem.add_dependency 'scanf'
21
22
  gem.add_dependency 'rexml'
22
- gem.add_development_dependency 'capybara-webkit'
23
+ gem.add_dependency 'scanf'
23
24
  gem.add_development_dependency 'geokit'
24
25
  gem.add_development_dependency 'git'
25
26
  gem.add_development_dependency 'hpricot'
26
27
  gem.add_development_dependency 'pry'
27
- gem.add_development_dependency 'rails', '~> 6.1.0'
28
+ gem.add_development_dependency 'rails', '~> 7.0.0.alpha2'
28
29
  gem.add_development_dependency 'rspec'
29
30
  gem.add_development_dependency 'rspec-its'
30
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
@@ -1,5 +1,5 @@
1
1
  # DoCoMoの時guid=onの付与
2
- class ActionController::Base #:nodoc:
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 #:nodoc:
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 unless request.mobile.valid_ip?
33
+ if docomo_guid_mode == :valid_ip && !request.mobile.valid_ip?
34
+ return false
35
35
  end
36
36
 
37
37
  true
@@ -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
@@ -96,20 +96,15 @@ module Jpmobile
96
96
  unicodes = match.unpack('U*')
97
97
  unicodes = unicodes.first if unicodes.size == 1
98
98
 
99
- if (emoticon = UNICODE_EMOTICON_TO_CARRIER_EMOTICON[unicodes]) == GETA_CODE
100
- GETA
101
- elsif emoticon
102
- case emoticon
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
@@ -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.object_id] ||= Regexp.union(table.keys), 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
- #:stopdoc:
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
- #:startdoc:
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
- #:startdoc:
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
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 =~ /\=\?[^?]+\?([QB])\?[^?]*?\?\=/mi
459
+ return value unless value =~ /=\?[^?]+\?([QB])\?[^?]*?\?=/mi
460
460
 
461
461
  Encodings.collapse_adjacent_encodings(value).each {|line|
462
- line.gsub!(/\=\?[^?]+\?([QB])\?[^?]*?\?\=/mi) do |string|
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(/\=\?(.+)?\?[Bb]\?(.*)\?\=/m)
482
+ match = str.match(/=\?(.+)?\?[Bb]\?(.*)\?=/m)
483
483
  if match
484
484
  charset = match[1]
485
485
  str = Ruby19.decode_base64(match[2])
@@ -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) #:nodoc:
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")
@@ -177,7 +177,7 @@ module Jpmobile::Mobile
177
177
  end
178
178
 
179
179
  def to_mail_subject_encoded?(str)
180
- str.match(/\=\?#{mail_charset}\?B.+\?\=/i)
180
+ str.match(/=\?#{mail_charset}\?B.+\?=/i)
181
181
  end
182
182
 
183
183
  def to_mail_body_encoded?(str)
@@ -6,6 +6,6 @@ module Jpmobile::Mobile
6
6
  include Jpmobile::Mobile::GoogleEmoticon
7
7
 
8
8
  # 対応するUser-Agentの正規表現
9
- USER_AGENT_REGEXP = /Android/.freeze
9
+ USER_AGENT_REGEXP = /Android/
10
10
  end
11
11
  end
@@ -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(/(?!Android.+Mobile)Android/, /Android.+SC-01C/)
9
+ USER_AGENT_REGEXP = Regexp.union(/^(?!.+Mobile).+(?=Android).+$/, /Android.+SC-01C/)
10
10
  end
11
11
  end
@@ -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/.+?)-(.+?) }.freeze
9
+ USER_AGENT_REGEXP = %r{^(?:KDDI|UP.Browser/.+?)-(.+?) }
10
10
  # 対応するメールアドレスの正規表現
11
- MAIL_ADDRESS_REGEXP = /.+@ezweb\.ne\.jp/.freeze
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,6 +4,6 @@ module Jpmobile::Mobile
4
4
  # ==BlackBerry
5
5
  class BlackBerry < SmartPhone
6
6
  # 対応するUser-Agentの正規表現
7
- USER_AGENT_REGEXP = /BlackBerry/.freeze
7
+ USER_AGENT_REGEXP = /BlackBerry/
8
8
  end
9
9
  end
@@ -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}.freeze
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/.freeze
7
+ USER_AGENT_REGEXP = /^DoCoMo/
8
8
  # 対応するメールアドレスの正規表現
9
- MAIL_ADDRESS_REGEXP = /.+@docomo\.ne\.jp/.freeze
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})$/ # mova
48
- Regexp.last_match(1)
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
- Regexp.last_match(1)
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$}.freeze
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/.freeze
8
+ MAIL_ADDRESS_REGEXP = /.+@emnet\.ne\.jp/
9
9
  # EMnet対応端末から通知されるユニークなユーザIDを取得する。
10
10
  def em_uid
11
11
  @request.env['HTTP_X_EM_UID']
@@ -6,6 +6,6 @@ module Jpmobile::Mobile
6
6
  include Jpmobile::Mobile::UnicodeEmoticon
7
7
 
8
8
  # 対応するUser-Agentの正規表現
9
- USER_AGENT_REGEXP = /iPad/.freeze
9
+ USER_AGENT_REGEXP = /iPad/
10
10
  end
11
11
  end
@@ -6,6 +6,6 @@ module Jpmobile::Mobile
6
6
  include Jpmobile::Mobile::UnicodeEmoticon
7
7
 
8
8
  # 対応するUser-Agentの正規表現
9
- USER_AGENT_REGEXP = /iPhone/.freeze
9
+ USER_AGENT_REGEXP = /iPhone/
10
10
  end
11
11
  end
@@ -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)/.freeze
8
+ USER_AGENT_REGEXP = /^(?:SoftBank|Semulator)/
9
9
  # 対応するメールアドレスの正規表現 ディズニーモバイル対応
10
- MAIL_ADDRESS_REGEXP = /.+@(?:softbank\.ne\.jp|disney\.ne\.jp)/.freeze
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)/.freeze
7
+ USER_AGENT_REGEXP = /^(Vodafone|Vemulator)/
8
8
  # 対応するメールアドレスの正規表現
9
- MAIL_ADDRESS_REGEXP = /.+@[dhtcrknsq]\.vodafone\.ne\.jp/.freeze
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}.freeze
7
+ USER_AGENT_REGEXP = %r{^Mozilla/3.0\(WILLCOM}
8
8
  # 対応するメールアドレスの正規表現
9
- MAIL_ADDRESS_REGEXP = /.+@((.+\.)?pdx\.ne\.jp|willcom\.com)/.freeze
9
+ MAIL_ADDRESS_REGEXP = /.+@((.+\.)?pdx\.ne\.jp|willcom\.com)/
10
10
 
11
11
  # 位置情報があれば Position のインスタンスを返す。無ければ +nil+ を返す。
12
12
  def position
@@ -4,6 +4,6 @@ module Jpmobile::Mobile
4
4
  # ==WindowsPhone
5
5
  class WindowsPhone < SmartPhone
6
6
  # 対応するUser-Agentの正規表現
7
- USER_AGENT_REGEXP = /Windows Phone/.freeze
7
+ USER_AGENT_REGEXP = /Windows Phone/
8
8
  end
9
9
  end
@@ -1,41 +1,15 @@
1
1
  module Jpmobile
2
- class PathSet < Array
3
- %w[initialize << concat insert push unshift].each do |method|
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 find(path, prefix = nil, partial = false, details = {}, key = nil)
13
- template = find_all(path, prefix, partial, details, key).first
14
- raise MissingTemplate.new(self, "#{prefix}/#{path}", details, partial) unless template
15
-
16
- template
17
- end
18
-
19
- def find_all(*args)
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
- unless env['REQUEST_METHOD'] == 'GET' || env['REQUEST_METHOD'] == 'HEAD'
14
- unless env['CONTENT_TYPE'].match?(%r{application/json|application/xml})
15
- env['rack.input'] = StringIO.new(parse_query(env['rack.input'].read, mobile))
16
- end
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
@@ -12,8 +12,10 @@ 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
@@ -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
- module Rails
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
@@ -1,14 +1,52 @@
1
1
  module Jpmobile
2
2
  class Resolver < ::ActionView::FileSystemResolver
3
- EXTENSIONS = [:locale, :formats, :handlers, :mobile].freeze
4
- DEFAULT_PATTERN = ':prefix/:action{_:mobile,}{.:locale,}{.:formats,}{+:variants,}{.:handlers,}'.freeze
5
-
6
3
  def initialize(path)
7
- raise ArgumentError, 'path already is a Resolver class' if path.is_a?(Resolver)
4
+ super(path)
5
+
6
+ @path_parser = Jpmobile::Resolver::PathParser.new
7
+ end
8
8
 
9
+ def clear_cache
9
10
  super
10
- @pattern = DEFAULT_PATTERN
11
- @path = File.expand_path(path)
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
@@ -0,0 +1,38 @@
1
+ module Jpmobile
2
+ class TemplateDetails < ActionView::TemplateDetails
3
+ def initialize(locale, handler, format, variant, mobile)
4
+ @mobile = mobile
5
+
6
+ super(locale, handler, format, variant)
7
+ end
8
+
9
+ def matches?(requested)
10
+ requested.formats_idx[@format] &&
11
+ requested.locale_idx[@locale] &&
12
+ requested.variants_idx[@variant] &&
13
+ requested.handlers_idx[@handler] &&
14
+ requested.mobile_idx[@mobile]
15
+ end
16
+
17
+ def sort_key_for(requested)
18
+ [
19
+ requested.formats_idx[@format],
20
+ requested.locale_idx[@locale],
21
+ requested.variants_idx[@variant],
22
+ requested.handlers_idx[@handler],
23
+ requested.mobile_idx[@mobile],
24
+ ]
25
+ end
26
+
27
+ class Requested < ActionView::TemplateDetails::Requested
28
+ attr_reader :mobile, :mobile_idx
29
+
30
+ def initialize(locale:, handlers:, formats:, variants:, mobile:)
31
+ super(locale: locale, handlers: handlers, formats: formats, variants: variants)
32
+
33
+ @mobile = mobile.map(&:to_sym)
34
+ @mobile_idx = build_idx_hash(mobile)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -91,7 +91,7 @@ module Jpmobile
91
91
  end
92
92
 
93
93
  module ActionController
94
- class Metal #:nodoc:
94
+ class Metal # :nodoc:
95
95
  class_attribute :trans_sid_mode
96
96
 
97
97
  class << self