mobile_path 0.1.0 → 0.2.0

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 CHANGED
@@ -30,6 +30,17 @@ You can override some of the defaults in your config/initializers/ folder like s
30
30
  config.mobile_device_regex = /(iPhone|Android)/
31
31
  end
32
32
 
33
+ Configure your environment for appropriate top level domain length such as the following examples
34
+
35
+ development.rb
36
+ # lvh.me = this is an alias for localhost
37
+ config.action_dispatch.tld_length=1
38
+
39
+ others
40
+
41
+ # staging.mysite.com
42
+ # config.action_dispatch.tld_length=2
43
+
33
44
  Usage
34
45
  -----
35
46
 
@@ -25,7 +25,12 @@ module MobilePath
25
25
  @@defaults = {
26
26
  :subdomain => 'm',
27
27
  :mobile_view_path => "mobile_views",
28
- :mobile_device_regex => /(iPhone|iPod|iPad|Android)/
28
+ :mobile_device_regex => /('palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
29
+ 'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
30
+ 'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' +
31
+ 'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' +
32
+ 'webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|' +
33
+ 'mobile')/i
29
34
  }
30
35
 
31
36
  def self.defaults
@@ -0,0 +1,3 @@
1
+ module MobilePath
2
+ VERSION = "0.2.0"
3
+ end
data/lib/mobile_path.rb CHANGED
@@ -20,10 +20,10 @@ require 'active_support/concern'
20
20
  require 'mobile_path/configuration'
21
21
 
22
22
  module MobilePath
23
-
23
+
24
24
  extend ActiveSupport::Concern
25
25
 
26
- included do
26
+ included do
27
27
  before_filter :toggle_mobile_preference_cookie
28
28
  before_filter :redirect_to_mobile_if_applicable
29
29
  before_filter :prepend_view_path_if_mobile
@@ -31,35 +31,35 @@ module MobilePath
31
31
 
32
32
 
33
33
  module InstanceMethods
34
-
34
+
35
35
  private
36
-
36
+
37
37
  #
38
38
  # checks if the requesting user agent is a mobile browser. The devices
39
39
  # that return true can be configured with the mobile_device_regex.
40
40
  def mobile_browser?
41
- user_agent && user_agent[MobilePath.config.mobile_device_regex]
41
+ user_agent && user_agent[MobilePath.config.mobile_device_regex].present?
42
42
  end
43
-
43
+
44
44
  #
45
45
  # Checks if the incoming request is using the mobile subdomain.
46
46
  def mobile_request?
47
- request.subdomains.first == mobile_subdomain
47
+ (mobile_subdomain.present? && request.subdomains.first == mobile_subdomain) || mobile_browser?
48
48
  end
49
-
49
+
50
50
  #
51
51
  # The subdomain for the application can be configured. This method
52
52
  # just caches the subdomain in case it is used more than once per request.
53
53
  def mobile_subdomain
54
54
  @mobile_subdomain ||= MobilePath.config.subdomain
55
- end
56
-
57
-
55
+ end
56
+
57
+
58
58
  #
59
59
  # The view path that is prepended can be configured with mobile_view_path.
60
- def mobile_view_path
60
+ def mobile_view_path
61
61
  @mobile_view_path ||= MobilePath.config.mobile_view_path
62
- end
62
+ end
63
63
 
64
64
  #
65
65
  # If the request is for a mobile device, prepend the configured mobile view
@@ -72,21 +72,29 @@ module MobilePath
72
72
 
73
73
  #
74
74
  # Remove the mobile sudomain from the request path and redirect.
75
+ # Make sure to set the correct told lenght in environment configuration
76
+ # lvh.me
77
+ # config.action_dispatch.tld_length=1
78
+ # staging.mysite.com
79
+ # config.action_dispatch.tld_length=2
75
80
  def redirect_to_full_site
76
- redirect_to request.protocol + request.host_with_port.gsub(mobile_subdomain, '') +
77
- request.fullpath and return
81
+ redirect_to [request.protocol, request.domain, request.port_string, request.fullpath].join and return
78
82
  end
79
83
 
80
84
  #
81
85
  # Remove www. and add the mobile submomain to the request and redirect
82
86
  def redirect_to_mobile
