File: README.md

package info (click to toggle)
ruby-mobile-fu 1.4.0%2Bgithub-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 152 kB
  • sloc: ruby: 206; makefile: 2
file content (159 lines) | stat: -rw-r--r-- 4,813 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
Mobile Fu
=========

Want to automatically detect mobile devices that access your Rails application?
Mobile Fu allows you to do just that.  People can access your site from a Palm,
Blackberry, iPhone, iPad, Nokia, etc. and it will automatically adjust the format
of the request from :html to :mobile or :tablet.

Installation
------------

Simply add `gem 'mobile-fu'` to your Gemfile and run bundle install.

Usage
-----

Add this this one line to the controller.

```ruby
class ApplicationController < ActionController::Base
  has_mobile_fu
end
```

Once this is in place, any request that comes from a mobile device will be
set as :mobile format.  It is up to you to determine how you want to handle
these requests.  It is also up to you to create the .mobile.erb versions of
your views that are to be requested.

If you do not want to set the format to :mobile or :tablet and only use the
helper functions, pass false as an argument.

```ruby
class ApplicationController < ActionController::Base
  has_mobile_fu false
end
```

If you dont want to have all the methods respond to :mobile and :tablet, you can opt-in this actions
using the following class method: `has_mobile_fu_for :action`
Example:

```ruby
class YourAwesomeClass < ActionController::Base
  has_mobile_fu
  has_mobile_fu_for :index

  def index
    # Mobile format will be set as normal here if user is on a mobile device
  end

  def another_method
    # Mobile format will not be set, even if user is on a mobile device
  end
```

Mobile Fu automatically adds a new `:mobile` and `:tablet` to `text/html` mime type
alias for Rails apps. If you already have a custom `:mobile` alias registered in
`config/initializers/mime_types.rb`, you can remove that.

I recommend that you setup a before_filter that will redirect to a specific page
depending on whether or not it is a mobile request.  How can you check this?

```ruby
is_mobile_device? # => Returns true or false depending on the device or

is_tablet_device? # => Returns true if the device is a tablet
```

You can also determine which format is currently set in by calling the following:

```ruby
in_mobile_view? # => Returns true or false depending on current req. format or

in_tablet_view? # => Returns true if the current req. format is for tablet view
```

Also, if you want the ability to allow a user to switch between 'mobile' and
'standard' format (:html), you can just adjust the mobile_view session variable
in a custom controller action.

```ruby
session[:mobile_view] # => Set to true if request format is :mobile and false
                           if set to :html

session[:tablet_view] # => Set to true if request format is :tablet and false
                           if set to :html
```

If you want to use the default response templates, like index.html.erb, instead of the index.tablet.erb you can
exclude the tablet rendering from beeing used:
you can create a `before_filter` and put it before the has_mobile_fu call

```ruby
before_filter :force_tablet_html
has_mobile_fu

def force_tablet_html
	session[:tablet_view] = false
end
```

Same will work for mobile, just change the `tablet` values to `mobile`

So, different devices need different styling.  Don't worry, we've got this
baked in to Mobile Fu.

If you are including a css or sass file via `stylesheet_link_tag`, all you have
to do is add _device to the name of one of your files to override your styling
for a certain device.  The stylesheet that is loaded is dependant on which device
is making the request.

e.g., Accessing a page from a Blackberry.

```ruby
stylesheet_link_tag 'mobile.css'
```

This loads mobile.css, and mobile_blackberry.css if the file exists.

Supported stylesheet override device extensions at the moment are:

  * blackberry
  * iphone (iphone,ipod)
  * ipad
  * android
  * mobileexplorer
  * nokia
  * palm

The stylesheet awesomeness was derived from [Michael Bleigh's browserized styles](http://www.intridea.com/2007/12/9/announcing-browserized-styles)

Inspiration for Mobile Fu came from [Noel Rappin's rails_iui](http://blogs.pathf.com/agileajax/2008/05/rails-developme.html)

Hopefully this should help you create some awesome mobile applications.

Testing Mobile Interface
------------------------

If you want to force the mobile interface for testing, you can either use a
mobile device emulator, or you can call `force_mobile_format` in a before filter.

```ruby
class ApplicationController < ActionController::Base
  has_mobile_fu
  before_filter :force_mobile_format
end
```

You can also force the tablet view by calling `force_tablet_format` instead

```ruby
class ApplicationController < ActionController::Base
  has_mobile_fu
  before_filter :force_tablet_format
end
```

Copyright (c) 2008 Brendan G. Lim, Intridea, Inc., released under the MIT license