jpmobile 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/CHANGELOG +4 -0
  2. data/README.rdoc +29 -15
  3. data/Rakefile +3 -3
  4. data/lib/jpmobile/emoticon/conversion_table.rb +10 -9
  5. data/lib/jpmobile/emoticon.rb +14 -6
  6. data/lib/jpmobile/filter.rb +2 -9
  7. data/lib/jpmobile/helpers.rb +2 -0
  8. data/lib/jpmobile/hook_action_view.rb +5 -5
  9. data/lib/jpmobile/mobile/softbank.rb +2 -2
  10. data/lib/jpmobile/mobile/z_display_info_docomo.rb +577 -528
  11. data/lib/jpmobile/mobile/z_ip_addresses_au.rb +5 -1
  12. data/lib/jpmobile/mobile/z_ip_addresses_softbank.rb +2 -2
  13. data/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +53 -13
  14. data/lib/jpmobile/trans_sid.rb +28 -14
  15. data/lib/jpmobile/version.rb +1 -1
  16. data/test/legacy/emoticon_test.rb +6 -0
  17. data/test/legacy/helpers_test.rb +6 -5
  18. data/test/rails/2.3.2/spec/controllers/trans_sid_spec.rb +99 -0
  19. data/test/rails/overrides/app/controllers/{application.rb → application_controller.rb} +0 -0
  20. data/test/rails/overrides/app/controllers/filter_controller.rb +1 -0
  21. data/test/rails/overrides/spec/controllers/filter_spec.rb +1 -0
  22. data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +20 -2
  23. data/test/rails/rails_root/README +6 -19
  24. data/test/rails/rails_root/app/controllers/{application.rb → application_controller.rb} +0 -0
  25. data/test/rails/rails_root/app/controllers/trans_sid_controller.rb +4 -2
  26. data/test/rails/rails_root/app/views/filter/index.html.erb +0 -0
  27. data/test/rails/rails_root/app/views/hankaku_filter/index.html.erb +0 -0
  28. data/test/rails/rails_root/app/views/template_path/_partial.html.erb +1 -0
  29. data/test/rails/rails_root/app/views/template_path/_partial_mobile.html.erb +1 -0
  30. data/test/rails/rails_root/app/views/template_path/_partial_mobile_docomo.html.erb +1 -0
  31. data/test/rails/rails_root/app/views/template_path/partial.html.erb +2 -0
  32. data/test/rails/rails_root/config/boot.rb +2 -1
  33. data/test/rails/rails_root/config/environment.rb +15 -48
  34. data/test/rails/rails_root/config/environments/production.rb +11 -7
  35. data/test/rails/rails_root/config/environments/test.rb +6 -0
  36. data/test/rails/rails_root/config/initializers/backtrace_silencers.rb +7 -0
  37. data/test/rails/rails_root/config/initializers/new_rails_defaults.rb +4 -0
  38. data/test/rails/rails_root/config/initializers/session_store.rb +15 -0
  39. data/test/rails/rails_root/config/routes.rb +1 -1
  40. data/test/rails/rails_root/db/development.sqlite3 +0 -0
  41. data/test/rails/rails_root/db/seeds.rb +7 -0
  42. data/test/rails/rails_root/db/test.sqlite3 +0 -0
  43. data/test/rails/rails_root/doc/README_FOR_APP +2 -5
  44. data/test/rails/rails_root/log/development.log +9 -9
  45. data/test/rails/rails_root/log/test.log +198 -148
  46. data/test/rails/rails_root/public/500.html +0 -3
  47. data/test/rails/rails_root/public/index.html +1 -0
  48. data/test/rails/rails_root/script/about +2 -2
  49. data/test/rails/rails_root/script/console +1 -1
  50. data/test/rails/rails_root/script/dbconsole +1 -1
  51. data/test/rails/rails_root/script/destroy +1 -1
  52. data/test/rails/rails_root/script/generate +1 -1
  53. data/test/rails/rails_root/script/performance/benchmarker +1 -1
  54. data/test/rails/rails_root/script/performance/profiler +1 -1
  55. data/test/rails/rails_root/script/plugin +1 -1
  56. data/test/rails/rails_root/script/runner +1 -1
  57. data/test/rails/rails_root/script/server +1 -1
  58. data/test/rails/rails_root/spec/controllers/template_path_spec.rb +49 -19
  59. data/test/rails/rails_root/spec/controllers/trans_sid_spec.rb +11 -8
  60. data/test/rails/rails_root/test/test_helper.rb +1 -1
  61. data/test/rails/rails_root/vendor/plugins/jpmobile/MIT-LICENSE +2 -2
  62. data/test/rails/rails_root/vendor/plugins/jpmobile/README.rdoc +31 -15
  63. data/test/rails/rails_root/vendor/plugins/jpmobile/Rakefile +1 -1
  64. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon.rb +3 -1
  65. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/filter.rb +3 -10
  66. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/helpers.rb +2 -0
  67. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_controller.rb +12 -0
  68. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_view.rb +79 -91
  69. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_request.rb +2 -10
  70. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/au.rb +9 -3
  71. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/softbank.rb +2 -2
  72. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_display_info_docomo.rb +577 -528
  73. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_au.rb +5 -1
  74. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_softbank.rb +2 -2
  75. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +53 -13
  76. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/auth.rb +55 -0
  77. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/combined_logger.rb +54 -0
  78. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/request.rb +7 -0
  79. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/trans_sid.rb +14 -0
  80. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/trans_sid.rb +76 -65
  81. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/version.rb +1 -1
  82. data/test/rails/rails_root/vendor/plugins/jpmobile/tasks/jpmobile_tasks.rake +26 -6
  83. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/{update_display_info_docomo.rb → disabled_update_display_info_docomo.rb} +11 -6
  84. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_docomo_emoticon_table.rb +0 -1
  85. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_softbank_emoticon_table.rb +0 -1
  86. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_au.rb +4 -3
  87. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_willcom.rb +2 -2
  88. data/tools/{update_display_info_docomo.rb → disabled_update_display_info_docomo.rb} +11 -6
  89. data/tools/generate_docomo_emoticon_table.rb +0 -1
  90. data/tools/generate_softbank_emoticon_table.rb +0 -1
  91. data/tools/update_ip_addresses_au.rb +4 -3
  92. data/tools/update_ip_addresses_willcom.rb +2 -2
  93. metadata +65 -35
  94. data/test/rails/rails_root/public/dispatch.cgi +0 -10
  95. data/test/rails/rails_root/public/dispatch.fcgi +0 -24
  96. data/test/rails/rails_root/public/dispatch.rb +0 -10
  97. data/test/rails/rails_root/script/performance/request +0 -3
  98. data/test/rails/rails_root/script/process/inspector +0 -3
  99. data/test/rails/rails_root/script/process/reaper +0 -3
  100. data/test/rails/rails_root/script/process/spawner +0 -3