83
- redirect_to request.protocol + mobile_subdomain + "." + request.host_with_port.gsub(/^www\./, '') + request.fullpath
87
+ redirect_to [request.protocol,
88
+ mobile_subdomain, "." ,
89
+ request.domain,
90
+ request.port_string,
91
+ request.fullpath].join and return if mobile_subdomain.present?
84
92
  end
85
93
 
86
94
  #
87
95
  # If a request is mobile and the user doesn't prefer the full-site, redirect to the mobile site.
88
96
  def redirect_to_mobile_if_applicable
89
- unless mobile_request? || cookies[:prefer_full_site] || !mobile_browser?
97
+ unless !mobile_request? || cookies[:prefer_full_site].present?
90
98
  redirect_to_mobile and return
91
99
  end
92
100
  end
@@ -98,15 +106,14 @@ module MobilePath
98
106
  cookies.delete(:prefer_full_site)
99
107
  elsif params[:full_site]
100
108
  cookies.permanent[:prefer_full_site] = 1
101
- redirect_to_full_site if mobile_request?
102
109
  end
103
110
  end
104
-
111
+
105
112
  #
106
113
  # wrapper for the request HTTP user agent.
107
114
  def user_agent
108
115
  @user_agent ||= request.env["HTTP_USER_AGENT"]
109
116
  end
110
117
  end
111
-
112
- end
118
+
119
+ end
metadata CHANGED
@@ -1,217 +1,156 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mobile_path
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - patricksrobertson
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-05-23 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rails
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70112691525380 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- version: "3.0"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rspec
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70112691525380
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70112691524900 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
29
+ requirements:
42
30
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 23
45
- segments:
46
- - 2
47
- - 6
48
- - 0
31
+ - !ruby/object:Gem::Version
49
32
  version: 2.6.0
50
33
  type: :development
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: rspec-rails
54
34
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70112691524900
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-rails
38
+ requirement: &70112691524420 !ruby/object:Gem::Requirement
56
39
  none: false
57
- requirements:
40
+ requirements:
58
41
  - - ~>
59
- - !ruby/object:Gem::Version
60
- hash: 23
61
- segments:
62
- - 2
63
- - 6
64
- - 0
42
+ - !ruby/object:Gem::Version
65
43
  version: 2.6.0
66
44
  type: :development
67
- version_requirements: *id003
68
- - !ruby/object:Gem::Dependency
69
- name: yard
70
45
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70112691524420
47
+ - !ruby/object:Gem::Dependency
48
+ name: yard
49
+ requirement: &70112691523940 !ruby/object:Gem::Requirement
72
50
  none: false
73
- requirements:
51
+ requirements:
74
52
  - - ~>
75
- - !ruby/object:Gem::Version
76
- hash: 7
77
- segments:
78
- - 0
79
- - 6
80
- - 0
53
+ - !ruby/object:Gem::Version
81
54
  version: 0.6.0
82
55
  type: :development
83
- version_requirements: *id004
84
- - !ruby/object:Gem::Dependency
85
- name: bundler
86
56
  prerelease: false
87
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *70112691523940
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: &70112691523460 !ruby/object:Gem::Requirement
88
61
  none: false
89
- requirements:
62
+ requirements:
90
63
  - - ~>
91
- - !ruby/object:Gem::Version
92
- hash: 23
93
- segments:
94
- - 1
95
- - 0
96
- - 0
64
+ - !ruby/object:Gem::Version
97
65
  version: 1.0.0
98
66
  type: :development
99
- version_requirements: *id005
100
- - !ruby/object:Gem::Dependency
101
- name: jeweler
102
67
  prerelease: false
103
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *70112691523460
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &70112691522980 !ruby/object:Gem::Requirement
104
72
  none: false
105
- requirements:
73
+ requirements:
106
74
  - - ~>
107
- - !ruby/object:Gem::Version
108
- hash: 15
109
- segments:
110
- - 1
111
- - 6
112
- - 0
75
+ - !ruby/object:Gem::Version
113
76
  version: 1.6.0
114
77
  type: :development
115
- version_requirements: *id006
116
- - !ruby/object:Gem::Dependency
117
- name: rcov
118
78
  prerelease: false
119
- requirement: &id007 !ruby/object:Gem::Requirement
79
+ version_requirements: *70112691522980
80
+ - !ruby/object:Gem::Dependency
81
+ name: rcov
82
+ requirement: &70112691522500 !ruby/object:Gem::Requirement
120
83
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- hash: 3
125
- segments:
126
- - 0
127
- version: "0"
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
128
88
  type: :development
