mobylette 2.2.rc1 → 2.2.rc2

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,8 @@ http://tscolari.github.com/mobylette/mobylette_images/mobylette.jpg
8
8
  Mobylette 1.6+ only supports Ruby 1.9.2+
9
9
  For Ruby 1.8.7 support, please use version < 1.6
10
10
 
11
- = Mobylette http://travis-ci.org/tscolari/mobylette.png
11
+ = Mobylette
12
+ {<img src="https://secure.travis-ci.org/tscolari/mobylette.png" />}[http://travis-ci.org/tscolari/mobylette]
12
13
 
13
14
  This gem works by adding the 'mobile' format to your rails application. Whenever a request come from a mobile device, if you have your controller mobile enabled, it shall render the view.mobile.erb instead of the view.html.erb (or haml, or whatever).
14
15
 
@@ -1,8 +1,9 @@
1
1
  #
2
2
  # Rails automatic mobile request support
3
3
  module Mobylette
4
- require "mobylette/respond_to_mobile_requests"
4
+ require 'mobylette/respond_to_mobile_requests'
5
5
  require 'mobylette/fallback_resolver'
6
+ require 'mobylette/mobile_user_agents'
6
7
 
7
8
  # TestHelpers
8
9
  # require "mobylette/helmet"
@@ -12,4 +13,4 @@ end
12
13
 
13
14
  # Creating the :mobile format alias
14
15
  require 'action_controller'
15
- Mime::Type.register_alias "text/html", :mobile
16
+ Mime::Type.register_alias 'text/html', :mobile
@@ -1,22 +1,42 @@
1
1
  module Mobylette
2
2
 
3
- # Creates a fallback from mobile to another format
3
+ # This manages the fall back from mobile views
4
+ # It only interfers on requests where the format is :mobile,
5
+ # and in case there is no view for the mobile format, it
6
+ # will fall back to the any other format that is configurated.
7
+ #
8
+ # When you insert Mobylette::RespondToMobileRequests to a
9
+ # controller, this class will be the new resolver for that
10
+ # controller.
11
+ #
12
+ # By default this resolver will not fallback to any format.
13
+ # Only is @fallback_to is configurated (by use_fallback)
14
+ #
15
+ # You should not use this by yourself unless you know what
16
+ # you are doing.
4
17
  #
5
18
  # Examples:
6
19
  #
7
- # append_view_path Mobylette::FallbackResolver.new('app/views')
20
+ # class SomeController < ApplicationController
21
+ # append_view_path Mobylette::FallbackResolver.new
22
+ # end
8
23
  #
9
- # Returns:
10
24
  #
11
- # if a .mobile view is not found it will look for a .html view
25
+ # ...
26
+ # my_controller_resolver = Mobylette::FallbackResolver.new
27
+ # my_controller_resolver.use_fallback(:html)
28
+ # ...
12
29
  #
13
30
  class FallbackResolver < ::ActionView::FileSystemResolver
14
31
 
32
+ def initialize
33
+ super('app/views')
34
+ end
35
+
15
36
  # Public: Configures what fallback the resolver should use
16
37
  #
17
38
  # - fallback:
18
- # * :default => Falls back to the original request format
19
- # * :html/:js/:xml => Falls back to the format
39
+ # * :html/:js/:xml/... => Falls back to that format
20
40
  #
21
41
  def use_fallback(fallback)
22
42
  @fallback_to = fallback
@@ -26,13 +46,8 @@ module Mobylette
26
46
  # using fallback if needed
27
47
  #
28
48
  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)
49
+ details[:formats] = Array.wrap(fallback_list) if details[:formats].first == :mobile
50
+ super
36
51
  end
37
52
 
38
53
  private
@@ -0,0 +1,10 @@
1
+ module Mobylette
2
+ # List of mobile agents
3
+ #
4
+ MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
5
+ 'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
6
+ 'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' +
7
+ 'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' +
8
+ 'webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|' +
9
+ 'mobile|maemo|fennec'
10
+ end
@@ -1,8 +1,29 @@
1
1
  module Mobylette
2
- # Mobylette::Controllers::RespondToMobileRequests includes the respond_to_mobile_requests
3
- # to your ActionController::Base.
2
+ # Defines the behavior for responding to mobile requests with a different view.
3
+ #
4
+ # By including this to a controller, it will automaticaly look for a .mobile view
5
+ # instead of a .html, when the request comes from a mobile device.
6
+ #
7
+ # Usage:
8
+ #
9
+ # class AppicationController < ActionController::Base
10
+ # include Mobylette::RespondToMobileRequests
11
+ # end
12
+ #
13
+ #
14
+ # You can define some options:
15
+ #
16
+ # class...
17
+ # include Mobylette::RespondToMobileRequests
18
+ # mobylette_config do |config|
19
+ # config[:fall_back] = :html
20
+ # config[:skip_xhr_requests] = false
21
+ # end
22
+ # ...
23
+ # end
24
+ #
25
+ # note: By default it will already fall back to the :html format
4
26
  #