@@ -229,6 +229,7 @@
229
229
  <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
230
230
  <li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li>
231
231
  <li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li>
232
+ <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
232
233
  </ul>
233
234
  </li>
234
235
  </ul>
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
2
+ require File.expand_path('../../config/boot', __FILE__)
3
3
  $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
4
- require 'commands/about'
4
+ require 'commands/about'
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
2
+ require File.expand_path('../../config/boot', __FILE__)
3
3
  require 'commands/console'
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
2
+ require File.expand_path('../../config/boot', __FILE__)
3
3
  require 'commands/dbconsole'
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
2
+ require File.expand_path('../../config/boot', __FILE__)
3
3
  require 'commands/destroy'
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
2
+ require File.expand_path('../../config/boot', __FILE__)
3
3
  require 'commands/generate'
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../../config/boot'
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
3
  require 'commands/performance/benchmarker'
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../../config/boot'
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
3
  require 'commands/performance/profiler'
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
2
+ require File.expand_path('../../config/boot', __FILE__)
3
3
  require 'commands/plugin'
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
2
+ require File.expand_path('../../config/boot', __FILE__)
3
3
  require 'commands/runner'
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
2
+ require File.expand_path('../../config/boot', __FILE__)
3
3
  require 'commands/server'
@@ -56,30 +56,60 @@ end
56
56
 