129
- version_requirements: *id007
130
- - !ruby/object:Gem::Dependency
131
- name: diesel
132
89
  prerelease: false
133
- requirement: &id008 !ruby/object:Gem::Requirement
90
+ version_requirements: *70112691522500
91
+ - !ruby/object:Gem::Dependency
92
+ name: diesel
93
+ requirement: &70112691522020 !ruby/object:Gem::Requirement
134
94
  none: false
135
- requirements:
95
+ requirements:
136
96
  - - ~>
137
- - !ruby/object:Gem::Version
138
- hash: 9
139
- segments:
140
- - 0
141
- - 1
142
- version: "0.1"
97
+ - !ruby/object:Gem::Version
98
+ version: '0.1'
143
99
  type: :development
144
- version_requirements: *id008
145
- - !ruby/object:Gem::Dependency
146
- name: sqlite3
147
100
  prerelease: false
148
- requirement: &id009 !ruby/object:Gem::Requirement
101
+ version_requirements: *70112691522020
102
+ - !ruby/object:Gem::Dependency
103
+ name: sqlite3
104
+ requirement: &70112691521540 !ruby/object:Gem::Requirement
149
105
  none: false
150
- requirements:
151
- - - ">="
152
- - !ruby/object:Gem::Version
153
- hash: 3
154
- segments:
155
- - 0
156
- version: "0"
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
157
110
  type: :development
158
- version_requirements: *id009
159
- description: Mobile Path provides you with a mobile sub-domain and a new view path for mobile content.
111
+ prerelease: false
112
+ version_requirements: *70112691521540
113
+ description: Mobile Path provides you with a mobile sub-domain and a new view path
114
+ for mobile content.
160
115
  email: patrick.robertson@velir.com
161
116
  executables: []
162
-
163
117
  extensions: []
164
-
165
- extra_rdoc_files:
118
+ extra_rdoc_files:
166
119
  - LICENSE.txt
167
120
  - README.md
168
- files:
169
- - .document
170
- - .rspec
121
+ files:
171
122
  - Gemfile
172
123
  - Gemfile.lock
173
124
  - LICENSE.txt
174
- - README.md
175
125
  - Rakefile
126
+ - README.md
176
127
  - VERSION
177
- - lib/mobile_path.rb
178
128
  - lib/mobile_path/configuration.rb
179
- - mobile_path.gemspec
180
- - spec/controllers/application_controller_spec.rb
181
- - spec/spec_helper.rb
182
- has_rdoc: true
129
+ - lib/mobile_path/version.rb
130
+ - lib/mobile_path.rb
183
131
  homepage: http://github.com/Velir/mobile_path
184
- licenses:
132
+ licenses:
185
133
  - MIT
186
134
  post_install_message:
187
135
  rdoc_options: []
188
-
189
- require_paths:
136
+ require_paths:
190
137
  - lib
191
- required_ruby_version: !ruby/object:Gem::Requirement
138
+ required_ruby_version: !ruby/object:Gem::Requirement
192
139
  none: false
193
- requirements:
194
- - - ">="
195
- - !ruby/object:Gem::Version
196
- hash: 3
197
- segments:
198
- - 0
199
- version: "0"
200
- required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
145
  none: false
202
- requirements:
203
- - - ">="
204
- - !ruby/object:Gem::Version
205
- hash: 3
206
- segments:
207
- - 0
208
- version: "0"
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
209
150
  requirements: []
210
-
211
151
  rubyforge_project:
212
- rubygems_version: 1.6.2
152
+ rubygems_version: 1.8.6
213
153
  signing_key:
214
154
  specification_version: 3
215
155
  summary: Simple way to give your Rails app mobile views.
216
156
  test_files: []
