rails-mobile 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.rdoc +181 -0
- data/README.rdoc +271 -0
- data/Rakefile +48 -0
- data/install.rb +1 -0
- data/lib/rails_mobile.rb +22 -0
- data/lib/rails_mobile/application.rb +7 -0
- data/lib/rails_mobile/middleware/mobile_filter.rb +30 -0
- data/lib/rails_mobile/mobile_dispatch/action_dispatch.rb +85 -0
- data/lib/rails_mobile/mobile_dispatch/categories.rb +10 -0
- data/lib/rails_mobile/mobile_dispatch/mobile_matcher.rb +14 -0
- data/lib/rails_mobile/mobile_dispatch/parameters.rb +21 -0
- data/rails/init.rb +3 -0
- data/test/rails_mobile_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +90 -0
data/LICENSE.rdoc
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
== mobilesrepo
|
2
|
+
|
3
|
+
Apache License
|
4
|
+
Version 2.0, January 2004
|
5
|
+
http://www.apache.org/licenses/
|
6
|
+
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8
|
+
|
9
|
+
1. Definitions.
|
10
|
+
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
13
|
+
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
15
|
+
the copyright owner that is granting the License.
|
16
|
+
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
18
|
+
other entities that control, are controlled by, or are under common
|
19
|
+
control with that entity. For the purposes of this definition,
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
21
|
+
direction or management of such entity, whether by contract or
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
24
|
+
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
26
|
+
exercising permissions granted by this License.
|
27
|
+
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
29
|
+
including but not limited to software source code, documentation
|
30
|
+
source, and configuration files.
|
31
|
+
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
33
|
+
transformation or translation of a Source form, including but
|
34
|
+
not limited to compiled object code, generated documentation,
|
35
|
+
and conversions to other media types.
|
36
|
+
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
38
|
+
Object form, made available under the License, as indicated by a
|
39
|
+
copyright notice that is included in or attached to the work
|
40
|
+
(an example is provided in the Appendix below).
|
41
|
+
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
48
|
+
the Work and Derivative Works thereof.
|
49
|
+
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
51
|
+
the original version of the Work and any modifications or additions
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
63
|
+
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
66
|
+
subsequently incorporated within the Work.
|
67
|
+
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
74
|
+
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
80
|
+
where such license applies only to those patent claims licensable
|
81
|
+
by such Contributor that are necessarily infringed by their
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
84
|
+
institute patent litigation against any entity (including a
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
87
|
+
or contributory patent infringement, then any patent licenses
|
88
|
+
granted to You under this License for that Work shall terminate
|
89
|
+
as of the date such litigation is filed.
|
90
|
+
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
93
|
+
modifications, and in Source or Object form, provided that You
|
94
|
+
meet the following conditions:
|
95
|
+
|
96
|
+
(a) You must give any other recipients of the Work or
|
97
|
+
Derivative Works a copy of this License; and
|
98
|
+
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
100
|
+
stating that You changed the files; and
|
101
|
+
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
104
|
+
attribution notices from the Source form of the Work,
|
105
|
+
excluding those notices that do not pertain to any part of
|
106
|
+
the Derivative Works; and
|
107
|
+
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
110
|
+
include a readable copy of the attribution notices contained
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
113
|
+
of the following places: within a NOTICE text file distributed
|
114
|
+
as part of the Derivative Works; within the Source form or
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
116
|
+
within a display generated by the Derivative Works, if and
|
117
|
+
wherever such third-party notices normally appear. The contents
|
118
|
+
of the NOTICE file are for informational purposes only and
|
119
|
+
do not modify the License. You may add Your own attribution
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
122
|
+
that such additional attribution notices cannot be construed
|
123
|
+
as modifying the License.
|
124
|
+
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
126
|
+
may provide additional or different license terms and conditions
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
130
|
+
the conditions stated in this License.
|
131
|
+
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
135
|
+
this License, without any additional terms or conditions.
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
137
|
+
the terms of any separate license agreement you may have executed
|
138
|
+
with Licensor regarding such Contributions.
|
139
|
+
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
142
|
+
except as required for reasonable and customary use in describing the
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
144
|
+
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
154
|
+
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
160
|
+
incidental, or consequential damages of any character arising as a
|
161
|
+
result of this License or out of the use or inability to use the
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
164
|
+
other commercial damages or losses), even if such Contributor
|
165
|
+
has been advised of the possibility of such damages.
|
166
|
+
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
170
|
+
or other liability obligations and/or rights consistent with this
|
171
|
+
License. However, in accepting such obligations, You may act only
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
176
|
+
of your accepting any such warranty or additional liability.
|
177
|
+
|
178
|
+
END OF TERMS AND CONDITIONS
|
179
|
+
|
180
|
+
|
181
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,271 @@
|
|
1
|
+
= Rails Mobile
|
2
|
+
|
3
|
+
== Introduction
|
4
|
+
Rails mobile is a Rails plug-in that adds mobile device recognition and dynamic
|
5
|
+
controller/action switching to Rails.
|
6
|
+
|
7
|
+
The idea behind this plugin is to provide all Rails 3 website a transparent
|
8
|
+
solution to provide mobile version alongside the standard version.
|
9
|
+
With the help of this plug-in the same url (eg. http://company.com/info) can be
|
10
|
+
rendered differently for different devices by categorizing mobile devices into
|
11
|
+
similar groups and then calling a customized controller or action.
|
12
|
+
|
13
|
+
|
14
|
+
== Installation
|
15
|
+
|
16
|
+
gem install rails-mobile
|
17
|
+
|
18
|
+
You also need to add rails-mobile to your Gemfile
|
19
|
+
gem 'rails-mobile', :require => "rails_mobile"
|
20
|
+
|
21
|
+
== Added Functionality
|
22
|
+
|
23
|
+
Rails mobile add mobile related capabilities to Rails 3. In this part we review
|
24
|
+
these capabilities.
|
25
|
+
|
26
|
+
=== Device parameter
|
27
|
+
|
28
|
+
In case a site visitor uses a mobile browser this plugin includes a
|
29
|
+
<b>params[:mobile_device]</b> to the params variable.
|
30
|
+
|
31
|
+
The value of this parameter is a mobile object from <b>mobilesrepo gem</b>.
|
32
|
+
|
33
|
+
=== routing.rb options
|
34
|
+
|
35
|
+
|
36
|
+
==== Classifier methods
|
37
|
+
At the end of the routing.rb we need to add a classification/categorization
|
38
|
+
block. This is where we define a set of functions that can be used by rails to
|
39
|
+
label similar mobile devices under same categories. Later these labels will be
|
40
|
+
used to decide what controller or action should handle a web request.
|
41
|
+
|
42
|
+
MobileDispatch::Categories.add do
|
43
|
+
def mobile_classifier(device)
|
44
|
+
"_mobile"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
This is a the simplest way for defining a classifier. Here this method sends
|
49
|
+
back "_mobile" label for all mobile devices. (The classifier methods only get
|
50
|
+
called when the visitor is on a mobile device)
|
51
|
+
|
52
|
+
You may have as many different classifier-methods as you need and then later mix
|
53
|
+
or match them in your routing configuration.
|
54
|
+
|
55
|
+
==== routing options
|
56
|
+
Rails mobile adds two new options to the match method of routing configuration,
|
57
|
+
:classifier and :mobile_only.
|
58
|
+
:classifier option defines which classifier method should be used for a
|
59
|
+
particular routing.
|
60
|
+
|
61
|
+
eg:
|
62
|
+
match '/photo/:id', :to => "photo#index$", :classifier => :mobile_classifier
|
63
|
+
|
64
|
+
In the above example the :mobile_classifier method gets called every time a
|
65
|
+
mobile user visits '/photo/:id'. Then based on the return value all occurrences
|
66
|
+
of $ will be replaced by that label per request and per user.
|
67
|
+
For instance if the return value is '_mobile' the :to option will be dynamically
|
68
|
+
changed to "photo#index_mobile".
|
69
|
+
In case of a web user the system simply removes all occurrences of '$'.
|
70
|
+
|
71
|
+
This simple mechanism provides a great level of flexibility. We can define
|
72
|
+
classification methods that categories devices in to low-end, high-end, iphone,
|
73
|
+
android, etc and then decide what part of our side needs customized functionality
|
74
|
+
for that group of devices.
|
75
|
+
|
76
|
+
== Example
|
77
|
+
|
78
|
+
RailsMobileApp::Application.routes.draw do
|
79
|
+
|
80
|
+
match "info", :to => "info#index$", :classifier => :mobile_classifier
|
81
|
+
match "mobile", :to => "mobile#index", :mobile_only =>true, :classifier => :mobile_classifier
|
82
|
+
match '/photo/:id', :to => "photo#index$", :classifier => :mobile_classifier
|
83
|
+
get "contact/index$", :classifier => :mobile_classifier
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
MobileDispatch::Categories.add do
|
88
|
+
def mobile_classifier(device)
|
89
|
+
"_mobile"
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
== License
|
95
|
+
|
96
|
+
Apache License
|
97
|
+
Version 2.0, January 2004
|
98
|
+
http://www.apache.org/licenses/
|
99
|
+
|
100
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
101
|
+
|
102
|
+
1. Definitions.
|
103
|
+
|
104
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
105
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
106
|
+
|
107
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
108
|
+
the copyright owner that is granting the License.
|
109
|
+
|
110
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
111
|
+
other entities that control, are controlled by, or are under common
|
112
|
+
control with that entity. For the purposes of this definition,
|
113
|
+
"control" means (i) the power, direct or indirect, to cause the
|
114
|
+
direction or management of such entity, whether by contract or
|
115
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
116
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
117
|
+
|
118
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
119
|
+
exercising permissions granted by this License.
|
120
|
+
|
121
|
+
"Source" form shall mean the preferred form for making modifications,
|
122
|
+
including but not limited to software source code, documentation
|
123
|
+
source, and configuration files.
|
124
|
+
|
125
|
+
"Object" form shall mean any form resulting from mechanical
|
126
|
+
transformation or translation of a Source form, including but
|
127
|
+
not limited to compiled object code, generated documentation,
|
128
|
+
and conversions to other media types.
|
129
|
+
|
130
|
+
"Work" shall mean the work of authorship, whether in Source or
|
131
|
+
Object form, made available under the License, as indicated by a
|
132
|
+
copyright notice that is included in or attached to the work
|
133
|
+
(an example is provided in the Appendix below).
|
134
|
+
|
135
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
136
|
+
form, that is based on (or derived from) the Work and for which the
|
137
|
+
editorial revisions, annotations, elaborations, or other modifications
|
138
|
+
represent, as a whole, an original work of authorship. For the purposes
|
139
|
+
of this License, Derivative Works shall not include works that remain
|
140
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
141
|
+
the Work and Derivative Works thereof.
|
142
|
+
|
143
|
+
"Contribution" shall mean any work of authorship, including
|
144
|
+
the original version of the Work and any modifications or additions
|
145
|
+
to that Work or Derivative Works thereof, that is intentionally
|
146
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
147
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
148
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
149
|
+
means any form of electronic, verbal, or written communication sent
|
150
|
+
to the Licensor or its representatives, including but not limited to
|
151
|
+
communication on electronic mailing lists, source code control systems,
|
152
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
153
|
+
Licensor for the purpose of discussing and improving the Work, but
|
154
|
+
excluding communication that is conspicuously marked or otherwise
|
155
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
156
|
+
|
157
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
158
|
+
on behalf of whom a Contribution has been received by Licensor and
|
159
|
+
subsequently incorporated within the Work.
|
160
|
+
|
161
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
162
|
+
this License, each Contributor hereby grants to You a perpetual,
|
163
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
164
|
+
copyright license to reproduce, prepare Derivative Works of,
|
165
|
+
publicly display, publicly perform, sublicense, and distribute the
|
166
|
+
Work and such Derivative Works in Source or Object form.
|
167
|
+
|
168
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
169
|
+
this License, each Contributor hereby grants to You a perpetual,
|
170
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
171
|
+
(except as stated in this section) patent license to make, have made,
|
172
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
173
|
+
where such license applies only to those patent claims licensable
|
174
|
+
by such Contributor that are necessarily infringed by their
|
175
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
176
|
+
with the Work to which such Contribution(s) was submitted. If You
|
177
|
+
institute patent litigation against any entity (including a
|
178
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
179
|
+
or a Contribution incorporated within the Work constitutes direct
|
180
|
+
or contributory patent infringement, then any patent licenses
|
181
|
+
granted to You under this License for that Work shall terminate
|
182
|
+
as of the date such litigation is filed.
|
183
|
+
|
184
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
185
|
+
Work or Derivative Works thereof in any medium, with or without
|
186
|
+
modifications, and in Source or Object form, provided that You
|
187
|
+
meet the following conditions:
|
188
|
+
|
189
|
+
(a) You must give any other recipients of the Work or
|
190
|
+
Derivative Works a copy of this License; and
|
191
|
+
|
192
|
+
(b) You must cause any modified files to carry prominent notices
|
193
|
+
stating that You changed the files; and
|
194
|
+
|
195
|
+
(c) You must retain, in the Source form of any Derivative Works
|
196
|
+
that You distribute, all copyright, patent, trademark, and
|
197
|
+
attribution notices from the Source form of the Work,
|
198
|
+
excluding those notices that do not pertain to any part of
|
199
|
+
the Derivative Works; and
|
200
|
+
|
201
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
202
|
+
distribution, then any Derivative Works that You distribute must
|
203
|
+
include a readable copy of the attribution notices contained
|
204
|
+
within such NOTICE file, excluding those notices that do not
|
205
|
+
pertain to any part of the Derivative Works, in at least one
|
206
|
+
of the following places: within a NOTICE text file distributed
|
207
|
+
as part of the Derivative Works; within the Source form or
|
208
|
+
documentation, if provided along with the Derivative Works; or,
|
209
|
+
within a display generated by the Derivative Works, if and
|
210
|
+
wherever such third-party notices normally appear. The contents
|
211
|
+
of the NOTICE file are for informational purposes only and
|
212
|
+
do not modify the License. You may add Your own attribution
|
213
|
+
notices within Derivative Works that You distribute, alongside
|
214
|
+
or as an addendum to the NOTICE text from the Work, provided
|
215
|
+
that such additional attribution notices cannot be construed
|
216
|
+
as modifying the License.
|
217
|
+
|
218
|
+
You may add Your own copyright statement to Your modifications and
|
219
|
+
may provide additional or different license terms and conditions
|
220
|
+
for use, reproduction, or distribution of Your modifications, or
|
221
|
+
for any such Derivative Works as a whole, provided Your use,
|
222
|
+
reproduction, and distribution of the Work otherwise complies with
|
223
|
+
the conditions stated in this License.
|
224
|
+
|
225
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
226
|
+
any Contribution intentionally submitted for inclusion in the Work
|
227
|
+
by You to the Licensor shall be under the terms and conditions of
|
228
|
+
this License, without any additional terms or conditions.
|
229
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
230
|
+
the terms of any separate license agreement you may have executed
|
231
|
+
with Licensor regarding such Contributions.
|
232
|
+
|
233
|
+
6. Trademarks. This License does not grant permission to use the trade
|
234
|
+
names, trademarks, service marks, or product names of the Licensor,
|
235
|
+
except as required for reasonable and customary use in describing the
|
236
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
237
|
+
|
238
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
239
|
+
agreed to in writing, Licensor provides the Work (and each
|
240
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
241
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
242
|
+
implied, including, without limitation, any warranties or conditions
|
243
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
244
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
245
|
+
appropriateness of using or redistributing the Work and assume any
|
246
|
+
risks associated with Your exercise of permissions under this License.
|
247
|
+
|
248
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
249
|
+
whether in tort (including negligence), contract, or otherwise,
|
250
|
+
unless required by applicable law (such as deliberate and grossly
|
251
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
252
|
+
liable to You for damages, including any direct, indirect, special,
|
253
|
+
incidental, or consequential damages of any character arising as a
|
254
|
+
result of this License or out of the use or inability to use the
|
255
|
+
Work (including but not limited to damages for loss of goodwill,
|
256
|
+
work stoppage, computer failure or malfunction, or any and all
|
257
|
+
other commercial damages or losses), even if such Contributor
|
258
|
+
has been advised of the possibility of such damages.
|
259
|
+
|
260
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
261
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
262
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
263
|
+
or other liability obligations and/or rights consistent with this
|
264
|
+
License. However, in accepting such obligations, You may act only
|
265
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
266
|
+
of any other Contributor, and only if You agree to indemnify,
|
267
|
+
defend, and hold each Contributor harmless for any liability
|
268
|
+
incurred by, or claims asserted against, such Contributor by reason
|
269
|
+
of your accepting any such warranty or additional liability.
|
270
|
+
|
271
|
+
END OF TERMS AND CONDITIONS
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
#require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/gempackagetask'
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
PKG_FILES = FileList[
|
12
|
+
'[a-zA-Z]*',
|
13
|
+
'generators/**/*',
|
14
|
+
'lib/**/*',
|
15
|
+
'rails/**/*',
|
16
|
+
'tasks/**/*',
|
17
|
+
'test/**/*'
|
18
|
+
]
|
19
|
+
|
20
|
+
spec = Gem::Specification.new do |s|
|
21
|
+
s.name = "rails-mobile"
|
22
|
+
s.version = "0.9.1"
|
23
|
+
s.author = "Reza Alavi"
|
24
|
+
s.email = "rezaalavi@rubyforge.org"
|
25
|
+
s.homepage = "https://github.com/rezaalavi/Rails-Mobile"
|
26
|
+
s.platform = Gem::Platform::RUBY
|
27
|
+
s.rubyforge_project = "rails-mobile"
|
28
|
+
s.summary = "Rails mobile is a Rails plug-in that adds mobile device recognition and dynamic controller/action switching to Rails."
|
29
|
+
s.files = PKG_FILES.to_a
|
30
|
+
s.require_path = "lib"
|
31
|
+
s.has_rdoc = false
|
32
|
+
s.add_dependency('mobilesrepo')
|
33
|
+
s.extra_rdoc_files = ['README.rdoc']
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Turn this plugin into a gem.'
|
37
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
38
|
+
pkg.gem_spec = spec
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Generate documentation for the rails_mobile plugin.'
|
42
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = 'RailsMobile'
|
45
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
46
|
+
rdoc.rdoc_files.include('README')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/rails_mobile.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module RailsMobilePlugin
|
2
|
+
# namespace our plugin and inherit from Rails::Railtie
|
3
|
+
# to get our plugin into the initialization process
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
|
6
|
+
# configure our plugin on boot. other extension points such
|
7
|
+
# as configuration, rake tasks, etc, are also available
|
8
|
+
initializer "railsmobilenewplugin.initialize" do |app|
|
9
|
+
require "rails_mobile/application"
|
10
|
+
require "rails_mobile/mobile_dispatch/mobile_matcher"
|
11
|
+
require "rails_mobile/mobile_dispatch/action_dispatch"
|
12
|
+
require "rails_mobile/mobile_dispatch/categories"
|
13
|
+
require "rails_mobile/mobile_dispatch/parameters"
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
require 'mobiles/device_locator'
|
3
|
+
class MobileFilter
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
|
11
|
+
user_agent = env.fetch "HTTP_USER_AGENT",nil
|
12
|
+
unless user_agent.nil?
|
13
|
+
user_device = Mobiles::DeviceLocator.find_device_by_user_agent(user_agent)
|
14
|
+
unless user_device.nil?
|
15
|
+
params = env.fetch "action_dispatch.request.mobile_device",nil
|
16
|
+
if params.nil?
|
17
|
+
params = Hash.new
|
18
|
+
end
|
19
|
+
params.update :mobile_device => user_device
|
20
|
+
|
21
|
+
env.update "action_dispatch.request.mobile_device" => params
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
@app.call(env)
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module ActionDispatch
|
2
|
+
module Routing
|
3
|
+
|
4
|
+
class Mapper
|
5
|
+
|
6
|
+
def match(*args)
|
7
|
+
options = nil
|
8
|
+
path = nil
|
9
|
+
if args.size == 1 && args.last.is_a?(Hash)
|
10
|
+
options = args.pop
|
11
|
+
path, to = options.find { |name, value| name.is_a?(String) }
|
12
|
+
options.merge!(:to => to).delete(path)
|
13
|
+
|
14
|
+
else
|
15
|
+
path = args.shift
|
16
|
+
options = args.pop
|
17
|
+
|
18
|
+
end
|
19
|
+
if options.nil?
|
20
|
+
super path
|
21
|
+
else
|
22
|
+
if options.fetch(:classifier,nil).nil?
|
23
|
+
super path,options
|
24
|
+
else
|
25
|
+
|
26
|
+
mobile_only = options.fetch(:mobile_only,false)
|
27
|
+
|
28
|
+
if mobile_only
|
29
|
+
options.update({:constraints => MobileMatcher.new})
|
30
|
+
end
|
31
|
+
|
32
|
+
options.update({:to => mobile_dispatch(path,options) })
|
33
|
+
super path.gsub(/\$/,''), options
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
|
44
|
+
def mobile_dispatch(path,options)
|
45
|
+
original_to = options.fetch(:to,nil)
|
46
|
+
if original_to.nil?
|
47
|
+
original_to = path.gsub(/\//, '#')
|
48
|
+
end
|
49
|
+
classifier = options.fetch(:classifier)
|
50
|
+
|
51
|
+
|
52
|
+
proc do |env|
|
53
|
+
|
54
|
+
device = mobile_device env
|
55
|
+
to_str = original_to.gsub(/\$/,'')
|
56
|
+
|
57
|
+
unless device.nil?
|
58
|
+
classifier_method = method(classifier)
|
59
|
+
device_category = classifier_method.call(device)
|
60
|
+
to_str = original_to.gsub(/\$/,device_category)
|
61
|
+
end
|
62
|
+
|
63
|
+
controller_name,action_name = to_str.split('#')
|
64
|
+
controller = controller_reference(controller_name)
|
65
|
+
controller.action(action_name).call(env)
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
def controller_reference(controller_param)
|
70
|
+
controller_name = "#{controller_param.camelize}Controller"
|
71
|
+
puts "controller_name #{controller_name}"
|
72
|
+
controller = ActiveSupport::Dependencies.ref(controller_name)
|
73
|
+
controller.get
|
74
|
+
end
|
75
|
+
def mobile_device(env)
|
76
|
+
env.fetch "action_dispatch.request.mobile_device",nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActionDispatch
|
2
|
+
module Http
|
3
|
+
module Parameters
|
4
|
+
# Returns both GET and POST \parameters in a single hash.
|
5
|
+
def parameters
|
6
|
+
@env["action_dispatch.request.parameters"] ||= begin
|
7
|
+
params = request_parameters.merge(query_parameters)
|
8
|
+
params.merge!(path_parameters)
|
9
|
+
unless mobile_device_paramter.nil?
|
10
|
+
params.merge!(mobile_device_paramter)
|
11
|
+
end
|
12
|
+
encode_params(params).with_indifferent_access
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def mobile_device_paramter
|
17
|
+
@env["action_dispatch.request.mobile_device"]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/rails/init.rb
ADDED
data/test/test_helper.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-mobile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
- 1
|
9
|
+
version: 0.9.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Reza Alavi
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-30 00:00:00 +11:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: mobilesrepo
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
description:
|
34
|
+
email: rezaalavi@rubyforge.org
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files:
|
40
|
+
- README.rdoc
|
41
|
+
files:
|
42
|
+
- install.rb
|
43
|
+
- LICENSE.rdoc
|
44
|
+
- Rakefile
|
45
|
+
- README.rdoc
|
46
|
+
- uninstall.rb
|
47
|
+
- lib/rails_mobile/application.rb
|
48
|
+
- lib/rails_mobile/middleware/mobile_filter.rb
|
49
|
+
- lib/rails_mobile/mobile_dispatch/action_dispatch.rb
|
50
|
+
- lib/rails_mobile/mobile_dispatch/categories.rb
|
51
|
+
- lib/rails_mobile/mobile_dispatch/mobile_matcher.rb
|
52
|
+
- lib/rails_mobile/mobile_dispatch/parameters.rb
|
53
|
+
- lib/rails_mobile.rb
|
54
|
+
- rails/init.rb
|
55
|
+
- test/rails_mobile_test.rb
|
56
|
+
- test/test_helper.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: https://github.com/rezaalavi/Rails-Mobile
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project: rails-mobile
|
85
|
+
rubygems_version: 1.3.7
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Rails mobile is a Rails plug-in that adds mobile device recognition and dynamic controller/action switching to Rails.
|
89
|
+
test_files: []
|
90
|
+
|