57
57
  describe TemplatePathController, "integrated_views" do
58
58
  integrate_views
59
- context "PCからのアクセスの場合" do
60
- before do
61
- get :index
59
+ describe "index" do
60
+ context "PCからのアクセスの場合" do
61
+ before do
62
+ get :index
63
+ end
64
+ it 'index.html.erbが使用されること' do
65
+ response.should have_tag("h1", "index.html.erb")
66
+ end
62
67
  end
63
- it 'index.html.erbが使用されること' do
64
- response.should have_tag("h1", "index.html.erb")
68
+ context "DoCoMoからのアクセスの場合" do
69
+ before do
70
+ request.user_agent = "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
71
+ get :index
72
+ end
73
+ it 'index_mobile_docomo.html.erbが使用されること' do
74
+ response.should have_tag("h1", "index_mobile_docomo.html.erb")
75
+ end
65
76
  end
66
- end
67
- context "DoCoMoからのアクセスの場合" do
68
- before do
69
- request.user_agent = "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
70
- get :index
71
- end
72
- it 'index_mobile_docomo.html.erbが使用されること' do
73
- response.should have_tag("h1", "index_mobile_docomo.html.erb")
77
+ context "SoftBankからのアクセスの場合" do
78
+ before do
79
+ request.user_agent = "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
80
+ get :index
81
+ end
82
+ it 'index_mobile.html.erbが使用されること' do
83
+ response.should have_tag("h1", "index_mobile.html.erb")
84
+ end
74
85
  end
75
86
  end
76
- context "SoftBankからのアクセスの場合" do
77
- before do
78
- request.user_agent = "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
79
- get :index
87
+ describe "partial" do
88
+ context "PCからのアクセスの場合" do
89
+ before do
90
+ get :partial
91
+ end
92
+ it '_partial.html.erbが使用されること' do
93
+ response.should have_tag("h2", "_partial.html.erb")
94
+ end
95
+ end
96
+ context "DoCoMoからのアクセスの場合" do
97
+ before do
98
+ request.user_agent = "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
99
+ get :partial
100
+ end
101
+ it '_partial_mobile_docomo.html.erbが使用されること' do
102
+ response.should have_tag("h2", "_partial_mobile_docomo.html.erb")
103
+ end
80
104
  end
81
- it 'index_mobile.html.erbが使用されること' do
82
- response.should have_tag("h1", "index_mobile.html.erb")
105
+ context "SoftBankからのアクセスの場合" do
106
+ before do
107
+ request.user_agent = "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
108
+ get :partial
109
+ end
110
+ it '_partial_mobile.html.erbが使用されること' do
111
+ response.should have_tag("h2", "_partial_mobile.html.erb")
112
+ end
83
113
  end
84
114
  end
85
115
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require File.dirname(__FILE__) + '/../spec_helper'
2
3
 
3
4
  describe "trans_sid が起動しないとき", :shared => true do
@@ -9,11 +10,15 @@ describe "trans_sid が起動しないとき", :shared => true do
9
10
  get :form
10
11
  response.body.should =~ %r{^<form action="/.+?/form" method="post">Hello</form>$}
11
12
  end
13
+ it "で redirect の自動書き換えが行われない" do
14
+ get :redirect
15
+ response.should redirect_to('/')
16
+ end
12
17
  end
13
18
 
14
19
  describe "trans_sid が起動するとき", :shared => true do
15
20
  before :each do
16
- request.session.session_id = "mysessionid"
21
+ request.session_options[:id] = "mysessionid"
17
22
  end
18
23
  it "で link_to の自動書き換えが行われる" do
19
24
  get :link
@@ -23,6 +28,10 @@ describe "trans_sid が起動するとき", :shared => true do
23
28
  get :form
24
29
  response.body.should =~ %r{^<form action="/.+?/form\?_session_id=mysessionid" method="post">Hello<input type="hidden" name="_session_id" value="mysessionid" /></form>$}
25
30
  end
31
+ it "で redirect の自動書き換えが行われる" do
32
+ get :redirect
33
+ response.should redirect_to('/?_session_id=mysessionid')
34
+ end
26
35
  end