217
-
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/mobile_path.gemspec DELETED
@@ -1,76 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{mobile_path}
8
- s.version = "0.1.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["patricksrobertson"]
12
- s.date = %q{2011-05-23}
13
- s.description = %q{Mobile Path provides you with a mobile sub-domain and a new view path for mobile content.}
14
- s.email = %q{patrick.robertson@velir.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".rspec",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "LICENSE.txt",
25
- "README.md",
26
- "Rakefile",
27
- "VERSION",
28
- "lib/mobile_path.rb",
29
- "lib/mobile_path/configuration.rb",
30
- "mobile_path.gemspec",
31
- "spec/controllers/application_controller_spec.rb",
32
- "spec/spec_helper.rb"
33
- ]
34
- s.homepage = %q{http://github.com/Velir/mobile_path}
35
- s.licenses = ["MIT"]
36
- s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.6.2}
38
- s.summary = %q{Simple way to give your Rails app mobile views.}
39
-
40
- if s.respond_to? :specification_version then
41
- s.specification_version = 3
42
-
43
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
- s.add_runtime_dependency(%q<rails>, ["~> 3.0"])
45
- s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
46
- s.add_development_dependency(%q<rspec-rails>, ["~> 2.6.0"])
47
- s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
48
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
50
- s.add_development_dependency(%q<rcov>, [">= 0"])
51
- s.add_development_dependency(%q<diesel>, ["~> 0.1"])
52
- s.add_development_dependency(%q<sqlite3>, [">= 0"])
53
- else
54
- s.add_dependency(%q<rails>, ["~> 3.0"])
55
- s.add_dependency(%q<rspec>, ["~> 2.6.0"])
56
- s.add_dependency(%q<rspec-rails>, ["~> 2.6.0"])
57
- s.add_dependency(%q<yard>, ["~> 0.6.0"])
58
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
- s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
60
- s.add_dependency(%q<rcov>, [">= 0"])
61
- s.add_dependency(%q<diesel>, ["~> 0.1"])
62
- s.add_dependency(%q<sqlite3>, [">= 0"])
63
- end
64
- else
65
- s.add_dependency(%q<rails>, ["~> 3.0"])
66
- s.add_dependency(%q<rspec>, ["~> 2.6.0"])
67
- s.add_dependency(%q<rspec-rails>, ["~> 2.6.0"])
68
- s.add_dependency(%q<yard>, ["~> 0.6.0"])
69
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
70
- s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
71
- s.add_dependency(%q<rcov>, [">= 0"])
72
- s.add_dependency(%q<diesel>, ["~> 0.1"])
73
- s.add_dependency(%q<sqlite3>, [">= 0"])
74
- end
75
- end
76
-
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ApplicationController do
4
- controller do
5
- def index
6
- render :nothing => true
7
- end
8
- end
9
-
10
- describe "GET 'index'" do
11
- it "should redirect to a mobile domain when given an appropriate user agent" do
12
- request.env["HTTP_USER_AGENT"] = "Mozilla/5.0 (iPhone; U; XXXXX like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/241 Safari/419.3 |"
13
- get :index
14
- response.location.split("http://")[1].split(".")[0].should eq(MobilePath.config.subdomain)
15
- end
16
-
17
- it "should redirect to a configured domain as well." do
18
- request.env["HTTP_USER_AGENT"] = "Mozilla/5.0 (iPhone; U; XXXXX like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/241 Safari/419.3 |"
19
- MobilePath.configure do |config|
20
- config.subdomain = "mobizzle"
21
- end
22
- get :index
23
- response.location.split("http://")[1].split(".")[0].should eq("mobizzle")
24
- end
25
-
26
- it "shouldn't redirect on a normal user agent" do
27
- request.env["HTTP_USER_AGENT"] = "Test"
28
- get :index
29
- response.location.should be_false
30
- end
31
-
32
- it "shouldn't redirect on a mobile user agent with a full_site param" do
33
- request.env["HTTP_USER_AGENT"] = "Mozilla/5.0 (iPhone; U; XXXXX like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/241 Safari/419.3 |"
34
- get :index, {:full_site => true}
35
- response.location.should be_false
36
-
37
- get :index, {:mobile_site => true}
38
- response.location.split("http://")[1].split(".")[0].should eq(MobilePath.config.subdomain)
39
- end
40
-
41
- end
42
-
43
- end
data/spec/spec_helper.rb DELETED
@@ -1,19 +0,0 @@
1
- ENV["RAILS_ENV"] ||= 'test'
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
- require 'rspec'
5
- require 'mobile_path'
6
- require 'rails/all'
7
- require 'rspec/rails'
8
- require 'diesel/testing'
9
-
10
- # Requires supporting files with custom matchers and macros, etc,
11
- # in ./support/ and its subdirectories.
12
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
13
-
14
- class ApplicationController < ActionController::Base
15
- include MobilePath
16
- end
17
-
18
- RSpec.configure do |config|
19
- end