mobylette 2.1 → 2.2.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -5
- data/lib/mobylette.rb +1 -0
- data/lib/mobylette/fallback_resolver.rb +50 -0
- data/lib/mobylette/respond_to_mobile_requests.rb +10 -8
- data/lib/mobylette/version.rb +1 -1
- data/spec/lib/fallback_resolver_spec.rb +26 -0
- data/spec/lib/respond_to_mobile_requests_spec.rb +0 -11
- metadata +15 -15
data/README.rdoc
CHANGED
@@ -29,7 +29,7 @@ Add the gem to your gemfile:
|
|
29
29
|
|
30
30
|
And add to your ApplicationController.rb (for enabling it to all your controllers) or to the controllers you want this functionality on:
|
31
31
|
|
32
|
-
include
|
32
|
+
include Mobylette::RespondToMobileRequests
|
33
33
|
|
34
34
|
After that, you may start adding your .mobile. views.
|
35
35
|
|
@@ -49,22 +49,22 @@ There is a difference between is_mobile_view? and is_mobile_request?. You may ha
|
|
49
49
|
|
50
50
|
== Configuration
|
51
51
|
|
52
|
-
You can set the configuration with the
|
52
|
+
You can set the configuration with the mobylette_config method:
|
53
53
|
|
54
54
|
mobylette_config do |config|
|
55
|
-
config[:fall_back] =
|
55
|
+
config[:fall_back] = false
|
56
56
|
config[:skip_xhr_requests] = false
|
57
57
|
end
|
58
58
|
|
59
59
|
== Fall Backs
|
60
60
|
|
61
|
-
By default, when the mobile format is not found, mobylette will fall back to the
|
61
|
+
By default, when the mobile format is not found, mobylette will fall back to the html format. You may force it to fall back to another format, by setting the :fall_back option on your controller:
|
62
62
|
|
63
63
|
mobylette_config do |config|
|
64
64
|
config[:fall_back] = :html
|
65
65
|
end
|
66
66
|
|
67
|
-
This would force all views (mobile) to fall back to the html views. You may also disable
|
67
|
+
This would force all views (mobile) to fall back to the html views. You may also disable fall backs:
|
68
68
|
|
69
69
|
mobylette_config do |config|
|
70
70
|
config[:fall_back] = false
|
data/lib/mobylette.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Mobylette
|
2
|
+
|
3
|
+
# Creates a fallback from mobile to another format
|
4
|
+
#
|
5
|
+
# Examples:
|
6
|
+
#
|
7
|
+
# append_view_path Mobylette::FallbackResolver.new('app/views')
|
8
|
+
#
|
9
|
+
# Returns:
|
10
|
+
#
|
11
|
+
# if a .mobile view is not found it will look for a .html view
|
12
|
+
#
|
13
|
+
class FallbackResolver < ::ActionView::FileSystemResolver
|
14
|
+
|
15
|
+
# Public: Configures what fallback the resolver should use
|
16
|
+
#
|
17
|
+
# - fallback:
|
18
|
+
# * :default => Falls back to the original request format
|
19
|
+
# * :html/:js/:xml => Falls back to the format
|
20
|
+
#
|
21
|
+
def use_fallback(fallback)
|
22
|
+
@fallback_to = fallback
|
23
|
+
end
|
24
|
+
|
25
|
+
# Public: finds the right template on the filesystem,
|
26
|
+
# using fallback if needed
|
27
|
+
#
|
28
|
+
def find_templates(name, prefix, partial, details)
|
29
|
+
return super unless details[:formats].first == :mobile
|
30
|
+
|
31
|
+
formats = Array.wrap(fallback_list)
|
32
|
+
details_copy = details.dup
|
33
|
+
details_copy[:formats] = formats
|
34
|
+
path = Path.build(name, prefix, partial)
|
35
|
+
query(path, details_copy, formats)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# Private: formats array, in fall back order
|
41
|
+
#
|
42
|
+
def fallback_list
|
43
|
+
if @fallback_to
|
44
|
+
[:mobile, @fallback_to.to_sym]
|
45
|
+
else
|
46
|
+
[:mobile]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -15,7 +15,12 @@ module Mobylette
|
|
15
15
|
cattr_accessor :mobylette_options
|
16
16
|
@@mobylette_options = Hash.new
|
17
17
|
@@mobylette_options[:skip_xhr_requests] = true
|
18
|
-
@@mobylette_options[:fall_back] =
|
18
|
+
@@mobylette_options[:fall_back] = :html
|
19
|
+
|
20
|
+
cattr_accessor :mobylette_fallback_resolver
|
21
|
+
self.mobylette_fallback_resolver = Mobylette::FallbackResolver.new('app/views')
|
22
|
+
self.mobylette_fallback_resolver.use_fallback(@@mobylette_options[:fall_back])
|
23
|
+
append_view_path self.mobylette_fallback_resolver
|
19
24
|
|
20
25
|
# List of mobile agents, from mobile_fu (https://github.com/brendanlim/mobile-fu)
|
21
26
|
#
|
@@ -37,7 +42,7 @@ module Mobylette
|
|
37
42
|
# * fall_back: :html
|
38
43
|
# You may pass a fall_back option to the method, it will force the render
|
39
44
|
# to look for that other format, in case there is not a .mobile file for the view.
|
40
|
-
# By default, it will fall back to the format
|
45
|
+
# By default, it will fall back to the html format.
|
41
46
|
# If you don't want fall back at all, pass fall_back: false
|
42
47
|
# * skip_xhr_requests: true/false
|
43
48
|
# By default this is set to true. When a xhr request enters in, it will skip the
|
@@ -59,6 +64,7 @@ module Mobylette
|
|
59
64
|
#
|
60
65
|
def mobylette_config
|
61
66
|
yield(self.mobylette_options)
|
67
|
+
self.mobylette_fallback_resolver.use_fallback(self.mobylette_options[:fall_back])
|
62
68
|
end
|
63
69
|
end
|
64
70
|
|
@@ -122,13 +128,9 @@ module Mobylette
|
|
122
128
|
#
|
123
129
|
def handle_mobile
|
124
130
|
return if session[:mobylette_override] == :ignore_mobile
|
125
|
-
if respond_as_mobile?
|
126
131
|
|
127
|
-
|
128
|
-
request.format
|
129
|
-
if self.mobylette_options[:fall_back] != false
|
130
|
-
request.formats << Mime::Type.new(self.mobylette_options[:fall_back] || original_format)
|
131
|
-
end
|
132
|
+
if respond_as_mobile?
|
133
|
+
request.format = :mobile
|
132
134
|
end
|
133
135
|
end
|
134
136
|
|
data/lib/mobylette/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Mobylette
|
4
|
+
describe FallbackResolver do
|
5
|
+
|
6
|
+
subject { FallbackResolver.new('app/views') }
|
7
|
+
|
8
|
+
describe "#fallback_list" do
|
9
|
+
|
10
|
+
context "when use_fallback is set to false" do
|
11
|
+
it "should return only :mobile" do
|
12
|
+
subject.use_fallback(false)
|
13
|
+
subject.send(:fallback_list).should == [:mobile]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when use_fallback is set to any value" do
|
18
|
+
it "should return :mobile and the use_fallback value" do
|
19
|
+
subject.use_fallback(:somestuff)
|
20
|
+
subject.send(:fallback_list).should == [:mobile, :somestuff]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -236,17 +236,6 @@ module Mobylette
|
|
236
236
|
@format.should == :mobile
|
237
237
|
end
|
238
238
|
|
239
|
-
it "should have a fall back to the original format when fall_back is nil" do
|
240
|
-
subject.mobylette_options[:fall_back] = nil
|
241
|
-
subject.send(:handle_mobile)
|
242
|
-
@formats.include?(Mime::Type.new :old_format).should be_true
|
243
|
-
end
|
244
|
-
|
245
|
-
it "should have a fall back to :html when fall_back is :html" do
|
246
|
-
subject.mobylette_options[:fall_back] = :html
|
247
|
-
subject.send(:handle_mobile)
|
248
|
-
@formats.include?(Mime::Type.new :html).should be_true
|
249
|
-
end
|
250
239
|
end
|
251
240
|
end
|
252
241
|
end
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobylette
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.2.rc1
|
5
|
+
prerelease: 4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tiago Scolari
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70219511332780 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70219511332780
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70219511331560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70219511331560
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec-rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &70219511347220 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70219511347220
|
47
47
|
description: Adds the mobile format for rendering views for mobile device.
|
48
48
|
email:
|
49
49
|
- tscolari@gmail.com
|
@@ -52,6 +52,7 @@ extensions: []
|
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
54
|
- config/initializers/responders.rb
|
55
|
+
- lib/mobylette/fallback_resolver.rb
|
55
56
|
- lib/mobylette/helmet.rb
|
56
57
|
- lib/mobylette/railtie.rb
|
57
58
|
- lib/mobylette/respond_to_mobile_requests.rb
|
@@ -132,6 +133,7 @@ files:
|
|
132
133
|
- spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384
|
133
134
|
- spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
|
134
135
|
- spec/integration/navigation_spec.rb
|
136
|
+
- spec/lib/fallback_resolver_spec.rb
|
135
137
|
- spec/lib/respond_to_mobile_requests_spec.rb
|
136
138
|
- spec/mobylette_spec.rb
|
137
139
|
- spec/spec_helper.rb
|
@@ -151,16 +153,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
153
|
version: '0'
|
152
154
|
segments:
|
153
155
|
- 0
|
154
|
-
hash:
|
156
|
+
hash: 2077747218505376093
|
155
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
158
|
none: false
|
157
159
|
requirements:
|
158
|
-
- - ! '
|
160
|
+
- - ! '>'
|
159
161
|
- !ruby/object:Gem::Version
|
160
|
-
version:
|
161
|
-
segments:
|
162
|
-
- 0
|
163
|
-
hash: -3922416622570358250
|
162
|
+
version: 1.3.1
|
164
163
|
requirements: []
|
165
164
|
rubyforge_project:
|
166
165
|
rubygems_version: 1.8.10
|
@@ -239,6 +238,7 @@ test_files:
|
|
239
238
|
- spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384
|
240
239
|
- spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
|
241
240
|
- spec/integration/navigation_spec.rb
|
241
|
+
- spec/lib/fallback_resolver_spec.rb
|
242
242
|
- spec/lib/respond_to_mobile_requests_spec.rb
|
243
243
|
- spec/mobylette_spec.rb
|
244
244
|
- spec/spec_helper.rb
|