27
36
 
28
37
  describe TransSidBaseController, "という trans_sid が有効になっていないコントローラ" do
@@ -44,7 +53,7 @@ end
44
53
  describe TransSidAlwaysController, "という trans_sid :always が指定されているコントローラ" do
45
54
  controller_name :trans_sid_always
46
55
  before :each do
47
- request.session.session_id = "mysessionid"
56
+ request.session_options[:id] = "mysessionid"
48
57
  end
49
58
  it "の trans_sid_mode は :always" do
50
59
  controller.trans_sid_mode.should == :always
@@ -88,9 +97,3 @@ end
88
97
  describe_mobile_with_ua "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0" do
89
98
  it_should_behave_like "trans_sid が起動しないとき"
90
99
  end
91
-
92
-
93
- describe TransSidAlwaysAndSessionOffController, "という trans_sid :always と session :off を同時に指定しているコントローラ" do
94
- controller_name :trans_sid_always_and_session_off
95
- it_should_behave_like "trans_sid が起動しないとき"
96
- end
@@ -2,7 +2,7 @@ ENV["RAILS_ENV"] = "test"
2
2
  require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
3
  require 'test_help'
4
4
 
5
- class Test::Unit::TestCase
5
+ class ActiveSupport::TestCase
6
6
  # Transactional fixtures accelerate your tests by wrapping each test method
7
7
  # in a transaction that's rolled back on completion. This ensures that the
8
8
  # test database remains unchanged so your fixtures don't have to be reloaded
@@ -1,7 +1,7 @@
1
- Copyright (c) 2006 Yohji Shidara
1
+ Copyright (c) 2006 Yoji Shidara
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
5
5
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
6
 
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -15,17 +15,24 @@
15
15
  * 文字コード変換機能/絵文字のキャリア間相互変換
16
16
 
17
17
  == インストール
18
+ Rails の Version に応じて選択してください。
19
+ === Rails 2.3.3, 2.3.4, 2.3.5
20
+ 開発版:
21
+ % ./script/plugin install git://github.com/darashi/jpmobile.git
18
22
 
19
- === pluginとしてインストールする場合
23
+ === Rails 2.3.2
24
+ ==== pluginとしてインストールする場合
20
25
 
21
- リリース版:
22
- % ./script/plugin install git://github.com/darashi/jpmobile.git -r 'tag x.x.x'
23
- (x.x.xはバージョン)
26
+ リリース版: (Version 0.0.6)
27
+ % git clone git://github.com/darashi/jpmobile.git vendor/plugins/jpmobile
28
+ % cd vendor/plugins/jpmobile
29
+ % git checkout 0.0.6
30
+ % rm -rf .git
24
31
 
25
32
  開発版:
26
33
  % ./script/plugin install git://github.com/darashi/jpmobile.git
27
34
 
28
- === gemでインストールする場合
35
+ ==== gemでインストールする場合
29
36
 
30
37
  # gem install jpmobile
31
38
  としてgemをインストールした後
@@ -34,6 +41,12 @@ RAILS_ROOT/config/environment.rb の Rails::Initializer.run do |config| 〜 end
34
41
  config.gem "jpmobile"
35
42
  の行を追加する。
36
43
 
44
+ === Rails 2.2.x 以前
45
+ リリース版:
46
+ % git clone git://github.com/darashi/jpmobile.git vendor/plugins/jpmobile
47
+ % cd vendor/plugins/jpmobile
48
+ % git checkout 0.0.5
49
+ % rm -rf .git
37
50
 
38
51
  == 使用例
39
52
 
@@ -149,12 +162,19 @@ BUG: 現状、上記の例では index.html.erb が存在しない場合に振
149
162
  end
150
163
 
151
164
  trans_sid 機能を使う場合には cookie session store を使用することができません。
152
- trans_sid を使用する際には、例えば environment.rb で
153
- config.action_controller.session_store = :active_record_store
165
+ trans_sid を使用する際には、例えば config/initializers/session_store.rb で
166
+ ActionController::Base.session_store = :active_record_store
154
167
  として active_record_store を使用します。
