mobile-fu 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +47 -24
- data/lib/mobile-fu.rb +6 -6
- data/lib/mobile-fu/version.rb +1 -1
- metadata +9 -4
data/README.md
CHANGED
@@ -16,41 +16,58 @@ Usage
|
|
16
16
|
|
17
17
|
Add this this one line to the controller.
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
```ruby
|
20
|
+
class ApplicationController < ActionController::Base
|
21
|
+
has_mobile_fu
|
22
|
+
end
|
23
|
+
```
|
22
24
|
|
23
25
|
Once this is in place, any request that comes from a mobile device will be be
|
24
26
|
set as :mobile format. It is up to you to determine how you want to handle
|
25
27
|
these requests. It is also up to you to create the .mobile.erb versions of
|
26
28
|
your views that are to be requested.
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
+
If you do not want to set the format to :mobile or :tablet and only use the
|
31
|
+
helper functions, pass false as an argument.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class ApplicationController < ActionController::Base
|
35
|
+
has_mobile_fu false
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Mobile Fu automatically adds a new `:mobile` and `:tablet` to `text/html` mime type
|
40
|
+
alias for Rails apps. If you already have a custom `:mobile` alias registered in
|
30
41
|
`config/initializers/mime_types.rb`, you can remove that.
|
31
42
|
|
32
43
|
I recommend that you setup a before_filter that will redirect to a specific page
|
33
44
|
depending on whether or not it is a mobile request. How can you check this?
|
34
45
|
|
35
|
-
|
46
|
+
```ruby
|
47
|
+
is_mobile_device? # => Returns true or false depending on the device or
|
36
48
|
|
37
|
-
|
49
|
+
is_tablet_device? # => Returns true if the device is a tablet
|
50
|
+
```
|
38
51
|
|
39
52
|
You can also determine which format is currently set in by calling the following:
|
40
53
|
|
41
|
-
|
54
|
+
```ruby
|
55
|
+
in_mobile_view? # => Returns true or false depending on current req. format or
|
42
56
|
|
43
|
-
|
57
|
+
in_tablet_view? # => Returns true if the current req. format is for tablet view
|
58
|
+
```
|
44
59
|
|
45
60
|
Also, if you want the ability to allow a user to switch between 'mobile' and
|
46
61
|
'standard' format (:html), you can just adjust the mobile_view session variable
|
47
62
|
in a custom controller action.
|
48
63
|
|
49
|
-
|
50
|
-
|
64
|
+
```ruby
|
65
|
+
session[:mobile_view] # => Set to true if request format is :mobile and false
|
66
|
+
if set to :html
|
51
67
|
|
52
|
-
|
53
|
-
|
68
|
+
session[:tablet_view] # => Set to true if request format is :tablet and false
|
69
|
+
if set to :html
|
70
|
+
```
|
54
71
|
|
55
72
|
So, different devices need different styling. Don't worry, we've got this
|
56
73
|
baked in to Mobile Fu.
|
@@ -60,11 +77,13 @@ to do is add _device to the name of one of your files to override your styling
|
|
60
77
|
for a certain device. The stylesheet that is loaded is dependant on which device
|
61
78
|
is making the request.
|
62
79
|
|
63
|
-
|
80
|
+
e.g., Accessing a page from a Blackberry.
|
64
81
|
|
65
|
-
|
82
|
+
```ruby
|
83
|
+
stylesheet_link_tag 'mobile.css'
|
84
|
+
```
|
66
85
|
|
67
|
-
|
86
|
+
This loads mobile.css, and mobile_blackberry.css if the file exists.
|
68
87
|
|
69
88
|
Supported stylesheet override device extensions at the moment are:
|
70
89
|
|
@@ -88,16 +107,20 @@ Testing Mobile Interface
|
|
88
107
|
If you want to force the mobile interface for testing, you can either use a
|
89
108
|
mobile device emulator, or you can call `force_mobile_format` in a before filter.
|
90
109
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
110
|
+
```ruby
|
111
|
+
class ApplicationController < ActionController::Base
|
112
|
+
has_mobile_fu
|
113
|
+
before_filter :force_mobile_format
|
114
|
+
end
|
115
|
+
```
|
95
116
|
|
96
117
|
You can also force the tablet view by calling `force_tablet_format` instead
|
97
118
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
119
|
+
```ruby
|
120
|
+
class ApplicationController < ActionController::Base
|
121
|
+
has_mobile_fu
|
122
|
+
before_filter :force_tablet_format
|
123
|
+
end
|
124
|
+
```
|
102
125
|
|
103
126
|
Copyright (c) 2008 Brendan G. Lim, Intridea, Inc., released under the MIT license
|
data/lib/mobile-fu.rb
CHANGED
@@ -70,11 +70,11 @@ module ActionController
|
|
70
70
|
# Add this to your controllers to prevent the mobile format from being set for specific actions
|
71
71
|
# class AwesomeController < ApplicationController
|
72
72
|
# has_no_mobile_fu_for :index
|
73
|
-
#
|
73
|
+
#
|
74
74
|
# def index
|
75
75
|
# # Mobile format will not be set, even if user is on a mobile device
|
76
76
|
# end
|
77
|
-
#
|
77
|
+
#
|
78
78
|
# def show
|
79
79
|
# # Mobile format will be set as normal here if user is on a mobile device
|
80
80
|
# end
|
@@ -139,12 +139,12 @@ module ActionController
|
|
139
139
|
# Returns either true or false depending on whether or not the user agent of
|
140
140
|
# the device making the request is matched to a device in our regex.
|
141
141
|
|
142
|
-
def
|
143
|
-
!!
|
142
|
+
def is_tablet_device?
|
143
|
+
!!(request.user_agent.to_s.downcase =~ Regexp.new(ActionController::MobileFu::TABLET_USER_AGENTS))
|
144
144
|
end
|
145
145
|
|
146
|
-
def
|
147
|
-
|
146
|
+
def is_mobile_device?
|
147
|
+
!is_tablet_device? && !!mobile_device
|
148
148
|
end
|
149
149
|
|
150
150
|
def mobile_device
|
data/lib/mobile-fu/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobile-fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-11-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -106,19 +106,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
- - ! '>='
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
hash: -851634981796251436
|
109
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
113
|
none: false
|
111
114
|
requirements:
|
112
115
|
- - ! '>='
|
113
116
|
- !ruby/object:Gem::Version
|
114
117
|
version: '0'
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
hash: -851634981796251436
|
115
121
|
requirements: []
|
116
122
|
rubyforge_project: mobile-fu
|
117
|
-
rubygems_version: 1.8.
|
123
|
+
rubygems_version: 1.8.24
|
118
124
|
signing_key:
|
119
125
|
specification_version: 3
|
120
126
|
summary: Automatically detect mobile requests from mobile devices in your Rails application.
|
121
127
|
test_files:
|
122
128
|
- spec/mobilized_styles_spec.rb
|
123
129
|
- spec/spec_helper.rb
|
124
|
-
has_rdoc:
|