jpmobile 6.1.2 → 7.0.2
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 +12 -4
- data/.rubocop.yml +104 -1
- data/.ruby-version +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +157 -149
- data/README.md +5 -21
- data/Rakefile +1 -1
- data/jpmobile.gemspec +4 -4
- data/lib/jpmobile/datum_conv.rb +7 -7
- data/lib/jpmobile/docomo_guid.rb +2 -2
- data/lib/jpmobile/email.rb +2 -2
- data/lib/jpmobile/fallback_view_selector.rb +2 -2
- data/lib/jpmobile/filter.rb +3 -1
- data/lib/jpmobile/hook_action_view.rb +3 -3
- data/lib/jpmobile/hook_template_details_requested.rb +12 -0
- data/lib/jpmobile/mail.rb +2 -2
- data/lib/jpmobile/mailer.rb +2 -2
- data/lib/jpmobile/mobile/abstract_mobile.rb +1 -1
- data/lib/jpmobile/mobile/android_tablet.rb +1 -1
- data/lib/jpmobile/mobile/au.rb +4 -6
- data/lib/jpmobile/mobile/softbank.rb +3 -1
- data/lib/jpmobile/path_set.rb +10 -36
- data/lib/jpmobile/position.rb +2 -2
- data/lib/jpmobile/rails.rb +2 -0
- data/lib/jpmobile/resolver.rb +44 -6
- data/lib/jpmobile/template_details.rb +38 -0
- data/lib/jpmobile/trans_sid.rb +1 -1
- data/lib/jpmobile/util.rb +1 -1
- data/lib/jpmobile/version.rb +1 -1
- data/lib/jpmobile/view_selector.rb +5 -6
- data/lib/jpmobile.rb +13 -0
- data/lib/tasks/jpmobile_tasks.rake +4 -5
- data/spec/rack/jpmobile/mobile_by_ua_spec.rb +1 -0
- data/spec/unit/decorated_mail_spec.rb +1 -1
- data/spec/unit/mail_spec.rb +2 -2
- data/spec/unit/receive_mail_spec.rb +29 -29
- data/test/rails/overrides/Gemfile.jpmobile +4 -0
- 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/mailers/decorated_mailer.rb +1 -1
- data/test/rails/overrides/app/views/mobile_spec/mobile_not_exist.html.erb +3 -0
- data/test/rails/overrides/config/routes.rb +3 -1
- 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/{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 +25 -30
- data/test/rails/overrides/app/views/mobile_spec/no_mobile.html.erb +0 -3
data/lib/jpmobile/datum_conv.rb
CHANGED
@@ -19,11 +19,11 @@ module DatumConv
|
|
19
19
|
l = l_deg * Deg2Rad
|
20
20
|
|
21
21
|
e2 = f * (2 - f)
|
22
|
-
n = a / Math.sqrt(1 - e2 * Math.sin(b)**2)
|
22
|
+
n = a / Math.sqrt(1 - (e2 * (Math.sin(b)**2)))
|
23
23
|
|
24
24
|
x = (n + he) * Math.cos(b) * Math.cos(l)
|
25
25
|
y = (n + he) * Math.cos(b) * Math.sin(l)
|
26
|
-
z = (n * (1 - e2) + he) * Math.sin(b)
|
26
|
+
z = ((n * (1 - e2)) + he) * Math.sin(b)
|
27
27
|
return x, y, z
|
28
28
|
end
|
29
29
|
|
@@ -34,12 +34,12 @@ module DatumConv
|
|
34
34
|
e2 = f * (2 - f)
|
35
35
|
l = Math.atan2(y, x)
|
36
36
|
|
37
|
-
p = Math.sqrt(x**2 + y**2)
|
38
|
-
r = Math.sqrt(p**2 + z**2)
|
39
|
-
u = Math.atan2(z * ((1 - f) + e2 * a / r), p)
|
40
|
-
b = Math.atan2(z * (1 - f) + e2 * a * Math.sin(u)**3, (1 - f) * (p - e2 * a * Math.cos(u)**3))
|
37
|
+
p = Math.sqrt((x**2) + (y**2))
|
38
|
+
r = Math.sqrt((p**2) + (z**2))
|
39
|
+
u = Math.atan2(z * ((1 - f) + (e2 * a / r)), p)
|
40
|
+
b = Math.atan2((z * (1 - f)) + (e2 * a * (Math.sin(u)**3)), (1 - f) * (p - (e2 * a * (Math.cos(u)**3))))
|
41
41
|
|
42
|
-
he = p * Math.cos(b) + z * Math.sin(b) - a * Math.sqrt(1 - e2 * Math.sin(b)**2)
|
42
|
+
he = (p * Math.cos(b)) + (z * Math.sin(b)) - (a * Math.sqrt(1 - (e2 * (Math.sin(b)**2))))
|
43
43
|
|
44
44
|
b_deg = b / Deg2Rad
|
45
45
|
l_deg = l / Deg2Rad
|
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
|
data/lib/jpmobile/email.rb
CHANGED
@@ -10,7 +10,7 @@ module Jpmobile
|
|
10
10
|
def detect(email)
|
11
11
|
Mobile.carriers.each do |const|
|
12
12
|
c = Mobile.const_get(const)
|
13
|
-
return c if c::MAIL_ADDRESS_REGEXP && email.match(/^#{c::MAIL_ADDRESS_REGEXP}$/)
|
13
|
+
return c if c::MAIL_ADDRESS_REGEXP && email.match(/^#{c::MAIL_ADDRESS_REGEXP}$/) # rubocop:disable Performance/ConstantRegexp
|
14
14
|
end
|
15
15
|
nil
|
16
16
|
end
|
@@ -21,7 +21,7 @@ module Jpmobile
|
|
21
21
|
c = Mobile.const_get(const)
|
22
22
|
if c::MAIL_ADDRESS_REGEXP &&
|
23
23
|
header.match(/(\S+@[A-Za-z0-9\-._]+)/) &&
|
24
|
-
Regexp.last_match(1).match(/^#{c::MAIL_ADDRESS_REGEXP}$/)
|
24
|
+
Regexp.last_match(1).match(/^#{c::MAIL_ADDRESS_REGEXP}$/) # rubocop:disable Performance/ConstantRegexp
|
25
25
|
return c
|
26
26
|
end
|
27
27
|
end
|
@@ -8,10 +8,10 @@ module Jpmobile
|
|
8
8
|
begin
|
9
9
|
expected_view_file = lookup_context.find_template(options[:template], options[:prefixes])
|
10
10
|
|
11
|
-
_candidates = lookup_context.mobile.
|
11
|
+
_candidates = lookup_context.mobile.filter_map do |variant|
|
12
12
|
target_template = options[:template] + '_' + variant
|
13
13
|
expected_view_file.virtual_path.match(target_template)
|
14
|
-
|
14
|
+
end
|
15
15
|
|
16
16
|
if _candidates.empty?
|
17
17
|
lookup_context.mobile = []
|
data/lib/jpmobile/filter.rb
CHANGED
@@ -42,6 +42,8 @@ module Jpmobile
|
|
42
42
|
Regexp.escape('application/xhtml+xm'),
|
43
43
|
)
|
44
44
|
|
45
|
+
CONVERT_TARGET_ELEMENTS = %w[submit reset button].freeze
|
46
|
+
|
45
47
|
class << self
|
46
48
|
def hankaku_format(str)
|
47
49
|
replace_chars(str, zen_to_han_table)
|
@@ -149,7 +151,7 @@ module Jpmobile
|
|
149
151
|
# textarea 以外のテキストなら content を変換
|
150
152
|
element.content = filter(:hankaku, element.content)
|
151
153
|
end
|
152
|
-
elsif (element.node_name == 'input') &&
|
154
|
+
elsif (element.node_name == 'input') && CONVERT_TARGET_ELEMENTS.include?(element['type'])
|
153
155
|
# テキスト以外でもボタンの value は変換
|
154
156
|
element['value'] = filter(:hankaku, element['value'])
|
155
157
|
elsif element.children.any?
|
@@ -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
|
data/lib/jpmobile/mail.rb
CHANGED
@@ -55,7 +55,7 @@ module Mail
|
|
55
55
|
|
56
56
|
def parse_message_with_jpmobile
|
57
57
|
_crlf_raw_source = raw_source.encode(raw_source.encoding, universal_newline: true).encode!(raw_source.encoding, crlf_newline: true)
|
58
|
-
header_part, body_part = _crlf_raw_source.lstrip.split(/#{CRLF}#{CRLF}|#{CRLF}#{WSP}*#{CRLF}(?!#{WSP})/
|
58
|
+
header_part, body_part = _crlf_raw_source.lstrip.split(/#{CRLF}#{CRLF}|#{CRLF}#{WSP}*#{CRLF}(?!#{WSP})/mo, 2)
|
59
59
|
# header_part, body_part = raw_source.lstrip.split(HEADER_SEPARATOR, 2)
|
60
60
|
|
61
61
|
self.header = header_part
|
@@ -277,7 +277,7 @@ module Mail
|
|
277
277
|
end
|
278
278
|
|
279
279
|
def parse_message_with_jpmobile
|
280
|
-
header_part, body_part = raw_source.split(/#{CRLF}#{WSP}*#{CRLF}/
|
280
|
+
header_part, body_part = raw_source.split(/#{CRLF}#{WSP}*#{CRLF}/mo, 2)
|
281
281
|
|
282
282
|
self.header = if header_part && header_part.match(HEADER_LINE)
|
283
283
|
header_part
|
data/lib/jpmobile/mailer.rb
CHANGED
@@ -11,7 +11,7 @@ module Jpmobile
|
|
11
11
|
|
12
12
|
def mail(headers = {}, &block)
|
13
13
|
tos = headers[:to] || self.default_params[:to]
|
14
|
-
tos = tos.split(
|
14
|
+
tos = tos.split(',')
|
15
15
|
|
16
16
|
@mobile = if tos.size == 1
|
17
17
|
# for mobile
|
@@ -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")
|
@@ -242,7 +242,7 @@ module Jpmobile::Mobile
|
|
242
242
|
end
|
243
243
|
|
244
244
|
def ip_address_class
|
245
|
-
Object.const_get("::Jpmobile::Mobile::IpAddresses::#{self.to_s.split(
|
245
|
+
Object.const_get("::Jpmobile::Mobile::IpAddresses::#{self.to_s.split("::").last}").new
|
246
246
|
rescue
|
247
247
|
nil
|
248
248
|
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(
|
9
|
+
USER_AGENT_REGEXP = Regexp.union(/^(?!.+Mobile).+(?=Android).+$/, /Android.+SC-01C/)
|
10
10
|
end
|
11
11
|
end
|
data/lib/jpmobile/mobile/au.rb
CHANGED
@@ -15,6 +15,8 @@ module Jpmobile::Mobile
|
|
15
15
|
# GPS取得に対応していないデバイスID
|
16
16
|
GPS_UNSUPPORTED_DEVICE_ID = %w[PT21 KC26 SN28 SN26 KC23 SA28 TS25 SA25 SA24 SN23 ST14 KC15 SN22 KC14 ST13 SN17 SY15 CA14 HI14 TS14 KC13 SN15 SN16 SY14 ST12 TS13 CA13 MA13 HI13 SN13 SY13 SN12 SN14 ST11 DN11 SY12 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
|
17
17
|
|
18
|
+
TARGET_PARAMS = %w[ver datum unit lat lon alt time smaj smin vert majaa fm].freeze
|
19
|
+
|
18
20
|
# EZ番号(サブスクライバID)があれば返す。無ければ +nil+ を返す。
|
19
21
|
def subno
|
20
22
|
@request.env['HTTP_X_UP_SUBNO']
|
@@ -27,7 +29,7 @@ module Jpmobile::Mobile
|
|
27
29
|
return @__posotion = nil if params['lat'].nil? || params['lat'] == '' || params['lon'].nil? || params['lon'] == ''
|
28
30
|
|
29
31
|
l = Jpmobile::Position.new
|
30
|
-
l.options = params.select {|x, _|
|
32
|
+
l.options = params.select {|x, _| TARGET_PARAMS.include?(x) }
|
31
33
|
case params['unit']
|
32
34
|
when '1'
|
33
35
|
l.lat = params['lat'].to_f
|
@@ -83,11 +85,7 @@ module Jpmobile::Mobile
|
|
83
85
|
'none'
|
84
86
|
end
|
85
87
|
|
86
|
-
|
87
|
-
false
|
88
|
-
else
|
89
|
-
true
|
90
|
-
end
|
88
|
+
!protocol.start_with?('https')
|
91
89
|
end
|
92
90
|
|
93
91
|
# 文字コード変換
|
@@ -13,6 +13,8 @@ module Jpmobile::Mobile
|
|
13
13
|
# テキスト部分の content-transfer-encoding
|
14
14
|
MAIL_CONTENT_TRANSFER_ENCODING = '8bit'.freeze
|
15
15
|
|
16
|
+
TARGET_PARAMS = ['pos', 'geo', 'x-acr'].freeze
|
17
|
+
|
16
18
|
# 製造番号を返す。無ければ +nil+ を返す。
|
17
19
|
def serial_number
|
18
20
|
@request.env['HTTP_USER_AGENT'] =~ /SN(.+?) /
|
@@ -36,7 +38,7 @@ module Jpmobile::Mobile
|
|
36
38
|
l = Jpmobile::Position.new
|
37
39
|
l.lat = ((Regexp.last_match(1) == 'N') ? 1 : -1) * Jpmobile::Position.dms2deg(Regexp.last_match(2), Regexp.last_match(3), Regexp.last_match(4))
|
38
40
|
l.lon = ((Regexp.last_match(5) == 'E') ? 1 : -1) * Jpmobile::Position.dms2deg(Regexp.last_match(6), Regexp.last_match(7), Regexp.last_match(8))
|
39
|
-
l.options = params.select {|x, _|
|
41
|
+
l.options = params.select {|x, _| TARGET_PARAMS.include?(x) }
|
40
42
|
|
41
43
|
@__position = l
|
42
44
|
end
|
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
|
data/lib/jpmobile/position.rb
CHANGED
@@ -10,7 +10,7 @@ end
|
|
10
10
|
module Jpmobile
|
11
11
|
# 位置情報
|
12
12
|
class Position
|
13
|
-
if Object.const_defined?(
|
13
|
+
if Object.const_defined?(:GeoKit)
|
14
14
|
# GeoKitが読み込まれている場合はMappableにする
|
15
15
|
include ::GeoKit::Mappable
|
16
16
|
def self.acts_as_mappable
|
@@ -35,7 +35,7 @@ module Jpmobile
|
|
35
35
|
|
36
36
|
# 度分秒を度に変換する。
|
37
37
|
def self.dms2deg(d, m, s)
|
38
|
-
d.to_i + m.to_i.to_f / 60 + s.to_f / 3600
|
38
|
+
d.to_i + (m.to_i.to_f / 60) + (s.to_f / 3600)
|
39
39
|
end
|
40
40
|
|
41
41
|
# 日本測地系から世界測地系に変換する。
|
data/lib/jpmobile/rails.rb
CHANGED
@@ -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
|
data/lib/jpmobile/resolver.rb
CHANGED
@@ -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
|
-
|
4
|
+
super(path)
|
5
|
+
|
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
|
@@ -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.mobile_idx[@mobile],
|
23
|
+
requested.handlers_idx[@handler],
|
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
|
data/lib/jpmobile/trans_sid.rb
CHANGED
data/lib/jpmobile/util.rb
CHANGED
data/lib/jpmobile/version.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
module Jpmobile
|
2
2
|
module ViewSelector
|
3
|
-
|
4
|
-
base.class_eval do
|
5
|
-
before_action :register_mobile
|
3
|
+
extend ActiveSupport::Concern
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
included do
|
6
|
+
before_action :register_mobile
|
7
|
+
|
8
|
+
self.view_paths = Jpmobile::PathSet.new(self.view_paths.paths.map(&:path))
|
10
9
|
end
|
11
10
|
|
12
11
|
def register_mobile
|
data/lib/jpmobile.rb
CHANGED
@@ -48,9 +48,19 @@ module Jpmobile
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def self.carriers=(ary)
|
51
|
+
@all_variants = nil
|
52
|
+
|
51
53
|
@carriers = ary
|
52
54
|
end
|
53
55
|
|
56
|
+
def self.all_variants
|
57
|
+
return @all_variants if @all_variants
|
58
|
+
|
59
|
+
@all_variants = carriers.map {|carrier|
|
60
|
+
Jpmobile::Mobile.const_get(carrier).new({}, {}).variants
|
61
|
+
}.flatten.uniq
|
62
|
+
end
|
63
|
+
|
54
64
|
require 'jpmobile/mobile/abstract_mobile'
|
55
65
|
end
|
56
66
|
|
@@ -63,6 +73,9 @@ module Jpmobile
|
|
63
73
|
autoload :Mailer, 'jpmobile/mailer'
|
64
74
|
autoload :Resolver, 'jpmobile/resolver'
|
65
75
|
|
76
|
+
autoload :PathSet, 'jpmobile/path_set'
|
77
|
+
autoload :TemplateDetails, 'jpmobile/template_details'
|
78
|
+
|
66
79
|
autoload :ViewSelector, 'jpmobile/view_selector'
|
67
80
|
autoload :FallbackViewSelector, 'jpmobile/fallback_view_selector'
|
68
81
|
|
@@ -84,12 +84,10 @@ namespace :test do
|
|
84
84
|
unless skip
|
85
85
|
# for cookie_only option
|
86
86
|
config_path = File.join(rails_root, 'config', 'initializers', 'session_store.rb')
|
87
|
-
File.
|
88
|
-
file.write <<-SESSION_CONFIG
|
87
|
+
File.write(config_path, <<-SESSION_CONFIG)
|
89
88
|
Rails.application.config.session_store :active_record_store, :key => '_session_id'
|
90
89
|
Rails.application.config.session_options = { :cookie_only => false }
|
91
|
-
|
92
|
-
end
|
90
|
+
SESSION_CONFIG
|
93
91
|
end
|
94
92
|
|
95
93
|
unless skip
|
@@ -112,12 +110,13 @@ namespace :test do
|
|
112
110
|
|
113
111
|
system 'bundle install'
|
114
112
|
system 'bin/rails db:migrate RAILS_ENV=test' unless skip
|
115
|
-
system 'bin/rails spec'
|
113
|
+
system 'bin/rails spec', exception: true
|
116
114
|
|
117
115
|
ENV.replace(original_env)
|
118
116
|
end
|
119
117
|
end
|
120
118
|
end
|
119
|
+
|
121
120
|
desc 'Run sinatra on jpmobile tests'
|
122
121
|
Rake::TestTask.new(:sinatra) do |t|
|
123
122
|
t.libs << 'lib'
|
@@ -17,6 +17,7 @@ describe Jpmobile::MobileCarrier do
|
|
17
17
|
[Jpmobile::Mobile::Emobile, 'emobile/1.0.0 (H11T; like Gecko; Wireless) NetFront/3.4'],
|
18
18
|
[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'],
|
19
19
|
[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'],
|
20
|
+
[Jpmobile::Mobile::Android, 'Mozilla/5.0 (Linux; Android 9; ANE-LX2J Build/HUAWEIANE-LX2J; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/88.0.4324.93 Mobile Safari/537.36 Instagram 172.0.0.21.123 Android (28/9; 480dpi; 1080x2060; HUAWEI; ANE-LX2J; HWANE; hi6250; ja_JP; 269790805)'],
|
20
21
|
[Jpmobile::Mobile::WindowsPhone, 'Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.1 T-01A_6.5; Windows Phone 6.5)'],
|
21
22
|
[Jpmobile::Mobile::BlackBerry, 'BlackBerry9000/4.6.0.224 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/220'],
|
22
23
|
[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'],
|
@@ -14,7 +14,7 @@ describe 'decorated mails' do
|
|
14
14
|
@mail.from = 'ちはやふる <info@jpmobile-rails.org>'
|
15
15
|
@mail.to = 'むすめふさほせ <info+to@jpmobile-rails.org>'
|
16
16
|
|
17
|
-
@photo = File.
|
17
|
+
@photo = File.read(File.join(__dir__, 'email-fixtures/photo.jpg'))
|
18
18
|
@mail.attachments.inline['photo.jpg'] = @photo
|
19
19
|
@inline_url = @mail.attachments['photo.jpg'].url
|
20
20
|
end
|
data/spec/unit/mail_spec.rb
CHANGED
@@ -285,7 +285,7 @@ describe 'Jpmobile::Mail' do
|
|
285
285
|
@mobile = Jpmobile::Mobile::AbstractMobile.new(nil, nil)
|
286
286
|
@mail.mobile = @mobile
|
287
287
|
@mail.to = 'むすめふさほせ <info+to@jpmobile-rails.org>'
|
288
|
-
@photo = File.
|
288
|
+
@photo = File.read(File.join(__dir__, 'email-fixtures/photo.jpg'))
|
289
289
|
end
|
290
290
|
|
291
291
|
it 'should encodes itself successfully' do
|
@@ -318,7 +318,7 @@ describe 'Jpmobile::Mail' do
|
|
318
318
|
@mobile = Jpmobile::Mobile::AbstractMobile.new(nil, nil)
|
319
319
|
@mail.mobile = @mobile
|
320
320
|
@mail.to = 'むすめふさほせ <info+to@jpmobile-rails.org>'
|
321
|
-
@photo = File.
|
321
|
+
@photo = File.read(File.join(__dir__, 'email-fixtures/photo.jpg'))
|
322
322
|
end
|
323
323
|
|
324
324
|
it 'wave dash converting correctly' do
|