155
168
  このとき ApplicationController において protect_from_forgery の :secret を指定するか、
156
169
  あるいは protect_from_forgery を解除する必要があるでしょう。
157
170
 
171
+ また、
172
+ link_to "hoge", "/controller/action/id"
173
+ のようにリンク先を直接指定するとセッションIDは付加されません。
174
+ link_to "hoge", :controller => "controller", :action => "action", :id => "id"
175
+ のように指定する必要があります。
176
+
177
+
158
178
  === 端末の画面サイズ
159
179
  request.mobile.display で Jpmobile::Display クラスのインスタンスが返る。
160
180
  画面幅 <%= request.mobile.display.width %>
@@ -207,17 +227,13 @@ mobile_filterを有効にすると以下の処理が自動で行われる。
207
227
  * spec-fixtures
208
228
 
209
229
  == リンク
210
- * Project Website: http://jpmobile-rails.org
211
- * RDoc Documentation: http://jpmobile.rubyforge.org/rdoc
212
- * GitHub: http://github.com/darashi/jpmobile/
213
- * RubyForge Project Page: http://rubyforge.org/projects/jpmobile
214
- * Mailing List: http://groups.google.com/group/jpmobile
215
- * IRC Channel #jpmobile@freenode.net
230
+
231
+ * http://jpmobile-rails.org
216
232
 
217
233
  == 作者
218
234
 
219
- Copyright 2006 (c) Yohji Shidara, under MIT License.
235
+ Copyright 2006 (c) Yoji Shidara, under MIT License.
220
236
 
221
- Yohji Shidara <dara@shidara.net>
237
+ Yoji Shidara <dara@shidara.net>
222
238
 
223
239
  http://d.hatena.ne.jp/darashi
@@ -64,7 +64,7 @@ spec =
64
64
  s.bindir = "bin"
65
65
  s.require_path = "lib"
66
66
 
67
- s.add_runtime_dependency('actionpack', '>=2.2.2')
67
+ s.add_runtime_dependency('actionpack', '>=2.3.2')
68
68
  s.add_development_dependency('rspec', '>=1.1.12')
69
69
  s.add_development_dependency('rspec-rails', '>=1.1.12')
70
70
  s.add_development_dependency('rspec-fixture', '>=0.0.2')
@@ -1,3 +1,5 @@
1
+ require 'nkf'
2
+
1
3
  module Jpmobile
2
4
  # 絵文字関連処理
3
5
  module Emoticon
@@ -95,7 +97,7 @@ module Jpmobile
95
97
  end
96
98
  when String
97
99
  # 変換先がUnicodeで指定されている。
98
- to_sjis ? Kconv::kconv(converted, Kconv::SJIS, Kconv::UTF8) : converted
100
+ to_sjis ? NKF.nkf('-m0 -x -Ws', converted) : converted
99
101
  when nil
100
102
  # 変換先が定義されていない。
101
103
  match
@@ -25,13 +25,8 @@ module Jpmobile
25
25
  module Filter
26
26
  # 文字コードフィルタのベースクラス。
27
27
  class Base
28
- def initialize
29
- @counter = 0 # render :component 時に多重で適用されるのを防ぐ
30
- end
31
28
  # 外部コードから内部コードに変換
32
29
  def before(controller)
33
- @counter += 1
34
- return unless @counter == 1
35
30
  if respond_to?(:to_internal) && apply_incoming?(controller)
36
31
  Util.deep_apply(controller.params) do |value|
37
32
  value = to_internal(value, controller)
@@ -40,9 +35,7 @@ module Jpmobile
40
35
  end
41
36
  # 内部コードから外部コードに変換
42
37
  def after(controller)
43
- @counter -= 1
44
- return unless @counter.zero?
45
- if respond_to?(:to_external) && apply_outgoing?(controller)
38
+ if respond_to?(:to_external) && apply_outgoing?(controller) && controller.response.body.is_a?(String)
46
39
  controller.response.body = to_external(controller.response.body, controller)
47
40
  after_after(controller) if respond_to? :after_after
48
41
  end
@@ -117,8 +110,8 @@ module Jpmobile
117
110
  # 半角カナと全角カナのフィルタ
