mobile-fu 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eec8e6c6d23829759304cd7265e7ec8f15ba159e
4
+ data.tar.gz: 766d897636d26203c5fa56f16c3ae1aa933bdb37
5
+ SHA512:
6
+ metadata.gz: f113d5ca4f26d7e11e79185485202144cf4154edaf220df8b88da24b9e98ea2c4bdc8b6e0ceedf273707b17682fe84f2d4225a91f3f8067298c360d8bf78e25e
7
+ data.tar.gz: 6a634c597c1b1b3054bff34d1b3a6bbb832e3795044dddf50343c5ee7f08b87c68fb4dec4a0b7b30286461b48dbeb698c0b5175afa262616cb10016f7baa8167
data/README.md CHANGED
@@ -36,6 +36,24 @@ class ApplicationController < ActionController::Base
36
36
  end
37
37
  ```
38
38
 
39
+ If you dont want to have all the methods respond to :mobile and :tablet, you can opt-in this actions
40
+ using the following class method: `has_mobile_fu_for :action`
41
+ Example:
42
+
43
+ ```ruby
44
+ class YourAwesomeClass < ActionController::Base
45
+ has_mobile_fu
46
+ has_mobile_fu_for :index
47
+
48
+ def index
49
+ # Mobile format will be set as normal here if user is on a mobile device
50
+ end
51
+
52
+ def another_method
53
+ # Mobile format will not be set, even if user is on a mobile device
54
+ end
55
+ ```
56
+
39
57
  Mobile Fu automatically adds a new `:mobile` and `:tablet` to `text/html` mime type
40
58
  alias for Rails apps. If you already have a custom `:mobile` alias registered in
41
59
  `config/initializers/mime_types.rb`, you can remove that.
@@ -69,6 +87,21 @@ session[:tablet_view] # => Set to true if request format is :tablet and false
69
87
  if set to :html
70
88
  ```
71
89
 
90
+ If you want to use the default response templates, like index.html.erb, instead of the index.tablet.erb you can
91
+ exclude the tablet rendering from beeing used:
92
+ you can create a `before_filter` and put it before the has_mobile_fu call
93
+
94
+ ```ruby
95
+ before_filter :force_tablet_html
96
+ has_mobile_fu
97
+
98
+ def force_tablet_html
99
+ session[:tablet_view] = false
100
+ end
101
+ ```
102
+
103
+ Same will work for mobile, just change the `tablet` values to `mobile`
104
+
72
105
  So, different devices need different styling. Don't worry, we've got this
73
106
  baked in to Mobile Fu.
74
107
 
@@ -33,7 +33,7 @@ module ActionController
33
33
  module MobileFu
34
34
  # These are various strings that can be found in tablet devices. Please feel free
35
35
  # to add on to this list.
36
- TABLET_USER_AGENTS = 'ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle|honeycomb'
36
+ TABLET_USER_AGENTS = /ipad|android 3.0|xoom|sch-i800|gt-p1000|playbook|tablet|kindle|honeycomb|nexus 7/.freeze
37
37
 
38
38
  def self.included(base)
39
39
  base.extend ClassMethods
@@ -82,6 +82,23 @@ module ActionController
82
82
  def has_no_mobile_fu_for(*actions)
83
83
  @mobile_exempt_actions = actions
84
84
  end
85
+
86
+ # Add this to your controllers to only let those actions use the mobile format
87
+ # this method has priority over the #has_no_mobile_fu_for
88
+ # class AwesomeController < ApplicationController
89
+ # has_mobile_fu_for :index
90
+ #
91
+ # def index
92
+ # # Mobile format will be set as normal here if user is on a mobile device
93
+ # end
94
+ #
95
+ # def show
96
+ # # Mobile format will not be set, even if user is on a mobile device
97
+ # end
98
+ # end
99
+ def has_mobile_fu_for(*actions)
100
+ @mobile_include_actions = actions
101
+ end
85
102
  end
86
103
 
87
104
  module InstanceMethods
@@ -111,10 +128,10 @@ module ActionController
111
128
  # 'Tablet' view.
112
129
 
113
130
  def set_mobile_format
