jpmobile 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +227 -0
- data/Rakefile +6 -13
- data/lib/jpmobile/docomo_guid.rb +42 -0
- data/lib/jpmobile/filter.rb +1 -1
- data/lib/jpmobile/helpers.rb +2 -1
- data/lib/jpmobile/hook_action_controller.rb +12 -0
- data/lib/jpmobile/hook_action_view.rb +82 -72
- data/lib/jpmobile/{hook_abstract_request.rb → hook_request.rb} +1 -1
- data/lib/jpmobile/mobile/au.rb +9 -3
- data/lib/jpmobile/mobile/z_display_info_docomo.rb +10 -2
- data/lib/jpmobile/mobile/z_ip_addresses_au.rb +1 -26
- data/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +2 -4
- data/lib/jpmobile/rack/auth.rb +55 -0
- data/lib/jpmobile/rack/combined_logger.rb +54 -0
- data/lib/jpmobile/rack/request.rb +7 -0
- data/lib/jpmobile/rack/trans_sid.rb +14 -0
- data/lib/jpmobile/trans_sid.rb +70 -62
- data/lib/jpmobile/version.rb +1 -1
- data/test/{au_test.rb → legacy/au_test.rb} +0 -0
- data/test/{autoload_test.rb → legacy/autoload_test.rb} +0 -0
- data/test/{docomo_test.rb → legacy/docomo_test.rb} +0 -0
- data/test/{emoticon_functional_test.rb → legacy/emoticon_functional_test.rb} +1 -1
- data/test/{emoticon_test.rb → legacy/emoticon_test.rb} +0 -0
- data/test/{filter_test.rb → legacy/filter_test.rb} +0 -0
- data/test/{helper.rb → legacy/helper.rb} +4 -5
- data/test/{helpers_test.rb → legacy/helpers_test.rb} +1 -1
- data/test/{softbank_test.rb → legacy/softbank_test.rb} +0 -0
- data/test/{willcom_test.rb → legacy/willcom_test.rb} +0 -0
- data/test/rails/overrides/app/controllers/application.rb +5 -0
- data/test/rails/overrides/app/controllers/docomo_guid_controller.rb +13 -0
- data/test/rails/overrides/app/controllers/filter_controller.rb +26 -0
- data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +5 -0
- data/test/rails/overrides/app/controllers/template_path_controller.rb +6 -0
- data/test/rails/overrides/app/controllers/trans_sid_controller.rb +28 -0
- data/test/rails/overrides/app/views/filter/index.html.erb +0 -0
- data/test/rails/overrides/app/views/hankaku_filter/index.html.erb +0 -0
- data/test/rails/overrides/app/views/template_path/_partial.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/_partial_mobile.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/_partial_mobile_docomo.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/index.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/index_mobile.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/index_mobile_docomo.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/partial.html.erb +2 -0
- data/test/rails/overrides/lib/tasks/rspec.rake +165 -0
- data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +77 -0
- data/test/rails/overrides/spec/controllers/docomo_spec.rb +28 -0
- data/test/rails/overrides/spec/controllers/emobile_spec.rb +35 -0
- data/test/rails/overrides/spec/controllers/filter_spec.rb +157 -0
- data/test/rails/overrides/spec/controllers/pc_spec.rb +11 -0
- data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +40 -0
- data/test/rails/overrides/spec/controllers/template_path_spec.rb +115 -0
- data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +98 -0
- data/test/rails/overrides/spec/helpers/helpers_spec.rb +13 -0
- data/test/rails/overrides/spec/rcov.opts +2 -0
- data/test/rails/overrides/spec/rspec.rake +165 -0
- data/test/rails/overrides/spec/spec.opts +4 -0
- data/test/rails/overrides/spec/spec_helper.rb +47 -0
- data/test/rails/rails_root/README +256 -0
- data/test/rails/rails_root/Rakefile +10 -0
- data/test/rails/rails_root/app/controllers/application.rb +5 -0
- data/test/rails/rails_root/app/controllers/docomo_guid_controller.rb +13 -0
- data/test/rails/rails_root/app/controllers/filter_controller.rb +26 -0
- data/test/rails/rails_root/app/controllers/mobile_spec_controller.rb +5 -0
- data/test/rails/rails_root/app/controllers/template_path_controller.rb +6 -0
- data/test/rails/rails_root/app/controllers/trans_sid_controller.rb +26 -0
- data/test/rails/rails_root/app/helpers/application_helper.rb +3 -0
- data/test/rails/rails_root/app/views/template_path/index.html.erb +1 -0
- data/test/rails/rails_root/app/views/template_path/index_mobile.html.erb +1 -0
- data/test/rails/rails_root/app/views/template_path/index_mobile_docomo.html.erb +1 -0
- data/test/rails/rails_root/config/boot.rb +109 -0
- data/test/rails/rails_root/config/database.yml +22 -0
- data/test/rails/rails_root/config/environment.rb +75 -0
- data/test/rails/rails_root/config/environments/development.rb +17 -0
- data/test/rails/rails_root/config/environments/production.rb +24 -0
- data/test/rails/rails_root/config/environments/test.rb +22 -0
- data/test/rails/rails_root/config/initializers/inflections.rb +10 -0
- data/test/rails/rails_root/config/initializers/mime_types.rb +5 -0
- data/test/rails/rails_root/config/initializers/new_rails_defaults.rb +17 -0
- data/test/rails/rails_root/config/locales/en.yml +5 -0
- data/test/rails/rails_root/config/routes.rb +43 -0
- data/test/rails/rails_root/db/development.sqlite3 +0 -0
- data/test/rails/rails_root/db/schema.rb +14 -0
- data/test/rails/rails_root/db/test.sqlite3 +0 -0
- data/test/rails/rails_root/doc/README_FOR_APP +5 -0
- data/test/rails/rails_root/lib/tasks/rspec.rake +165 -0
- data/test/rails/rails_root/log/development.log +38 -0
- 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 +401 -0
- data/test/rails/rails_root/public/404.html +30 -0
- data/test/rails/rails_root/public/422.html +30 -0
- data/test/rails/rails_root/public/500.html +33 -0
- data/test/rails/rails_root/public/dispatch.cgi +10 -0
- data/test/rails/rails_root/public/dispatch.fcgi +24 -0
- data/test/rails/rails_root/public/dispatch.rb +10 -0
- 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 +274 -0
- data/test/rails/rails_root/public/javascripts/application.js +2 -0
- data/test/rails/rails_root/public/javascripts/controls.js +963 -0
- data/test/rails/rails_root/public/javascripts/dragdrop.js +973 -0
- data/test/rails/rails_root/public/javascripts/effects.js +1128 -0
- data/test/rails/rails_root/public/javascripts/prototype.js +4320 -0
- data/test/rails/rails_root/public/robots.txt +5 -0
- data/test/rails/rails_root/script/about +4 -0
- data/test/rails/rails_root/script/console +3 -0
- data/test/rails/rails_root/script/dbconsole +3 -0
- data/test/rails/rails_root/script/destroy +3 -0
- data/test/rails/rails_root/script/generate +3 -0
- data/test/rails/rails_root/script/performance/benchmarker +3 -0
- data/test/rails/rails_root/script/performance/profiler +3 -0
- data/test/rails/rails_root/script/performance/request +3 -0
- data/test/rails/rails_root/script/plugin +3 -0
- data/test/rails/rails_root/script/process/inspector +3 -0
- data/test/rails/rails_root/script/process/reaper +3 -0
- data/test/rails/rails_root/script/process/spawner +3 -0
- data/test/rails/rails_root/script/runner +3 -0
- data/test/rails/rails_root/script/server +3 -0
- data/test/rails/rails_root/spec/controllers/docomo_guid_spec.rb +77 -0
- data/test/rails/rails_root/spec/controllers/docomo_spec.rb +28 -0
- data/test/rails/rails_root/spec/controllers/emobile_spec.rb +35 -0
- data/test/rails/rails_root/spec/controllers/filter_spec.rb +157 -0
- data/test/rails/rails_root/spec/controllers/pc_spec.rb +11 -0
- data/test/rails/rails_root/spec/controllers/softbank_emulator_spec.rb +40 -0
- data/test/rails/rails_root/spec/controllers/template_path_spec.rb +85 -0
- data/test/rails/rails_root/spec/controllers/trans_sid_spec.rb +96 -0
- data/test/rails/rails_root/spec/helpers/helpers_spec.rb +13 -0
- data/test/rails/rails_root/spec/rcov.opts +2 -0
- data/test/rails/rails_root/spec/rspec.rake +165 -0
- data/test/rails/rails_root/spec/spec.opts +4 -0
- data/test/rails/rails_root/spec/spec_helper.rb +47 -0
- data/test/rails/rails_root/test/performance/browsing_test.rb +9 -0
- data/test/rails/rails_root/test/test_helper.rb +38 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/CHANGELOG +7 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/MIT-LICENSE +7 -0
- data/{README → test/rails/rails_root/vendor/plugins/jpmobile/README.rdoc} +15 -17
- data/test/rails/rails_root/vendor/plugins/jpmobile/Rakefile +116 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/init.rb +3 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/install.rb +1 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile.rb +42 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/datum_conv.rb +72 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/docomo_guid.rb +42 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/email.rb +19 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon.rb +123 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/au.rb +1287 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/conversion_table.rb +3908 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/docomo.rb +255 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/softbank.rb +477 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/z_combine.rb +20 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/filter.rb +173 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/helpers.rb +185 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_controller.rb +11 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_view.rb +142 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_request.rb +13 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/abstract_mobile.rb +73 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/au.rb +97 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/display.rb +33 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/docomo.rb +97 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/emobile.rb +17 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/softbank.rb +110 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/willcom.rb +39 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_display_info_docomo.rb +688 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_au.rb +22 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_docomo.rb +12 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_emobile.rb +10 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_softbank.rb +17 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +117 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/position.rb +67 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/request_with_mobile.rb +44 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/trans_sid.rb +105 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/util.rb +21 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/version.rb +9 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec.opts +6 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec_helper.rb +36 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_email_spec.rb +31 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_ua_spec.rb +42 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/is_carrier_spec.rb +93 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/spec_helper.rb +5 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/util_spec.rb +28 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/valid_ip_spec.rb +60 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tasks/jpmobile_tasks.rake +59 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/emoji/genregexp.rb +47 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_au_emoticon_table.rb +34 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_docomo_emoticon_table.rb +34 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_emoticon_conversion_table.rb +107 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_softbank_emoticon_table.rb +32 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/list_gps_unsupported_au.rb +23 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_display_info_docomo.rb +45 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_au.rb +29 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_willcom.rb +17 -0
- data/tools/update_ip_addresses_au.rb +15 -5
- metadata +188 -22
data/README.rdoc
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
= jpmobile: A Rails plugin for Japanese mobile-phones
|
2
|
+
|
3
|
+
== jpmobileとは
|
4
|
+
携帯電話特有の機能を Rails で利用するためのプラグイン。
|
5
|
+
以下の機能を備える。
|
6
|
+
|
7
|
+
* 携帯電話のキャリア判別
|
8
|
+
* 端末位置情報の取得
|
9
|
+
* 端末製造番号、契約者番号等の取得
|
10
|
+
* IPアドレスの検証(キャリアが公開しているIPアドレス帯域からのアクセスか判定)
|
11
|
+
* セッションIDをフォーム/リンクに付与(Trans SID)
|
12
|
+
* 携帯電話ビューへの自動振分け
|
13
|
+
* ディスプレイ情報(画面サイズ、ブラウザ画面サイズ、カラー・白黒、色数)の取得
|
14
|
+
* GeoKit(http://geokit.rubyforge.org)との連携
|
15
|
+
* 文字コード変換機能/絵文字のキャリア間相互変換
|
16
|
+
|
17
|
+
== インストール
|
18
|
+
Rails の Version に応じて選択してください。
|
19
|
+
=== Rails 2.3.2
|
20
|
+
==== pluginとしてインストールする場合
|
21
|
+
|
22
|
+
リリース版:
|
23
|
+
% ./script/plugin install git://github.com/darashi/jpmobile.git -r 'tag x.x.x'
|
24
|
+
(x.x.xはバージョン)
|
25
|
+
|
26
|
+
開発版:
|
27
|
+
% ./script/plugin install git://github.com/darashi/jpmobile.git
|
28
|
+
|
29
|
+
==== gemでインストールする場合
|
30
|
+
|
31
|
+
# gem install jpmobile
|
32
|
+
としてgemをインストールした後
|
33
|
+
|
34
|
+
RAILS_ROOT/config/environment.rb の Rails::Initializer.run do |config| 〜 end 内に
|
35
|
+
config.gem "jpmobile"
|
36
|
+
の行を追加する。
|
37
|
+
|
38
|
+
=== Rails 2.2.x 以前
|
39
|
+
リリース版:
|
40
|
+
% ./script/plugin install git://github.com/darashi/jpmobile.git -r 'tag 0.0.5'
|
41
|
+
|
42
|
+
== 使用例
|
43
|
+
|
44
|
+
=== 携帯電話の識別
|
45
|
+
|
46
|
+
==== Viewの中で一部を切替える例
|
47
|
+
<% if request.mobile? %>
|
48
|
+
携帯電話からのアクセスです。
|
49
|
+
<% else %>
|
50
|
+
携帯電話からのアクセスではありません。
|
51
|
+
<% end %>
|
52
|
+
|
53
|
+
==== 別に用意した携帯電話用コントローラへリダイレクトする例
|
54
|
+
class PcController < ApplicationController
|
55
|
+
before_filter :redirect_if_mobile
|
56
|
+
|
57
|
+
def index
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def redirect_if_mobile
|
62
|
+
if request.mobile?
|
63
|
+
pa = params.dup
|
64
|
+
pa[:controller] = "/mobile"
|
65
|
+
redirect_to pa
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class MobileController < ApplicationController
|
71
|
+
mobile_filter
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
=== 携帯電話viewの自動振分け
|
76
|
+
DoCoMo携帯電話からアクセスすると、
|
77
|
+
* index_mobile_docomo.html.erb
|
78
|
+
* index_mobile.html.erb
|
79
|
+
* index.html.erb
|
80
|
+
の順でテンプレートを検索し、最初に見付かったテンプレートが利用される。
|
81
|
+
Auの場合は、index_mobile_au.html.erb、Softbankの場合はindex_mobile_softbank.html.erbが最初に検索される。
|
82
|
+
|
83
|
+
BUG: 現状、上記の例では index.html.erb が存在しない場合に振り分けが行われない(ダミーファイルを置くことで回避可能)。
|
84
|
+
|
85
|
+
==== キャリアの識別
|
86
|
+
|
87
|
+
case request.mobile
|
88
|
+
when Jpmobile::Mobile::Docomo
|
89
|
+
# for DoCoMo
|
90
|
+
when Jpmobile::Mobile::Au
|
91
|
+
# for au
|
92
|
+
when Jpmobile::Mobile::Softbank
|
93
|
+
# for SoftBank
|
94
|
+
when Jpmobile::Mobile::Willcom
|
95
|
+
# for Willcom
|
96
|
+
when Jpmobile::Mobile::Emobile
|
97
|
+
# for EMOBILE
|
98
|
+
else
|
99
|
+
# for PC
|
100
|
+
end
|
101
|
+
|
102
|
+
あるいは
|
103
|
+
if request.mobile.is_a?(Jpmobile::Mobile::Docomo)
|
104
|
+
# for DoCoMo
|
105
|
+
end
|
106
|
+
|
107
|
+
=== 位置情報の取得
|
108
|
+
|
109
|
+
==== 取得用リンクの生成
|
110
|
+
|
111
|
+
以下のようなコードで、端末に位置情報を要求するリンクを出力する。
|
112
|
+
<%= get_position_link_to(:action=>:gps) %>
|
113
|
+
|
114
|
+
==== 位置情報の取得
|
115
|
+
|
116
|
+
class MobileController < ApplicationController
|
117
|
+
def gps
|
118
|
+
if request.mobile && pos = request.mobile.position
|
119
|
+
@latitude = pos.lat
|
120
|
+
@longuitude = pos.lon
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
=== 端末情報の取得
|
127
|
+
|
128
|
+
端末側から通知されている場合、request.mobile.ident で
|
129
|
+
契約に固有の識別子もしくは端末の製造番号を取得できる。
|
130
|
+
両方存在する場合は契約に固有のIDが優先される。
|
131
|
+
|
132
|
+
* 契約に固有のID (request.mobile.ident_subscriber)
|
133
|
+
* au: EZ番号(サブスクライバ番号)
|
134
|
+
* DoCoMo: FOMAカード製造番号
|
135
|
+
* EMOBILE: EMnet対応端末から通知されるユニークなユーザID
|
136
|
+
* 端末製造番号 (request.mobile.ident_device)
|
137
|
+
* DoCoMo: 端末製造番号(FOMA, MOVA)
|
138
|
+
* SoftBank: 製造番号
|
139
|
+
|
140
|
+
=== IPの検証
|
141
|
+
キャリアが公開しているIPアドレス帯域からのアクセスか判定する。
|
142
|
+
request.mobile.valid_ip?
|
143
|
+
|
144
|
+
=== セッションIDの付与(Trans SID)
|
145
|
+
==== Cookie非対応携帯だけに付与する
|
146
|
+
class MyController
|
147
|
+
trans_sid
|
148
|
+
end
|
149
|
+
|
150
|
+
==== PCにも付与する
|
151
|
+
class MyController
|
152
|
+
trans_sid :always
|
153
|
+
end
|
154
|
+
|
155
|
+
trans_sid 機能を使う場合には cookie session store を使用することができません。
|
156
|
+
trans_sid を使用する際には、例えば config/initializers/session_store.rb で
|
157
|
+
ActionController::Base.session_store = :active_record_store
|
158
|
+
として active_record_store を使用します。
|
159
|
+
このとき ApplicationController において protect_from_forgery の :secret を指定するか、
|
160
|
+
あるいは protect_from_forgery を解除する必要があるでしょう。
|
161
|
+
|
162
|
+
=== 端末の画面サイズ
|
163
|
+
request.mobile.display で Jpmobile::Display クラスのインスタンスが返る。
|
164
|
+
画面幅 <%= request.mobile.display.width %>
|
165
|
+
画面高さ <%= request.mobile.display.height %>
|
166
|
+
|
167
|
+
=== GeoKit(http://geokit.rubyforge.org)との連携
|
168
|
+
|
169
|
+
vandor/plugins/geokit以下にGeoKitがインストールされていると、Jpmobile::PositionにGeoKit::Mappableがincludeされる。したがって、
|
170
|
+
|
171
|
+
request.mobile.position.distance_to('札幌駅')
|
172
|
+
|
173
|
+
とすることで、端末と「札幌駅」との距離を求めることができる。詳細は http://geokit.rubyforge.org/api/index.html 参照。
|
174
|
+
|
175
|
+
=== 文字コード変換機能/絵文字のキャリア間相互変換
|
176
|
+
|
177
|
+
JpmobileではControllerにmobile_filterを指定することで
|
178
|
+
DoCoMo、Au、SoftBankの絵文字を透過的に扱うことができる。
|
179
|
+
|
180
|
+
class MyController
|
181
|
+
mobile_filter
|
182
|
+
end
|
183
|
+
|
184
|
+
また、半角・全角の自動変換を用いる場合は
|
185
|
+
class MyController
|
186
|
+
mobile_filter :hankaku=>true
|
187
|
+
end
|
188
|
+
と指定する。
|
189
|
+
|
190
|
+
Jpmobile内では、各キャリアの絵文字はUnicode私的領域上にマッピングされ、管理される。
|
191
|
+
このとき、DoCoMo、Auは公式サイト記載のマッピングが使用される。
|
192
|
+
ただしSoftBankはAuとの重複を避けるため、公式のマッピングに0x1000加算しU+F001以降に割り当てる。
|
193
|
+
テンプレート内ではUTF-8でエンコードするか、数値文字参照の&#xHHHH;形式で指定する。
|
194
|
+
|
195
|
+
絵文字は送出時に内蔵の変換表に基づいて変換され、携帯電話のエンコーディングにあわせて送出される。
|
196
|
+
携帯電話から受信した絵文字は上記マッピングに基づいてUTF-8でparamsに渡される。
|
197
|
+
|
198
|
+
mobile_filterを有効にすると以下の処理が自動で行われる。
|
199
|
+
* DoCoMo、Auとの通信時にはShift_JIS、SoftBankとの通信時にはUTF-8が使用される。
|
200
|
+
* :hankaku=>true指定時は、カタカナは半角カナに変換されて送出される。携帯電話から送られた半角カナは全角カナに変換される。
|
201
|
+
* 絵文字はキャリアにあわせて変換されて送出される。
|
202
|
+
* 携帯電話からの絵文字はUnicode私的領域にマップされ、UTF-8でparamsに格納される。
|
203
|
+
|
204
|
+
== テストに必要なgemパッケージ
|
205
|
+
テストを実行するためには以下のgemパッケージが必要です。
|
206
|
+
* rails
|
207
|
+
* rack
|
208
|
+
* hpricot
|
209
|
+
* rspec
|
210
|
+
* rspec-rails
|
211
|
+
* spec-fixtures
|
212
|
+
|
213
|
+
== リンク
|
214
|
+
* Project Website: http://jpmobile-rails.org
|
215
|
+
* RDoc Documentation: http://jpmobile.rubyforge.org/rdoc
|
216
|
+
* GitHub: http://github.com/darashi/jpmobile/
|
217
|
+
* RubyForge Project Page: http://rubyforge.org/projects/jpmobile
|
218
|
+
* Mailing List: http://groups.google.com/group/jpmobile
|
219
|
+
* IRC Channel #jpmobile@freenode.net
|
220
|
+
|
221
|
+
== 作者
|
222
|
+
|
223
|
+
Copyright 2006 (c) Yohji Shidara, under MIT License.
|
224
|
+
|
225
|
+
Yohji Shidara <dara@shidara.net>
|
226
|
+
|
227
|
+
http://d.hatena.ne.jp/darashi
|
data/Rakefile
CHANGED
@@ -25,7 +25,7 @@ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
|
25
25
|
RDOC_OPTS = ['--quiet', '--title', "jpmobile documentation",
|
26
26
|
"--opname", "index.html",
|
27
27
|
"--line-numbers",
|
28
|
-
"--main", "README",
|
28
|
+
"--main", "README.rdoc",
|
29
29
|
"--inline-source"]
|
30
30
|
|
31
31
|
desc "Packages up jpmobile gem."
|
@@ -35,19 +35,13 @@ task :package => [:clean]
|
|
35
35
|
desc 'Default: run unit tests.'
|
36
36
|
task :default => :test
|
37
37
|
|
38
|
-
desc 'Test the jpmobile plugin.'
|
39
|
-
Rake::TestTask.new(:test) do |t|
|
40
|
-
t.libs << 'lib'
|
41
|
-
t.pattern = 'test/**/*_test.rb'
|
42
|
-
t.verbose = true
|
43
|
-
end
|
44
38
|
|
45
39
|
desc 'Generate documentation for the jpmobile plugin.'
|
46
40
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
47
41
|
rdoc.rdoc_dir = 'doc'
|
48
42
|
rdoc.title = 'Jpmobile'
|
49
43
|
rdoc.options << '--line-numbers' << '--inline-source' << '-c UTF-8'
|
50
|
-
rdoc.rdoc_files.include('README')
|
44
|
+
rdoc.rdoc_files.include('README.rdoc')
|
51
45
|
rdoc.rdoc_files.include('CHANGELOG')
|
52
46
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
47
|
end
|
@@ -58,7 +52,7 @@ spec =
|
|
58
52
|
s.version = VERS
|
59
53
|
s.platform = Gem::Platform::RUBY
|
60
54
|
s.has_rdoc = true
|
61
|
-
s.extra_rdoc_files = ["README", "CHANGELOG"]
|
55
|
+
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG"]
|
62
56
|
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
63
57
|
s.summary = DESCRIPTION
|
64
58
|
s.description = DESCRIPTION
|
@@ -70,12 +64,12 @@ spec =
|
|
70
64
|
s.bindir = "bin"
|
71
65
|
s.require_path = "lib"
|
72
66
|
|
73
|
-
s.add_runtime_dependency('actionpack', '>=2.
|
67
|
+
s.add_runtime_dependency('actionpack', '>=2.3.2')
|
74
68
|
s.add_development_dependency('rspec', '>=1.1.12')
|
75
69
|
s.add_development_dependency('rspec-rails', '>=1.1.12')
|
76
70
|
s.add_development_dependency('rspec-fixture', '>=0.0.2')
|
77
71
|
|
78
|
-
s.files = %w(README CHANGELOG Rakefile) +
|
72
|
+
s.files = %w(README.rdoc CHANGELOG Rakefile) +
|
79
73
|
Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
|
80
74
|
Dir.glob("ext/**/*.{h,c,rb}") +
|
81
75
|
Dir.glob("examples/**/*.rb") +
|
@@ -118,6 +112,5 @@ task :rel => [:gem] do
|
|
118
112
|
puts "git tag #{VERS}"
|
119
113
|
end
|
120
114
|
|
121
|
-
|
122
|
-
RAILS_ROOT = '.'
|
115
|
+
task :test => ['test:legacy', 'spec:unit', 'test:rails']
|
123
116
|
load 'tasks/jpmobile_tasks.rake'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#DoCoMoの時guid=onの付与
|
2
|
+
class ActionController::Base #:nodoc:
|
3
|
+
class_inheritable_accessor :docomo_guid_mode
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def docomo_guid(mode=:docomo)
|
7
|
+
include Jpmobile::DocomoGuid
|
8
|
+
self.docomo_guid_mode = mode
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
module Jpmobile::DocomoGuid #:nodoc:
|
15
|
+
protected
|
16
|
+
def default_url_options options=nil
|
17
|
+
result = super || {}
|
18
|
+
return result unless request # for test process
|
19
|
+
return result unless apply_add_guid?
|
20
|
+
return result.merge({:guid => "ON"})
|
21
|
+
end
|
22
|
+
|
23
|
+
#guid=ONを付与すべきか否かを返す
|
24
|
+
def apply_add_guid?
|
25
|
+
return true if docomo_guid_mode == :always
|
26
|
+
return false if docomo_guid_mode == :none
|
27
|
+
|
28
|
+
return false unless request.mobile?
|
29
|
+
return false unless request.mobile.is_a?(Jpmobile::Mobile::Docomo)
|
30
|
+
return false if not_apply_guid_user_agent?
|
31
|
+
|
32
|
+
if docomo_guid_mode == :valid_ip
|
33
|
+
return false unless request.mobile.valid_ip?
|
34
|
+
end
|
35
|
+
|
36
|
+
return true
|
37
|
+
end
|
38
|
+
|
39
|
+
def not_apply_guid_user_agent?
|
40
|
+
request.user_agent.match(/(?:Googlebot|Y!J-SRD\/1\.0|Y!J-MBS\/1\.0)/)
|
41
|
+
end
|
42
|
+
end
|
data/lib/jpmobile/filter.rb
CHANGED
@@ -42,7 +42,7 @@ module Jpmobile
|
|
42
42
|
def after(controller)
|
43
43
|
@counter -= 1
|
44
44
|
return unless @counter.zero?
|
45
|
-
if respond_to?(:to_external) && apply_outgoing?(controller)
|
45
|
+
if respond_to?(:to_external) && apply_outgoing?(controller) && controller.response.body.is_a?(String)
|
46
46
|
controller.response.body = to_external(controller.response.body, controller)
|
47
47
|
after_after(controller) if respond_to? :after_after
|
48
48
|
end
|
data/lib/jpmobile/helpers.rb
CHANGED
@@ -147,10 +147,11 @@ module Jpmobile
|
|
147
147
|
mode = "auto"
|
148
148
|
if options.is_a?(Hash)
|
149
149
|
options = options.symbolize_keys
|
150
|
+
mode = options.delete(:mode) || "auto"
|
150
151
|
options[:only_path] = false
|
151
|
-
mode = options[:mode] || "auto"
|
152
152
|
url = url_for(options)
|
153
153
|
end
|
154
|
+
url.sub!(/\?/, '&')
|
154
155
|
return "location:#{mode}?url=#{url}"
|
155
156
|
end
|
156
157
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'action_pack'
|
2
|
+
|
1
3
|
class ActionController::Base
|
2
4
|
include Jpmobile::Helpers
|
3
5
|
before_filter :gettext_force_ja_for_mobile
|
@@ -8,4 +10,14 @@ class ActionController::Base
|
|
8
10
|
rescue NameError
|
9
11
|
end
|
10
12
|
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def view_paths=(value)
|
16
|
+
@view_paths = ActionView::Base.process_view_paths(value) if value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def view_paths=(value)
|
21
|
+
@view_paths = ActionView::Base.process_view_paths(value, controller) if value
|
22
|
+
end
|
11
23
|
end
|
@@ -21,47 +21,43 @@ require 'action_view'
|
|
21
21
|
# BUG: 現状、上記の例では index.rhtml が存在しない場合に振り分けが行われない
|
22
22
|
# (ダミーファイルを置くことで回避可能)。
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
alias render_partial_without_jpmobile render_partial #:nodoc:
|
31
|
-
|
32
|
-
def _pick_template(template_path)
|
33
|
-
mobile_path = mobile_template_path(template_path)
|
34
|
-
return mobile_path.nil? ? _pick_template_without_jpmobile(template_path) :
|
35
|
-
_pick_template_without_jpmobile(mobile_path)
|
36
|
-
end
|
24
|
+
module ActionView
|
25
|
+
class PathSet
|
26
|
+
alias find_template_without_jpmobile find_template #:nodoc:
|
27
|
+
alias initialize_without_jpmobile initialize #:nodoc:
|
28
|
+
|
29
|
+
attr_accessor :controller
|
37
30
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
mobile_path = mobile_template_path(partial_path, true)
|
42
|
-
options = options.merge(:partial => mobile_path) if mobile_path
|
31
|
+
def initialize(*args)
|
32
|
+
if args.first.kind_of?(ActionController::Base)
|
33
|
+
@controller = args.shift
|
43
34
|
end
|
44
|
-
|
45
|
-
end
|
46
|
-
else
|
47
|
-
### Rails 2.1 or lower
|
48
|
-
alias render_file_without_jpmobile render_file #:nodoc:
|
49
|
-
alias render_partial_without_jpmobile render_partial #:nodoc:
|
50
|
-
|
51
|
-
def render_file(template_path, use_full_path = true, local_assigns = {})
|
52
|
-
mobile_path = mobile_template_path(template_path)
|
53
|
-
return mobile_path.nil? ? render_file_without_jpmobile(template_path, use_full_path, local_assigns) :
|
54
|
-
render_file_without_jpmobile(mobile_path, use_full_path, local_assigns)
|
35
|
+
initialize_without_jpmobile(*args)
|
55
36
|
end
|
56
37
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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}" : ""
|
46
|
+
|
47
|
+
each do |load_path|
|
48
|
+
template_candidates.each do |template_postfix|
|
49
|
+
if template = load_path["#{template_path}_#{template_postfix}#{format_postfix}"]
|
50
|
+
return template
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
return find_template_without_jpmobile(original_template_path, format, html_fallback)
|
61
57
|
end
|
62
|
-
end
|
63
58
|
|
64
|
-
|
59
|
+
# collect cadidates of mobile_template
|
60
|
+
def mobile_template_candidates(controller)
|
65
61
|
candidates = []
|
66
62
|
c = controller.request.mobile.class
|
67
63
|
while c != Jpmobile::Mobile::AbstractMobile
|
@@ -69,52 +65,66 @@ class ActionView::Base #:nodoc:
|
|
69
65
|
c = c.superclass
|
70
66
|
end
|
71
67
|
candidates << "mobile"
|
68
|
+
end
|
72
69
|
end
|
73
70
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
path = self.controller.class.controller_path
|
81
|
-
partial_name = mobile_path
|
71
|
+
class Base #:nodoc:
|
72
|
+
delegate :default_url_options, :to => :controller unless respond_to?(:default_url_options)
|
73
|
+
|
74
|
+
# nothing to do
|
75
|
+
def view_paths=(paths)
|
76
|
+
@view_paths = self.class.process_view_paths(paths, controller)
|
82
77
|
end
|
83
|
-
File.join(path, "_#{partial_name}")
|
84
|
-
end
|
85
78
|
|
86
|
-
|
87
|
-
|
88
|
-
|
79
|
+
def self.process_view_paths(value, controller = nil)
|
80
|
+
if controller && controller.is_a?(ActionController::Base)
|
81
|
+
ActionView::PathSet.new(controller, Array(value))
|
82
|
+
else
|
83
|
+
ActionView::PathSet.new(Array(value))
|
84
|
+
end
|
85
|
+
end
|
89
86
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
else
|
97
|
-
full_path = mpath
|
98
|
-
end
|
99
|
-
if template_exists?(full_path)
|
100
|
-
return mpath
|
101
|
-
end
|
87
|
+
def mobile_template_candidates
|
88
|
+
candidates = []
|
89
|
+
c = controller.request.mobile.class
|
90
|
+
while c != Jpmobile::Mobile::AbstractMobile
|
91
|
+
candidates << "mobile_"+c.to_s.split(/::/).last.downcase
|
92
|
+
c = c.superclass
|
102
93
|
end
|
94
|
+
candidates << "mobile"
|
95
|
+
end
|
96
|
+
|
97
|
+
def mobile_template_partial mobile_path
|
98
|
+
# ActionView::PartialTemplate#extract_partial_name_and_path の動作を模倣
|
99
|
+
if mobile_path.include?('/')
|
100
|
+
path = File.dirname(mobile_path)
|
101
|
+
partial_name = File.basename(mobile_path)
|
102
|
+
else
|
103
|
+
path = self.controller.class.controller_path
|
104
|
+
partial_name = mobile_path
|
105
|
+
end
|
106
|
+
File.join(path, "_#{partial_name}")
|
103
107
|
end
|
104
|
-
return nil
|
105
|
-
end
|
106
108
|
|
107
|
-
|
108
|
-
|
109
|
-
def template_exists?(template_name)
|
110
|
-
send(:_pick_template_without_jpmobile, template_name) ? true : false
|
111
|
-
rescue ActionView::MissingTemplate
|
112
|
-
false
|
109
|
+
def mobile_path template_path, type
|
110
|
+
"#{template_path}_#{type}"
|
113
111
|
end
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
112
|
+
|
113
|
+
def mobile_template_path(template_path, partial=false)
|
114
|
+
if controller.is_a?(ActionController::Base) && m = controller.request.mobile
|
115
|
+
mobile_template_candidates.each do |v|
|
116
|
+
mpath = mobile_path template_path, v
|
117
|
+
if partial
|
118
|
+
full_path = mobile_template_partial mpath
|
119
|
+
else
|
120
|
+
full_path = mpath
|
121
|
+
end
|
122
|
+
if template_exists?(full_path)
|
123
|
+
return mpath
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
return nil
|
118
128
|
end
|
119
129
|
end
|
120
130
|
end
|