118
111
  class HankakuKana < FilterTable
119
112
  include ApplyOnlyForMobile
120
- @@internal = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゛ ゜ ー ).freeze
121
- @@external = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゙ ゚ ー).freeze
113
+ @@internal = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゛ ゜ ー 。 「 」 、 ・).freeze
114
+ @@external = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゙ ゚ ー 。 「 」 、 ・).freeze
122
115
  end
123
116
 
124
117
  # 絵文字変換フィルタ
@@ -63,6 +63,8 @@ module Jpmobile
63
63
  options[:only_path] = false
64
64
  posinfo = options.delete(:posinfo) || "1" # 基地局情報を元に測位した緯度経度情報を要求
65
65
  url = url_for(options)
66
+ else
67
+ posinfo = "1"
66
68
  end
67
69
  return "http://w1m.docomo.ne.jp/cp/iarea?ecode=OPENAREACODE&msn=OPENAREAKEY&posinfo=#{posinfo}&nl=#{CGI.escape(url)}"
68
70
  end
@@ -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
@@ -13,77 +13,78 @@ require 'action_view'
13
13
 
14
14
  # ActionView::Base を拡張して携帯からのアクセスの場合に携帯向けビューを優先表示する。
15
15
  # Vodafone携帯(request.mobile == Jpmobile::Mobile::Vodafone)の場合、
16
- # index_mobile_vodafone.rhtml
17
- # index_mobile_softbank.rhtml
18
- # index_mobile.rhtml
19
- # index.rhtml
16
+ # index_mobile_vodafone.html.erb
17
+ # index_mobile_softbank.html.erb
18
+ # index_mobile.html.erb
19
+ # index.html.erb
20
20
  # の順にテンプレートが検索される。
21
- # BUG: 現状、上記の例では index.rhtml が存在しない場合に振り分けが行われない
21
+ # BUG: 現状、上記の例では index.html.erb が存在しない場合に振り分けが行われない
22
22
  # (ダミーファイルを置くことで回避可能)。
23
23
 
24
- class ActionView::Base #:nodoc:
25
- delegate :default_url_options, :to => :controller unless respond_to?(:default_url_options)
26
-
27
- if ::ActionPack::VERSION::MAJOR >=2 and ::ActionPack::VERSION::MINOR >= 3
28
- ### Rails 2.3 or higher
24
+ module ActionView
25
+ class PathSet
29
26
  alias find_template_without_jpmobile find_template #:nodoc:
30
- alias render_partial_without_jpmobile render_partial #:nodoc:
27
+ alias initialize_without_jpmobile initialize #:nodoc:
31
28
 
32
- def find_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
29
+ attr_accessor :controller
37
30
 
38
- def render_partial(options = {}) #:nodoc:
39
- case partial_path = options[:partial]
40
- when String, Symbol, NilClass
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
- render_partial_without_jpmobile(options)
35
+ initialize_without_jpmobile(*args)
45
36
  end
46
37
 
47
- elsif ::ActionPack::VERSION::MAJOR >=2 and ::ActionPack::VERSION::MINOR >= 2
48
- ### Rails 2.2 or higher
49
- alias _pick_template_without_jpmobile _pick_template #:nodoc:
50
- alias render_partial_without_jpmobile render_partial #:nodoc:
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
51
55
 
52
- def _pick_template(template_path)
53
- mobile_path = mobile_template_path(template_path)
54
- return mobile_path.nil? ? _pick_template_without_jpmobile(template_path) :
55
- _pick_template_without_jpmobile(mobile_path)
56
+ return find_template_without_jpmobile(original_template_path, format, html_fallback)
56
57
  end
57
58
 
58
- def render_partial(options = {}) #:nodoc:
59
- case partial_path = options[:partial]
60
- when String, Symbol, NilClass
61
- mobile_path = mobile_template_path(partial_path, true)
62
- options = options.merge(:partial => mobile_path) if mobile_path
59
+ # collect cadidates of mobile_template
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
63
66
  end
64
- render_partial_without_jpmobile(options)
67
+ candidates << "mobile"
65
68
  end