114
- if !mobile_exempt? && is_mobile_device? && !request.xhr?
131
+ if request.format.html? && !mobile_action? && is_mobile_device? && !request.xhr?
115
132
  request.format = :mobile unless session[:mobile_view] == false
116
133
  session[:mobile_view] = true if session[:mobile_view].nil?
117
- elsif !mobile_exempt? && is_tablet_device? && !request.xhr?
134
+ elsif request.format.html? && !mobile_action? && is_tablet_device? && !request.xhr?
118
135
  request.format = :tablet unless session[:tablet_view] == false
119
136
  session[:tablet_view] = true if session[:tablet_view].nil?
120
137
  end
@@ -140,7 +157,7 @@ module ActionController
140
157
  # the device making the request is matched to a device in our regex.
141
158
 
142
159
  def is_tablet_device?
143
- !!(request.user_agent.to_s.downcase =~ Regexp.new(ActionController::MobileFu::TABLET_USER_AGENTS))
160
+ !!(request.user_agent.to_s.downcase =~ ActionController::MobileFu::TABLET_USER_AGENTS)
144
161
  end
145
162
 
146
163
  def is_mobile_device?
@@ -158,6 +175,16 @@ module ActionController
158
175
  request.user_agent.to_s.downcase.include? type.to_s.downcase
159
176
  end
160
177
 
178
+ # Returns true if current action is supposed to use mobile format
179
+ # See #has_mobile_fu_for
180
+ def mobile_action?
181
+ if self.class.instance_variable_get("@mobile_include_actions").nil? #Now we know we dont have any includes, maybe excludes?
182
+ return mobile_exempt?
183
+ else
184
+ self.class.instance_variable_get("@mobile_include_actions").try(:include?, params[:action].to_sym)
185
+ end
186
+ end
187
+
161
188
  # Returns true if current action isn't supposed to use mobile format
162
189
  # See #has_no_mobile_fu_for
163
190
 
@@ -1,7 +1,9 @@
1
1
  module MobileFu
2
2
  module Helper
3
+ JS_ENABLED_DEVICES = %w{iphone ipod ipad mobileexplorer android zune}
4
+
3
5
  def js_enabled_mobile_device?
4
- is_device?('iphone') || is_device?('ipod') || is_device?('ipad') || is_device?('mobileexplorer') || is_device?('android')
6
+ JS_ENABLED_DEVICES.find { |device| is_device? device }
5
7
  end
6
8
 
7
9
  def stylesheet_link_tag_with_mobilization(*sources)
@@ -1,3 +1,3 @@
1
1
  module MobileFu
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobile-fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brendan Lim
@@ -10,70 +9,62 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-11-15 00:00:00.000000000 Z
12
+ date: 2013-06-04 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rails
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: '0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rack-mobile-detect
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: rspec
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: rdoc
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - '>='
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - '>='
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0'
79
70
  description: Want to automatically detect mobile devices that access your Rails application?
@@ -96,33 +87,26 @@ files:
96
87
  - spec/spec_helper.rb
97
88
  homepage: https://github.com/benlangfeld/mobile-fu
98
89
  licenses: []
90
+ metadata: {}
99
91
  post_install_message:
100
92
  rdoc_options: []
101
93
  require_paths:
102
94
  - lib
103
95
  required_ruby_version: !ruby/object:Gem::Requirement
104
- none: false
105
96
  requirements:
106
- - - ! '>='
97
+ - - '>='
107
98
  - !ruby/object:Gem::Version
108
99
  version: '0'
109
- segments:
110
- - 0
111
- hash: -851634981796251436
112
100
  required_rubygems_version: !ruby/object:Gem::Requirement
113
- none: false
114
101
  requirements:
115
- - - ! '>='
102
+ - - '>='
116
103
  - !ruby/object:Gem::Version
117
104
  version: '0'
118
- segments:
119
- - 0
120
- hash: -851634981796251436
121
105
  requirements: []
122
106
  rubyforge_project: mobile-fu
123
- rubygems_version: 1.8.24
107
+ rubygems_version: 2.0.3
124
108
  signing_key:
125
- specification_version: 3
109
+ specification_version: 4
126
110
  summary: Automatically detect mobile requests from mobile devices in your Rails application.
127
111
  test_files:
128
112
  - spec/mobilized_styles_spec.rb