jpmobile 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/{test/rails/rails_root/vendor/plugins/jpmobile/MIT-LICENSE → MIT-LICENSE} +0 -0
- data/README.rdoc +16 -6
- data/Rakefile +14 -0
- data/VERSION.yml +4 -0
- data/init.rb +3 -0
- data/install.rb +1 -0
- data/jpmobile.gemspec +299 -0
- data/lib/jpmobile.rb +0 -2
- data/lib/jpmobile/emoticon.rb +16 -2
- data/lib/jpmobile/emoticon/z_combine.rb +17 -4
- data/lib/jpmobile/filter.rb +2 -3
- data/lib/jpmobile/mobile/abstract_mobile.rb +6 -0
- data/lib/jpmobile/mobile/docomo.rb +24 -1
- data/lib/jpmobile/mobile/z_ip_addresses_au.rb +3 -2
- data/lib/jpmobile/mobile/z_ip_addresses_docomo.rb +4 -1
- data/lib/jpmobile/request_with_mobile.rb +4 -1
- data/{test/rails/rails_root/vendor/plugins/jpmobile/spec → spec}/spec.opts +0 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/unit/detect_by_email_spec.rb +31 -0
- data/{test/rails/rails_root/vendor/plugins/jpmobile/spec → spec}/unit/detect_by_ua_spec.rb +11 -13
- data/spec/unit/is_carrier_spec.rb +93 -0
- data/spec/unit/spec_helper.rb +5 -0
- data/spec/unit/util_spec.rb +30 -0
- data/spec/unit/valid_ip_spec.rb +60 -0
- data/{test/rails/rails_root/vendor/plugins/jpmobile/tasks → tasks}/jpmobile_tasks.rake +3 -3
- data/test/legacy/autoload_test.rb +2 -1
- data/test/legacy/docomo_test.rb +39 -0
- data/test/legacy/emoticon_functional_test.rb +21 -19
- data/test/legacy/emoticon_test.rb +12 -12
- data/test/legacy/filter_test.rb +10 -8
- data/test/legacy/helper.rb +32 -3
- data/test/legacy/softbank_test.rb +2 -0
- data/test/rails/.gitignore +1 -0
- data/test/rails/overrides/app/controllers/filter_controller.rb +10 -0
- data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +2 -0
- data/test/rails/overrides/spec/controllers/docomo_spec.rb +2 -0
- data/test/rails/overrides/spec/controllers/emobile_spec.rb +2 -0
- data/test/rails/overrides/spec/controllers/filter_spec.rb +8 -7
- data/test/rails/overrides/spec/controllers/pc_spec.rb +2 -0
- data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +2 -0
- data/test/rails/overrides/spec/controllers/template_path_spec.rb +2 -0
- data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +1 -0
- data/test/rails/overrides/spec/helpers/helpers_spec.rb +2 -0
- data/test/rails/overrides/spec/spec_helper.rb +15 -0
- data/test/rails/rails_root/app/controllers/filter_controller.rb +0 -23
- data/test/rails/rails_root/app/controllers/mobile_spec_controller.rb +1 -1
- data/test/rails/rails_root/app/controllers/template_path_controller.rb +3 -0
- data/test/rails/rails_root/app/helpers/application_helper.rb +0 -1
- data/test/rails/rails_root/config/boot.rb +13 -110
- data/test/rails/rails_root/config/environment.rb +4 -41
- data/test/rails/rails_root/config/environments/development.rb +22 -13
- data/test/rails/rails_root/config/environments/production.rb +41 -20
- data/test/rails/rails_root/config/environments/test.rb +35 -28
- data/test/rails/rails_root/config/initializers/backtrace_silencers.rb +2 -2
- data/test/rails/rails_root/config/initializers/inflections.rb +1 -1
- data/test/rails/rails_root/config/initializers/session_store.rb +2 -15
- data/test/rails/rails_root/config/routes.rb +6 -42
- data/test/rails/rails_root/db/schema.rb +24 -7
- data/test/rails/rails_root/db/seeds.rb +2 -2
- data/test/rails/rails_root/spec/helpers/helpers_spec.rb +4 -2
- data/test/rails/rails_root/spec/spec_helper.rb +19 -35
- data/test/rails/rails_root/test/performance/browsing_test.rb +2 -2
- data/test/rails/rails_root/test/test_helper.rb +2 -27
- data/test/rails/rails_root/vendor/plugins/jpmobile/init.rb +1 -1
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile.rb +39 -25
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/docomo_guid.rb +2 -1
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/email.rb +3 -4
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon.rb +24 -8
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/conversion_table.rb +10 -9
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/z_combine.rb +17 -4
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/filter.rb +43 -136
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/helpers.rb +5 -18
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_controller.rb +24 -16
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_view.rb +42 -85
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/abstract_mobile.rb +25 -2
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/au.rb +28 -3
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/display.rb +29 -26
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/docomo.rb +60 -11
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/softbank.rb +16 -41
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/willcom.rb +1 -10
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_au.rb +3 -2
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_docomo.rb +4 -1
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/position.rb +4 -3
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/request_with_mobile.rb +14 -13
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/trans_sid.rb +52 -35
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/util.rb +68 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec_helper.rb +3 -2
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_email_spec.rb +21 -27
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/is_carrier_spec.rb +56 -84
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/spec_helper.rb +1 -2
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/util_spec.rb +8 -2
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/valid_ip_spec.rb +43 -52
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/disabled_update_display_info_docomo.rb +0 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_au.rb +0 -0
- data/tools/emoji/genregexp.rb +47 -0
- metadata +348 -253
- data/test/rails/rails_root/README +0 -243
- data/test/rails/rails_root/Rakefile +0 -10
- data/test/rails/rails_root/app/controllers/docomo_guid_controller.rb +0 -13
- data/test/rails/rails_root/app/controllers/trans_sid_controller.rb +0 -28
- data/test/rails/rails_root/app/views/filter/index.html.erb +0 -0
- data/test/rails/rails_root/app/views/hankaku_filter/index.html.erb +0 -0
- data/test/rails/rails_root/app/views/template_path/_partial.html.erb +0 -1
- data/test/rails/rails_root/app/views/template_path/_partial_mobile.html.erb +0 -1
- data/test/rails/rails_root/app/views/template_path/_partial_mobile_docomo.html.erb +0 -1
- data/test/rails/rails_root/app/views/template_path/index.html.erb +0 -1
- data/test/rails/rails_root/app/views/template_path/index_mobile.html.erb +0 -1
- data/test/rails/rails_root/app/views/template_path/index_mobile_docomo.html.erb +0 -1
- data/test/rails/rails_root/app/views/template_path/partial.html.erb +0 -2
- data/test/rails/rails_root/config/database.yml +0 -22
- data/test/rails/rails_root/config/initializers/new_rails_defaults.rb +0 -21
- data/test/rails/rails_root/config/locales/en.yml +0 -5
- data/test/rails/rails_root/db/development.sqlite3 +0 -0
- data/test/rails/rails_root/db/test.sqlite3 +0 -0
- data/test/rails/rails_root/doc/README_FOR_APP +0 -2
- data/test/rails/rails_root/lib/tasks/rspec.rake +0 -165
- data/test/rails/rails_root/log/development.log +0 -38
- data/test/rails/rails_root/log/production.log +0 -0
- data/test/rails/rails_root/log/server.log +0 -0
- data/test/rails/rails_root/log/test.log +0 -451
- data/test/rails/rails_root/public/404.html +0 -30
- data/test/rails/rails_root/public/422.html +0 -30
- data/test/rails/rails_root/public/500.html +0 -30
- data/test/rails/rails_root/public/favicon.ico +0 -0
- data/test/rails/rails_root/public/images/rails.png +0 -0
- data/test/rails/rails_root/public/index.html +0 -275
- data/test/rails/rails_root/public/javascripts/application.js +0 -2
- data/test/rails/rails_root/public/javascripts/controls.js +0 -963
- data/test/rails/rails_root/public/javascripts/dragdrop.js +0 -973
- data/test/rails/rails_root/public/javascripts/effects.js +0 -1128
- data/test/rails/rails_root/public/javascripts/prototype.js +0 -4320
- data/test/rails/rails_root/public/robots.txt +0 -5
- data/test/rails/rails_root/script/about +0 -4
- data/test/rails/rails_root/script/console +0 -3
- data/test/rails/rails_root/script/dbconsole +0 -3
- data/test/rails/rails_root/script/destroy +0 -3
- data/test/rails/rails_root/script/generate +0 -3
- data/test/rails/rails_root/script/performance/benchmarker +0 -3
- data/test/rails/rails_root/script/performance/profiler +0 -3
- data/test/rails/rails_root/script/plugin +0 -3
- data/test/rails/rails_root/script/runner +0 -3
- data/test/rails/rails_root/script/server +0 -3
- data/test/rails/rails_root/spec/controllers/docomo_guid_spec.rb +0 -77
- data/test/rails/rails_root/spec/controllers/docomo_spec.rb +0 -28
- data/test/rails/rails_root/spec/controllers/emobile_spec.rb +0 -35
- data/test/rails/rails_root/spec/controllers/filter_spec.rb +0 -157
- data/test/rails/rails_root/spec/controllers/pc_spec.rb +0 -11
- data/test/rails/rails_root/spec/controllers/softbank_emulator_spec.rb +0 -40
- data/test/rails/rails_root/spec/controllers/template_path_spec.rb +0 -115
- data/test/rails/rails_root/spec/controllers/trans_sid_spec.rb +0 -99
- data/test/rails/rails_root/spec/rcov.opts +0 -2
- data/test/rails/rails_root/spec/rspec.rake +0 -165
- data/test/rails/rails_root/spec/spec.opts +0 -4
- data/test/rails/rails_root/vendor/plugins/jpmobile/CHANGELOG +0 -7
- data/test/rails/rails_root/vendor/plugins/jpmobile/README.rdoc +0 -239
- data/test/rails/rails_root/vendor/plugins/jpmobile/Rakefile +0 -116
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_request.rb +0 -5
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/auth.rb +0 -55
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/combined_logger.rb +0 -54
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/request.rb +0 -7
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/trans_sid.rb +0 -14
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/version.rb +0 -9
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
unless Object.const_defined?(:Encoding)
|
2
|
+
$KCODE = 'u'
|
3
|
+
end
|
4
|
+
|
2
5
|
module Jpmobile
|
3
6
|
module Emoticon
|
4
7
|
SJIS_TO_UNICODE = {}
|
@@ -7,11 +10,21 @@ module Jpmobile
|
|
7
10
|
SJIS_TO_UNICODE.freeze
|
8
11
|
UNICODE_TO_SJIS = SJIS_TO_UNICODE.invert.freeze
|
9
12
|
|
10
|
-
|
13
|
+
if Object.const_defined?(:Encoding)
|
14
|
+
sjis_regexp = Proc.new do |sjis|
|
15
|
+
Regexp.compile(Regexp.escape([sjis].pack('n').force_encoding("Shift_JIS")))
|
16
|
+
end
|
17
|
+
else
|
18
|
+
sjis_regexp = Proc.new do |sjis|
|
19
|
+
Regexp.compile(Regexp.escape([sjis].pack('n'),"s"),nil,'s')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
SJIS_REGEXP = Regexp.union(*SJIS_TO_UNICODE.keys.map{|s| sjis_regexp[s]})
|
11
24
|
SOFTBANK_WEBCODE_REGEXP = Regexp.union(*([/(?!)/n]+SOFTBANK_WEBCODE_TO_UNICODE.keys.map{|x| "\x1b\x24#{x}\x0f"}))
|
12
25
|
|
13
|
-
DOCOMO_SJIS_REGEXP = Regexp.union(*DOCOMO_SJIS_TO_UNICODE.keys.map{|s|
|
14
|
-
AU_SJIS_REGEXP = Regexp.union(*AU_SJIS_TO_UNICODE.keys.map{|s|
|
26
|
+
DOCOMO_SJIS_REGEXP = Regexp.union(*DOCOMO_SJIS_TO_UNICODE.keys.map{|s| sjis_regexp[s]})
|
27
|
+
AU_SJIS_REGEXP = Regexp.union(*AU_SJIS_TO_UNICODE.keys.map{|s| sjis_regexp[s]})
|
15
28
|
SOFTBANK_UNICODE_REGEXP = Regexp.union(*SOFTBANK_UNICODE_TO_WEBCODE.keys.map{|x| [x].pack('U')}).freeze
|
16
29
|
|
17
30
|
EMOTICON_UNICODES = UNICODE_TO_SJIS.keys|SOFTBANK_UNICODE_TO_WEBCODE.keys.map{|k|k+0x1000}
|
@@ -1,166 +1,73 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
# = 文字コードフィルタ
|
2
3
|
# thanks to masuidrive <masuidrive (at) masuidrive.jp>
|
3
4
|
|
4
|
-
require 'scanf'
|
5
|
-
|
6
5
|
class ActionController::Base #:nodoc:
|
7
6
|
def self.mobile_filter(options={})
|
8
7
|
options = {:emoticon=>true, :hankaku=>false}.update(options)
|
9
8
|
|
10
|
-
if options[:emoticon]
|
11
|
-
around_filter Jpmobile::Filter::Emoticon::Outer.new # 外部エンコーディング<->数値文字参照
|
12
|
-
end
|
13
|
-
around_filter Jpmobile::Filter::Sjis.new
|
14
|
-
if options[:emoticon]
|
15
|
-
around_filter Jpmobile::Filter::Emoticon::Inner.new # 数値文字参照<->UTF-8
|
16
|
-
end
|
17
9
|
if options[:hankaku]
|
18
|
-
|
10
|
+
before_filter lambda {|controller| Jpmobile::HankakuFilter.before(controller)}
|
11
|
+
after_filter lambda {|controller| Jpmobile::HankakuFilter.after(controller)}
|
19
12
|
end
|
20
13
|
end
|
21
14
|
end
|
22
15
|
|
23
16
|
module Jpmobile
|
24
|
-
|
25
|
-
|
26
|
-
# 文字コードフィルタのベースクラス。
|
27
|
-
class Base
|
28
|
-
# 外部コードから内部コードに変換
|
29
|
-
def before(controller)
|
30
|
-
if respond_to?(:to_internal) && apply_incoming?(controller)
|
31
|
-
Util.deep_apply(controller.params) do |value|
|
32
|
-
value = to_internal(value, controller)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
# 内部コードから外部コードに変換
|
37
|
-
def after(controller)
|
38
|
-
if respond_to?(:to_external) && apply_outgoing?(controller) && controller.response.body.is_a?(String)
|
39
|
-
controller.response.body = to_external(controller.response.body, controller)
|
40
|
-
after_after(controller) if respond_to? :after_after
|
41
|
-
end
|
42
|
-
end
|
43
|
-
# 入力時(params)にこのフィルタを適用するか
|
44
|
-
def apply_incoming?(controller); true; end
|
45
|
-
# 出力時(response.body)にこのフィルタを適用するべきか
|
46
|
-
def apply_outgoing?(controller); true; end
|
47
|
-
end
|
17
|
+
module HankakuFilter
|
18
|
+
module_function
|
48
19
|
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
[nil, "text/html", "application/xhtml+xml"].include?(controller.response.content_type)
|
56
|
-
controller.request.mobile?
|
57
|
-
end
|
20
|
+
# 入出力フィルタの適用条件
|
21
|
+
def apply_incoming?(controller)
|
22
|
+
controller.request.mobile?
|
23
|
+
end
|
24
|
+
def apply_outgoing?(controller)
|
25
|
+
controller.request.mobile? and
|
26
|
+
[nil, "text/html", "application/xhtml+xml"].include?(controller.response.content_type)
|
58
27
|
end
|
59
28
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
NKF.nkf('-m0 -x -Ws', str)
|
65
|
-
end
|
66
|
-
# Shift_JISからUTF-8に変換する。
|
67
|
-
def to_internal(str, controller)
|
68
|
-
NKF.nkf('-m0 -x -Sw', str)
|
69
|
-
end
|
70
|
-
# afterfilterを実行した後に実行する。
|
71
|
-
def after_after(controller)
|
72
|
-
unless controller.response.body.blank?
|
73
|
-
# 500.htmlなどをUTF-8で書いたとき、docomoで文字化けするのを防ぐため
|
74
|
-
# response_bodyが空の場合はShift_JISを指定しない
|
75
|
-
controller.response.charset = "Shift_JIS"
|
29
|
+
def before(controller)
|
30
|
+
if apply_incoming?(controller)
|
31
|
+
Util.deep_apply(controller.params) do |value|
|
32
|
+
value = to_internal(value)
|
76
33
|
end
|
77
34
|
end
|
78
|
-
# to_internalを適用するべきかどうかを返す。
|
79
|
-
def apply_incoming?(controller)
|
80
|
-
# Vodafone 3G/Softbank(Shift-JISにすると絵文字で不具合が生じる)以外の
|
81
|
-
# 携帯電話の場合に適用する。
|
82
|
-
mobile = controller.request.mobile
|
83
|
-
mobile && !(mobile.instance_of?(Jpmobile::Mobile::Vodafone)||mobile.instance_of?(Jpmobile::Mobile::Softbank))
|
84
|
-
end
|
85
|
-
def apply_outgoing?(controller)
|
86
|
-
[nil, "text/html", "application/xhtml+xml"].include?(controller.response.content_type) &&
|
87
|
-
apply_incoming?(controller)
|
88
|
-
end
|
89
35
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
def to_internal(str, controller)
|
95
|
-
filter(str, external, internal)
|
96
|
-
end
|
97
|
-
def to_external(str, controller)
|
98
|
-
filter(str, internal, external)
|
99
|
-
end
|
100
|
-
private
|
101
|
-
def filter(str, from, to)
|
102
|
-
str = str.clone
|
103
|
-
from.each_with_index do |int, i|
|
104
|
-
str.gsub!(int, to[i])
|
105
|
-
end
|
106
|
-
str
|
36
|
+
# 内部コードから外部コードに変換
|
37
|
+
def after(controller)
|
38
|
+
if apply_outgoing?(controller) and controller.response.body.is_a?(String)
|
39
|
+
controller.response.body = to_external(controller.response.body)
|
107
40
|
end
|
108
41
|
end
|
109
42
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
43
|
+
@@internal = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゛ ゜ ー 。 「 」 、 ・).freeze
|
44
|
+
@@external = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゙ ゚ ー 。 「 」 、 ・).freeze
|
45
|
+
def to_internal(str)
|
46
|
+
filter(str, @@external, @@internal)
|
47
|
+
end
|
48
|
+
def to_external(str)
|
49
|
+
filter(str, @@internal, @@external)
|
115
50
|
end
|
51
|
+
def filter(str, from, to)
|
52
|
+
str = str.clone
|
116
53
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
def to_internal(str, controller)
|
124
|
-
method_name = "external_to_unicodecr_" +
|
125
|
-
controller.request.mobile.class.name[/::(\w*)$/, 1].downcase
|
126
|
-
if Jpmobile::Emoticon.respond_to?(method_name)
|
127
|
-
Jpmobile::Emoticon.send(method_name, str)
|
128
|
-
else
|
129
|
-
str # 対応する変換メソッドが定義されていない場合は素通し
|
130
|
-
end
|
131
|
-
end
|
132
|
-
def to_external(str, controller)
|
133
|
-
# 使用する変換テーブルの決定
|
134
|
-
table = nil
|
135
|
-
to_sjis = false
|
136
|
-
case controller.request.mobile
|
137
|
-
when Jpmobile::Mobile::Docomo
|
138
|
-
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_DOCOMO
|
139
|
-
to_sjis = true
|
140
|
-
when Jpmobile::Mobile::Au
|
141
|
-
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_AU
|
142
|
-
to_sjis = true
|
143
|
-
when Jpmobile::Mobile::Jphone
|
144
|
-
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK
|
145
|
-
to_sjis = true
|
146
|
-
when Jpmobile::Mobile::Softbank
|
147
|
-
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK
|
148
|
-
end
|
54
|
+
# 一度UTF-8に変換
|
55
|
+
before_encoding = nil
|
56
|
+
if str.respond_to?(:force_encoding)
|
57
|
+
before_encoding = str.encoding
|
58
|
+
str.force_encoding("UTF-8")
|
59
|
+
end
|
149
60
|
|
150
|
-
|
151
|
-
|
61
|
+
from.each_with_index do |int, i|
|
62
|
+
str.gsub!(int, to[i])
|
152
63
|
end
|
153
|
-
|
154
|
-
#
|
155
|
-
|
156
|
-
|
157
|
-
def to_internal(str, controller)
|
158
|
-
Jpmobile::Emoticon::unicodecr_to_utf8(str)
|
159
|
-
end
|
160
|
-
def to_external(str, controller)
|
161
|
-
Jpmobile::Emoticon::utf8_to_unicodecr(str)
|
162
|
-
end
|
64
|
+
|
65
|
+
# 元に戻す
|
66
|
+
if before_encoding
|
67
|
+
str.force_encoding(before_encoding)
|
163
68
|
end
|
69
|
+
|
70
|
+
str
|
164
71
|
end
|
165
72
|
end
|
166
73
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
# =位置情報等を要求するヘルパー
|
2
3
|
module Jpmobile
|
3
4
|
# 携帯電話端末に位置情報を要求するための、特殊なリンクを出力するヘルパー群。
|
@@ -32,16 +33,13 @@ module Jpmobile
|
|
32
33
|
s << au_location_link_to(str||"au(antenna)", options)
|
33
34
|
end
|
34
35
|
end
|
35
|
-
if show_all || request.mobile.instance_of?(Mobile::Jphone)
|
36
|
-
s << jphone_location_link_to(str||"Softbank(antenna)", options)
|
37
|
-
end
|
38
36
|
if show_all || request.mobile.instance_of?(Mobile::Vodafone) || request.mobile.instance_of?(Mobile::Softbank)
|
39
37
|
s << softbank_location_link_to(str||"Softbank 3G(GPS)", options)
|
40
38
|
end
|
41
39
|
if show_all || request.mobile.instance_of?(Mobile::Willcom)
|
42
40
|
s << willcom_location_link_to(str||"Willcom", options)
|
43
41
|
end
|
44
|
-
return s.join("<br>\n")
|
42
|
+
return s.join("<br>\n").html_safe
|
45
43
|
end
|
46
44
|
|
47
45
|
# DoCoMo FOMAでGPS位置情報を取得するためのリンクを返す。
|
@@ -52,7 +50,7 @@ module Jpmobile
|
|
52
50
|
options[:only_path] = false
|
53
51
|
url = url_for(options)
|
54
52
|
end
|
55
|
-
return %{<a href="#{url}" lcs>#{str}</a>}
|
53
|
+
return %{<a href="#{url}" lcs>#{str}</a>}.html_safe
|
56
54
|
end
|
57
55
|
|
58
56
|
# DoCoMoでオープンiエリアを取得するためのURLを返す。
|
@@ -82,7 +80,7 @@ module Jpmobile
|
|
82
80
|
options[:only_path] = false
|
83
81
|
url = url_for(options)
|
84
82
|
end
|
85
|
-
return %{<a href="#{url}" utn>#{str}</a>}
|
83
|
+
return %{<a href="#{url}" utn>#{str}</a>}.html_safe
|
86
84
|
end
|
87
85
|
|
88
86
|
# DoCoMoでiモードIDを取得するためのリンクを返す。
|
@@ -132,17 +130,6 @@ module Jpmobile
|
|
132
130
|
link_to_url(str, au_location_url_for(options))
|
133
131
|
end
|
134
132
|
|
135
|
-
# J-PHONE 位置情報 (基地局) を取得するためのリンクを返す。
|
136
|
-
def jphone_location_link_to(str,options={})
|
137
|
-
url = options
|
138
|
-
if options.is_a?(Hash)
|
139
|
-
options = options.symbolize_keys
|
140
|
-
options[:only_path] = false
|
141
|
-
url = url_for(options)
|
142
|
-
end
|
143
|
-
return %{<a z href="#{url}">#{str}</a>}
|
144
|
-
end
|
145
|
-
|
146
133
|
# Softbank(含むVodafone 3G)で位置情報を取得するためのURLを返す。
|
147
134
|
def softbank_location_url_for(options={})
|
148
135
|
url = options
|
@@ -181,7 +168,7 @@ module Jpmobile
|
|
181
168
|
private
|
182
169
|
# 外部へのリンク
|
183
170
|
def link_to_url(str, url)
|
184
|
-
%{<a href="#{url}">#{str}</a>}
|
171
|
+
%{<a href="#{url}">#{str}</a>}.html_safe
|
185
172
|
end
|
186
173
|
end
|
187
174
|
end
|
@@ -1,23 +1,31 @@
|
|
1
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module AbstractController
|
3
|
+
module ViewPaths
|
4
|
+
def lookup_context_with_jpmobile
|
5
|
+
jpmobile_context = lookup_context_without_jpmobile
|
6
|
+
jpmobile_context.view_paths.controller = self
|
2
7
|
|
3
|
-
|
4
|
-
include Jpmobile::Helpers
|
5
|
-
before_filter :gettext_force_ja_for_mobile
|
6
|
-
# gettextが組み込まれている場合、携帯電話からのアクセスをjaロケールに強制する。
|
7
|
-
def gettext_force_ja_for_mobile
|
8
|
-
begin
|
9
|
-
::GetText.locale = 'ja' if request.mobile?
|
10
|
-
rescue NameError
|
8
|
+
jpmobile_context
|
11
9
|
end
|
12
|
-
end
|
13
10
|
|
14
|
-
|
15
|
-
def view_paths=(value)
|
16
|
-
@view_paths = ActionView::Base.process_view_paths(value) if value
|
17
|
-
end
|
11
|
+
alias_method_chain :lookup_context, :jpmobile
|
18
12
|
end
|
13
|
+
end
|
19
14
|
|
20
|
-
|
21
|
-
|
15
|
+
module ActionController
|
16
|
+
class Base
|
17
|
+
include Jpmobile::Helpers
|
18
|
+
before_filter :gettext_force_ja_for_mobile
|
19
|
+
# gettextが組み込まれている場合、携帯電話からのアクセスをjaロケールに強制する。
|
20
|
+
def gettext_force_ja_for_mobile
|
21
|
+
if Object.const_defined?(:GetText) and request.mobile?
|
22
|
+
begin
|
23
|
+
::GetText.locale = 'ja'
|
24
|
+
rescue NameError
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
22
28
|
end
|
23
29
|
end
|
30
|
+
|
31
|
+
ActionController::Request.send :include, Jpmobile::Encoding
|
@@ -1,17 +1,12 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
# = viewの自動切り替え
|
2
3
|
#
|
3
|
-
# Rails 2.1.0 対応 http://d.hatena.ne.jp/kusakari/20080620/1213931903
|
4
|
-
# thanks to id:kusakari
|
5
|
-
#
|
6
4
|
#:stopdoc:
|
7
5
|
# helperを追加
|
8
6
|
ActionView::Base.class_eval { include Jpmobile::Helpers }
|
9
7
|
#:startdoc:
|
10
8
|
|
11
|
-
|
12
|
-
require 'action_view'
|
13
|
-
|
14
|
-
# ActionView::Base を拡張して携帯からのアクセスの場合に携帯向けビューを優先表示する。
|
9
|
+
# ActionView を拡張して携帯からのアクセスの場合に携帯向けビューを優先表示する。
|
15
10
|
# Vodafone携帯(request.mobile == Jpmobile::Mobile::Vodafone)の場合、
|
16
11
|
# index_mobile_vodafone.html.erb
|
17
12
|
# index_mobile_softbank.html.erb
|
@@ -20,111 +15,73 @@ require 'action_view'
|
|
20
15
|
# の順にテンプレートが検索される。
|
21
16
|
# BUG: 現状、上記の例では index.html.erb が存在しない場合に振り分けが行われない
|
22
17
|
# (ダミーファイルを置くことで回避可能)。
|
23
|
-
|
24
18
|
module ActionView
|
25
19
|
class PathSet
|
26
|
-
alias find_template_without_jpmobile find_template #:nodoc:
|
27
|
-
alias initialize_without_jpmobile initialize #:nodoc:
|
28
|
-
|
29
20
|
attr_accessor :controller
|
30
21
|
|
31
|
-
def
|
32
|
-
if
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
# hook ActionView::PathSet#find_template
|
39
|
-
def find_template(original_template_path, format = nil, html_fallback = true) #:nodoc:
|
40
|
-
if controller and controller.kind_of?(ActionController::Base) and controller.request.mobile?
|
41
|
-
return original_template_path if original_template_path.respond_to?(:render)
|
42
|
-
template_path = original_template_path.sub(/^\//, '')
|
43
|
-
|
44
|
-
template_candidates = mobile_template_candidates(controller)
|
45
|
-
format_postfix = format ? ".#{format}" : ""
|
22
|
+
def find_with_jpmobile(path, prefix = nil, partial = false, details = {}, key = nil) #:nodoc:
|
23
|
+
if controller and controller.kind_of?(ActionController::Base) and
|
24
|
+
(controller.request.mobile? or controller.request.smart_phone?)
|
25
|
+
return path if path.respond_to?(:render)
|
26
|
+
template_candidates = mobile_template_candidates
|
46
27
|
|
47
28
|
each do |load_path|
|
48
29
|
template_candidates.each do |template_postfix|
|
49
|
-
|
50
|
-
|
51
|
-
end
|
30
|
+
templates = load_path.find_all("#{path}_#{template_postfix}", prefix, partial, details, key)
|
31
|
+
return templates.first unless templates.empty?
|
52
32
|
end
|
53
33
|
end
|
54
34
|
end
|
55
35
|
|
56
|
-
|
36
|
+
find_without_jpmobile(path, prefix, partial, details, key)
|
57
37
|
end
|
58
38
|
|
59
|
-
|
60
|
-
def mobile_template_candidates(controller)
|
61
|
-
candidates = []
|
62
|
-
c = controller.request.mobile.class
|
63
|
-
while c != Jpmobile::Mobile::AbstractMobile
|
64
|
-
candidates << "mobile_"+c.to_s.split(/::/).last.downcase
|
65
|
-
c = c.superclass
|
66
|
-
end
|
67
|
-
candidates << "mobile"
|
68
|
-
end
|
69
|
-
end
|
39
|
+
alias_method_chain :find, :jpmobile #:nodoc:
|
70
40
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
# nothing to do
|
75
|
-
def view_paths=(paths)
|
76
|
-
@view_paths = self.class.process_view_paths(paths, controller)
|
77
|
-
end
|
41
|
+
def mobile_template_candidates #:nodoc:
|
42
|
+
candidates = []
|
78
43
|
|
79
|
-
|
80
|
-
|
81
|
-
|
44
|
+
view_class, parent_class, template_prefix = case controller.request.mobile
|
45
|
+
when ::Jpmobile::Mobile::SmartPhone
|
46
|
+
[controller.request.mobile.class, ::Jpmobile::Mobile::SmartPhone, "smart_phone"]
|
47
|
+
when ::Jpmobile::Mobile::AbstractMobile
|
48
|
+
[controller.request.mobile.class, ::Jpmobile::Mobile::AbstractMobile, "mobile"]
|
82
49
|
else
|
83
|
-
|
50
|
+
[nil, nil, nil]
|
84
51
|
end
|
85
|
-
end
|
86
52
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
candidates << "mobile_"+c.to_s.split(/::/).last.downcase
|
92
|
-
c = c.superclass
|
53
|
+
if view_class and parent_class
|
54
|
+
find_mobile_template(view_class, parent_class, template_prefix).push(template_prefix)
|
55
|
+
else
|
56
|
+
[]
|
93
57
|
end
|
94
|
-
candidates << "mobile"
|
95
58
|
end
|
96
59
|
|
97
|
-
|
98
|
-
|
99
|
-
if
|
100
|
-
|
101
|
-
partial_name = File.basename(mobile_path)
|
60
|
+
private
|
61
|
+
def find_mobile_template(klass, parent, prefix)
|
62
|
+
if klass == parent
|
63
|
+
[]
|
102
64
|
else
|
103
|
-
|
104
|
-
partial_name = mobile_path
|
65
|
+
find_mobile_template(klass.superclass, parent, prefix).unshift("#{prefix}_#{klass.to_s.split(/::/).last.underscore}")
|
105
66
|
end
|
106
|
-
File.join(path, "_#{partial_name}")
|
107
|
-
end
|
108
|
-
|
109
|
-
def mobile_path template_path, type
|
110
|
-
"#{template_path}_#{type}"
|
111
67
|
end
|
68
|
+
end
|
112
69
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
70
|
+
module Helpers
|
71
|
+
module FormTagHelper
|
72
|
+
private
|
73
|
+
def html_options_for_form(url_for_options, options, *parameters_for_url)
|
74
|
+
accept_charset = (Rails.application.config.jpmobile.form_accept_charset_conversion && request && request.mobile && request.mobile.default_charset) || "UTF-8"
|
75
|
+
|
76
|
+
options.stringify_keys.tap do |html_options|
|
77
|
+
html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart")
|
78
|
+
# The following URL is unescaped, this is just a hash of options, and it is the
|
79
|
+
# responsability of the caller to escape all the values.
|
80
|
+
html_options["action"] = url_for(url_for_options, *parameters_for_url)
|
81
|
+
html_options["accept-charset"] = accept_charset
|
82
|
+
html_options["data-remote"] = true if html_options.delete("remote")
|
125
83
|
end
|
126
84
|
end
|
127
|
-
return nil
|
128
85
|
end
|
129
86
|
end
|
130
87
|
end
|