69
+ end
66
70
 
67
- else
68
- ### Rails 2.1 or lower
69
- alias render_file_without_jpmobile render_file #:nodoc:
70
- alias render_partial_without_jpmobile render_partial #:nodoc:
71
+ class Base #:nodoc:
72
+ delegate :default_url_options, :to => :controller unless respond_to?(:default_url_options)
71
73
 
72
- def render_file(template_path, use_full_path = true, local_assigns = {})
73
- mobile_path = mobile_template_path(template_path)
74
- return mobile_path.nil? ? render_file_without_jpmobile(template_path, use_full_path, local_assigns) :
75
- render_file_without_jpmobile(mobile_path, use_full_path, local_assigns)
74
+ # nothing to do
75
+ def view_paths=(paths)
76
+ @view_paths = self.class.process_view_paths(paths, controller)
76
77
  end
77
78
 
78
- def render_partial(partial_path, object_assigns = nil, local_assigns = {}) #:nodoc:
79
- mobile_path = mobile_template_path(partial_path, true) if partial_path.class === "String"
80
- return mobile_path.nil? ? render_partial_without_jpmobile(partial_path, object_assigns, local_assigns) :
81
- render_partial_without_jpmobile(mobile_path, object_assigns, local_assigns)
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
82
85
  end
83
86
 
84
- end
85
-
86
- def mobile_template_candidates
87
+ def mobile_template_candidates
87
88
  candidates = []
88
89
  c = controller.request.mobile.class
89
90
  while c != Jpmobile::Mobile::AbstractMobile
@@ -91,52 +92,39 @@ class ActionView::Base #:nodoc:
91
92
  c = c.superclass
92
93
  end
93
94
  candidates << "mobile"
94
- end
95
-
96
- def mobile_template_partial mobile_path
97
- # ActionView::PartialTemplate#extract_partial_name_and_path の動作を模倣
98
- if mobile_path.include?('/')
99
- path = File.dirname(mobile_path)
100
- partial_name = File.basename(mobile_path)
101
- else
102
- path = self.controller.class.controller_path
103
- partial_name = mobile_path
104
95
  end
105
- File.join(path, "_#{partial_name}")
106
- end
107
-
108
- def mobile_path template_path, type
109
- "#{template_path}_#{type}"
110
- end
111
96
 
112
- def mobile_template_path(template_path, partial=false)
113
- if controller.is_a?(ActionController::Base) && m = controller.request.mobile
114
- mobile_template_candidates.each do |v|
115
- mpath = mobile_path template_path, v
116
- if partial
117
- full_path = mobile_template_partial mpath
118
- else
119
- full_path = mpath
120
- end
121
- if template_exists?(full_path)
122
- return mpath
123
- end
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
124
105
  end
106
+ File.join(path, "_#{partial_name}")
125
107
  end
126
- return nil
127
- end
128
108
 
129
- if ::ActionPack::VERSION::MAJOR >=2 and ::ActionPack::VERSION::MINOR >= 2
130
- ### Rails 2.2 or higher
131
- def template_exists?(template_name)
132
- send(:_pick_template_without_jpmobile, template_name) ? true : false
133
- rescue ActionView::MissingTemplate
134
- false
109
+ def mobile_path template_path, type
110
+ "#{template_path}_#{type}"
135
111
  end
136
- else
137
- ### Rails 2.1 or lower
138
- def template_exists?(template_name)
139
- finder.file_exists?(template_name)
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
140
128
  end
141
129
  end
142
130
  end
@@ -1,13 +1,5 @@
1
1
  require 'jpmobile/request_with_mobile'
2
2
 
3
- if ::ActionPack::VERSION::MAJOR >=2 and ::ActionPack::VERSION::MINOR >= 3
4
- ### Handle Rails 2.3 case
5
- class ActionController::Request
6
- include Jpmobile::RequestWithMobile
7
- end
8
- else
9
- ### Handle Rails 2.2 or lower case
10
- class ActionController::AbstractRequest
11
- include Jpmobile::RequestWithMobile
12
- end
3
+ class ActionController::Request
4
+ include Jpmobile::RequestWithMobile
13
5
  end