5
- # The respond_to_mobile_requests method enables the controller mobile handling
6
27
  module RespondToMobileRequests
7
28
  extend ActiveSupport::Concern
8
29
 
@@ -18,20 +39,13 @@ module Mobylette
18
39
  @@mobylette_options[:fall_back] = :html
19
40
 
20
41
  cattr_accessor :mobylette_fallback_resolver
21
- self.mobylette_fallback_resolver = Mobylette::FallbackResolver.new('app/views')
42
+ self.mobylette_fallback_resolver = Mobylette::FallbackResolver.new
22
43
  self.mobylette_fallback_resolver.use_fallback(@@mobylette_options[:fall_back])
23
44
  append_view_path self.mobylette_fallback_resolver
24
-
25
- # List of mobile agents, from mobile_fu (https://github.com/brendanlim/mobile-fu)
26
- #
27
- MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
28
- 'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
29
- 'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' +
30
- 'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' +
31
- 'webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|' +
32
- 'mobile|maemo|fennec'
33
45
  end
34
46
 
47
+
48
+
35
49
  module ClassMethods
36
50
  # This method enables the controller do handle mobile requests
37
51
  #
@@ -74,7 +88,7 @@ module Mobylette
74
88
  # Private: Tells if the request comes from a mobile user_agent or not
75
89
  #
76
90
  def is_mobile_request?
77
- request.user_agent.to_s.downcase =~ /#{MOBILE_USER_AGENTS}/
91
+ request.user_agent.to_s.downcase =~ /#{Mobylette::MOBILE_USER_AGENTS}/
78
92
  end
79
93
 
80
94
  # :doc:
@@ -1,3 +1,3 @@
1
1
  module Mobylette
2
- VERSION = "2.2.rc1"
2
+ VERSION = "2.2.rc2"
3
3
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  module Mobylette
4
4
  describe FallbackResolver do
5
5
 
6
- subject { FallbackResolver.new('app/views') }
6
+ subject { FallbackResolver.new }
7
7
 
8
8
  describe "#fallback_list" do
9
9
 
@@ -22,5 +22,32 @@ module Mobylette
22
22
  end
23
23
  end
24
24
 
25
+ describe "#find_templates" do
26
+ before(:each) do
27
+ @formats = []
28
+ Array.stub(:wrap).and_return(@formats)
29
+ @details = {:formats => []}
30
+ end
31
+
32
+ context "mobile request" do
33
+ before(:each) { @details[:formats] = [:mobile] }
34
+
35
+ it "should set the details[:formats]" do
36
+ Array.should_receive(:wrap)
37
+ subject.find_templates('', '', '', @details)
38
+ @details[:formats].should == @formats
39
+ end
40
+ end
41
+
42
+ context "normal request" do
43
+ before(:each) { @details[:formats] = [:html] }
44
+
45
+ it "should not set the details[:formats]" do
46
+ subject.find_templates('', '', '', @details)
47
+ @details[:formats].should == [:html]
48
+ end
49
+ end
50
+ end
51
+
25
52
  end
26
53
  end
@@ -36,7 +36,7 @@ module Mobylette
36
36
  subject.send(:is_mobile_request?).should be_false
37
37
  end
38
38
 
39
- RespondToMobileRequests::MOBILE_USER_AGENTS.split('|').each do |agent|
39
+ Mobylette::MOBILE_USER_AGENTS.split('|').each do |agent|
40
40
  agent.gsub!('\.', '.') # Ugly rack... but otherwise this will fail for up.b
41
41
  it "should be true for the agent #{agent}" do
42
42
  subject.stub_chain(:request, :user_agent).and_return(agent)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobylette
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.rc1
4
+ version: 2.2.rc2
5
5
  prerelease: 4
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
16
- requirement: &70219511332780 !ruby/object:Gem::Requirement
16
+ requirement: &70194941379380 !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: *70219511332780
24
+ version_requirements: *70194941379380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70219511331560 !ruby/object:Gem::Requirement
27
+ requirement: &70194941378280 !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: *70219511331560
35
+ version_requirements: *70194941378280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &70219511347220 !ruby/object:Gem::Requirement
38
+ requirement: &70194941377260 !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: *70219511347220
46
+ version_requirements: *70194941377260
47
47
  description: Adds the mobile format for rendering views for mobile device.
48
48
  email:
49
49
  - tscolari@gmail.com
@@ -54,6 +54,7 @@ files:
54
54
  - config/initializers/responders.rb
55
55
  - lib/mobylette/fallback_resolver.rb
56
56
  - lib/mobylette/helmet.rb
57
+ - lib/mobylette/mobile_user_agents.rb
57
58
  - lib/mobylette/railtie.rb
58
59
  - lib/mobylette/respond_to_mobile_requests.rb
59
60
  - lib/mobylette/version.rb
@@ -153,7 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
154
  version: '0'
154
155
  segments:
155
156
  - 0
156
- hash: 2077747218505376093
157
+ hash: -1627627498843530674
157
158
  required_rubygems_version: !ruby/object:Gem::Requirement
158
159
  none: false
159
160
  requirements: