mobile_path 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +103 -0
- data/LICENSE.txt +20 -0
- data/README.md +71 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/lib/mobile_path/configuration.rb +50 -0
- data/lib/mobile_path.rb +112 -0
- data/mobile_path.gemspec +76 -0
- data/spec/controllers/application_controller_spec.rb +43 -0
- data/spec/spec_helper.rb +19 -0
- metadata +217 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem "rails", "~> 3.0"
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem "rspec", "~> 2.6.0"
|
7
|
+
gem "rspec-rails", "~> 2.6.0"
|
8
|
+
gem "yard", "~> 0.6.0"
|
9
|
+
gem "bundler", "~> 1.0.0"
|
10
|
+
gem "jeweler", "~> 1.6.0"
|
11
|
+
gem "rcov", ">= 0"
|
12
|
+
gem "diesel", "~> 0.1"
|
13
|
+
gem "sqlite3"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.7)
|
6
|
+
actionpack (= 3.0.7)
|
7
|
+
mail (~> 2.2.15)
|
8
|
+
actionpack (3.0.7)
|
9
|
+
activemodel (= 3.0.7)
|
10
|
+
activesupport (= 3.0.7)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.14)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.7)
|
19
|
+
activesupport (= 3.0.7)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.5.0)
|
22
|
+
activerecord (3.0.7)
|
23
|
+
activemodel (= 3.0.7)
|
24
|
+
activesupport (= 3.0.7)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.7)
|
28
|
+
activemodel (= 3.0.7)
|
29
|
+
activesupport (= 3.0.7)
|
30
|
+
activesupport (3.0.7)
|
31
|
+
arel (2.0.10)
|
32
|
+
builder (2.1.2)
|
33
|
+
diesel (0.1.4)
|
34
|
+
railties (~> 3.0.3)
|
35
|
+
diff-lcs (1.1.2)
|
36
|
+
erubis (2.6.6)
|
37
|
+
abstract (>= 1.0.0)
|
38
|
+
git (1.2.5)
|
39
|
+
i18n (0.5.0)
|
40
|
+
jeweler (1.6.0)
|
41
|
+
bundler (~> 1.0.0)
|
42
|
+
git (>= 1.2.5)
|
43
|
+
rake
|
44
|
+
mail (2.2.19)
|
45
|
+
activesupport (>= 2.3.6)
|
46
|
+
i18n (>= 0.4.0)
|
47
|
+
mime-types (~> 1.16)
|
48
|
+
treetop (~> 1.4.8)
|
49
|
+
mime-types (1.16)
|
50
|
+
polyglot (0.3.1)
|
51
|
+
rack (1.2.3)
|
52
|
+
rack-mount (0.6.14)
|
53
|
+
rack (>= 1.0.0)
|
54
|
+
rack-test (0.5.7)
|
55
|
+
rack (>= 1.0)
|
56
|
+
rails (3.0.7)
|
57
|
+
actionmailer (= 3.0.7)
|
58
|
+
actionpack (= 3.0.7)
|
59
|
+
activerecord (= 3.0.7)
|
60
|
+
activeresource (= 3.0.7)
|
61
|
+
activesupport (= 3.0.7)
|
62
|
+
bundler (~> 1.0)
|
63
|
+
railties (= 3.0.7)
|
64
|
+
railties (3.0.7)
|
65
|
+
actionpack (= 3.0.7)
|
66
|
+
activesupport (= 3.0.7)
|
67
|
+
rake (>= 0.8.7)
|
68
|
+
thor (~> 0.14.4)
|
69
|
+
rake (0.9.0)
|
70
|
+
rcov (0.9.9)
|
71
|
+
rspec (2.6.0)
|
72
|
+
rspec-core (~> 2.6.0)
|
73
|
+
rspec-expectations (~> 2.6.0)
|
74
|
+
rspec-mocks (~> 2.6.0)
|
75
|
+
rspec-core (2.6.0)
|
76
|
+
rspec-expectations (2.6.0)
|
77
|
+
diff-lcs (~> 1.1.2)
|
78
|
+
rspec-mocks (2.6.0)
|
79
|
+
rspec-rails (2.6.0)
|
80
|
+
actionpack (~> 3.0)
|
81
|
+
activesupport (~> 3.0)
|
82
|
+
railties (~> 3.0)
|
83
|
+
rspec (~> 2.6.0)
|
84
|
+
sqlite3 (1.3.3)
|
85
|
+
thor (0.14.6)
|
86
|
+
treetop (1.4.9)
|
87
|
+
polyglot (>= 0.3.1)
|
88
|
+
tzinfo (0.3.27)
|
89
|
+
yard (0.6.8)
|
90
|
+
|
91
|
+
PLATFORMS
|
92
|
+
ruby
|
93
|
+
|
94
|
+
DEPENDENCIES
|
95
|
+
bundler (~> 1.0.0)
|
96
|
+
diesel (~> 0.1)
|
97
|
+
jeweler (~> 1.6.0)
|
98
|
+
rails (~> 3.0)
|
99
|
+
rcov
|
100
|
+
rspec (~> 2.6.0)
|
101
|
+
rspec-rails (~> 2.6.0)
|
102
|
+
sqlite3
|
103
|
+
yard (~> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Velir
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
Mobile Path
|
2
|
+
--------------
|
3
|
+
**Homepage**: [http://www.velir.com](http://www.velir.com)
|
4
|
+
**Author**: [Patrick Robertson](mailto:patrick.robertson@velir.com)
|
5
|
+
**Copyright**: 2011
|
6
|
+
**License**: [MIT License](file:LICENSE.txt)
|
7
|
+
|
8
|
+
About Mobile Path
|
9
|
+
-----------------
|
10
|
+
|
11
|
+
Mobile Path is a really simple gem for giving your Rails application a separate view path and subdomain specifically for mobile devices. It takes a different approach to mobile views than [mobile_fu](https://github.com/brendanlim/mobile-fu) for a couple of reasons:
|
12
|
+
|
13
|
+
* The .mobile.erb methodology doesn't work out with JQuery Mobile and I sort of like JQueryMobile.
|
14
|
+
* If all you need is a new layout, it's frustrating to write a pile of .mobile.erb views. Mobile Path drops back to
|
15
|
+
your already defined view_path gracefully.
|
16
|
+
|
17
|
+
Installation
|
18
|
+
------------
|
19
|
+
Mobile Path is only suitable for Rails 3.0+ apps. You can add it to your Gemfile like so:
|
20
|
+
|
21
|
+
#Gemfile
|
22
|
+
gem "mobile_path"
|
23
|
+
|
24
|
+
You can override some of the defaults in your config/initializers/ folder like so:
|
25
|
+
|
26
|
+
#config/initializers/mobile_path.rb
|
27
|
+
MobilePath.configure do |config|
|
28
|
+
config.subdomain = "mobile"
|
29
|
+
config.mobile_view_path = "mobizzle"
|
30
|
+
config.mobile_device_regex = /(iPhone|Android)/
|
31
|
+
end
|
32
|
+
|
33
|
+
Usage
|
34
|
+
-----
|
35
|
+
|
36
|
+
You can include this bad boy right into your ApplicationController like so:
|
37
|
+
|
38
|
+
#app/controllers/application_controller.rb
|
39
|
+
ApplicationController < ActionController::Base
|
40
|
+
include MobilePath
|
41
|
+
end
|
42
|
+
I'd rather give you the capability to explicitly include the file rather than insert it
|
43
|
+
into ActionController::Base for you. You may only want to only use mobile views for your
|
44
|
+
admin panel, or have some use case I don't foresee.
|
45
|
+
|
46
|
+
For any views you'd like to make mobile you'll then just need to add them to app/mobile_views/ .
|
47
|
+
You can change the folder that Mobile Path will prepend to the view_path as mentioned earlier.
|
48
|
+
|
49
|
+
If you'd like to let users swap between the normal/mobile layouts, you'll need links similar to this:
|
50
|
+
|
51
|
+
<%= link_to "View full site", url_for(:full_site => 1) %>
|
52
|
+
<%= link_to "View mobile site", url_for(:mobile_site => 1) if mobile_browser? %>
|
53
|
+
|
54
|
+
|
55
|
+
Contributing to mobile_path
|
56
|
+
---------------------------
|
57
|
+
|
58
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
59
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
60
|
+
* Fork the project
|
61
|
+
* Start a feature/bugfix branch
|
62
|
+
* Commit and push until you are happy with your contribution
|
63
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
64
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
65
|
+
|
66
|
+
Copyright
|
67
|
+
---------
|
68
|
+
|
69
|
+
Copyright (c) 2011 Velir. See LICENSE.txt for
|
70
|
+
further details.
|
71
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "mobile_path"
|
18
|
+
gem.homepage = "http://github.com/Velir/mobile_path"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "Simple way to give your Rails app mobile views."
|
21
|
+
gem.description = "Mobile Path provides you with a mobile sub-domain and a new view path for mobile content."
|
22
|
+
gem.email = "patrick.robertson@velir.com"
|
23
|
+
gem.authors = ["patricksrobertson"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#
|
2
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
3
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
4
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
5
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
6
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
7
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
8
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
9
|
+
#++
|
10
|
+
|
11
|
+
#
|
12
|
+
# The configuration class gives you a means to define a config block
|
13
|
+
# to override the defaults provided in the gem. You can configure the
|
14
|
+
# mobile subdomain, the view path, and the regex for recognizing mobile
|
15
|
+
# devices.
|
16
|
+
#
|
17
|
+
# @author Patrick Robertson
|
18
|
+
|
19
|
+
require 'singleton'
|
20
|
+
|
21
|
+
module MobilePath
|
22
|
+
class Configuration
|
23
|
+
include Singleton
|
24
|
+
|
25
|
+
@@defaults = {
|
26
|
+
:subdomain => 'm',
|
27
|
+
:mobile_view_path => "mobile_views",
|
28
|
+
:mobile_device_regex => /(iPhone|iPod|iPad|Android)/
|
29
|
+
}
|
30
|
+
|
31
|
+
def self.defaults
|
32
|
+
@@defaults
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
@@defaults.each_pair{|k,v| self.send("#{k}=",v)}
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_accessor :subdomain, :mobile_view_path, :mobile_device_regex
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.config
|
44
|
+
Configuration.instance
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.configure
|
48
|
+
yield config
|
49
|
+
end
|
50
|
+
end
|
data/lib/mobile_path.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
#
|
2
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
3
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
4
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
5
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
6
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
7
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
8
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
9
|
+
#++
|
10
|
+
|
11
|
+
#
|
12
|
+
# MobilePath determines when a request comes from a mobile device, redirects to a
|
13
|
+
# mobile subdomain, and then prepends the view rendering path with app/mobile_views. A mobile
|
14
|
+
# device can override this by using a html param of full_site=true.
|
15
|
+
#
|
16
|
+
# @author Patrick Robertson
|
17
|
+
# @todo Split redirecting and prepending responsibilities.
|
18
|
+
|
19
|
+
require 'active_support/concern'
|
20
|
+
require 'mobile_path/configuration'
|
21
|
+
|
22
|
+
module MobilePath
|
23
|
+
|
24
|
+
extend ActiveSupport::Concern
|
25
|
+
|
26
|
+
included do
|
27
|
+
before_filter :toggle_mobile_preference_cookie
|
28
|
+
before_filter :redirect_to_mobile_if_applicable
|
29
|
+
before_filter :prepend_view_path_if_mobile
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
module InstanceMethods
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
#
|
38
|
+
# checks if the requesting user agent is a mobile browser. The devices
|
39
|
+
# that return true can be configured with the mobile_device_regex.
|
40
|
+
def mobile_browser?
|
41
|
+
user_agent && user_agent[MobilePath.config.mobile_device_regex]
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Checks if the incoming request is using the mobile subdomain.
|
46
|
+
def mobile_request?
|
47
|
+
request.subdomains.first == mobile_subdomain
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# The subdomain for the application can be configured. This method
|
52
|
+
# just caches the subdomain in case it is used more than once per request.
|
53
|
+
def mobile_subdomain
|
54
|
+
@mobile_subdomain ||= MobilePath.config.subdomain
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
#
|
59
|
+
# The view path that is prepended can be configured with mobile_view_path.
|
60
|
+
def mobile_view_path
|
61
|
+
@mobile_view_path ||= MobilePath.config.mobile_view_path
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# If the request is for a mobile device, prepend the configured mobile view
|
66
|
+
# path to the view paths.
|
67
|
+
def prepend_view_path_if_mobile
|
68
|
+
if mobile_request?
|
69
|
+
prepend_view_path Rails.root + 'app' + mobile_view_path
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Remove the mobile sudomain from the request path and redirect.
|
75
|
+
def redirect_to_full_site
|
76
|
+
redirect_to request.protocol + request.host_with_port.gsub(mobile_subdomain, '') +
|
77
|
+
request.fullpath and return
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Remove www. and add the mobile submomain to the request and redirect
|
82
|
+
def redirect_to_mobile
|
83
|
+
redirect_to request.protocol + mobile_subdomain + "." + request.host_with_port.gsub(/^www\./, '') + request.fullpath
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# If a request is mobile and the user doesn't prefer the full-site, redirect to the mobile site.
|
88
|
+
def redirect_to_mobile_if_applicable
|
89
|
+
unless mobile_request? || cookies[:prefer_full_site] || !mobile_browser?
|
90
|
+
redirect_to_mobile and return
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Switch to either the mobile or the full site based upon parameters.
|
96
|
+
def toggle_mobile_preference_cookie
|
97
|
+
if params[:mobile_site]
|
98
|
+
cookies.delete(:prefer_full_site)
|
99
|
+
elsif params[:full_site]
|
100
|
+
cookies.permanent[:prefer_full_site] = 1
|
101
|
+
redirect_to_full_site if mobile_request?
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# wrapper for the request HTTP user agent.
|
107
|
+
def user_agent
|
108
|
+
@user_agent ||= request.env["HTTP_USER_AGENT"]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
data/mobile_path.gemspec
ADDED
@@ -0,0 +1,76 @@
|
|
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
|
+
|
@@ -0,0 +1,43 @@
|
|
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
ADDED
@@ -0,0 +1,19 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mobile_path
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- patricksrobertson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-23 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
version: "3.0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 23
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 6
|
48
|
+
- 0
|
49
|
+
version: 2.6.0
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: rspec-rails
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 23
|
61
|
+
segments:
|
62
|
+
- 2
|
63
|
+
- 6
|
64
|
+
- 0
|
65
|
+
version: 2.6.0
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: yard
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 7
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
- 6
|
80
|
+
- 0
|
81
|
+
version: 0.6.0
|
82
|
+
type: :development
|
83
|
+
version_requirements: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: bundler
|
86
|
+
prerelease: false
|
87
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ~>
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 23
|
93
|
+
segments:
|
94
|
+
- 1
|
95
|
+
- 0
|
96
|
+
- 0
|
97
|
+
version: 1.0.0
|
98
|
+
type: :development
|
99
|
+
version_requirements: *id005
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: jeweler
|
102
|
+
prerelease: false
|
103
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ~>
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 15
|
109
|
+
segments:
|
110
|
+
- 1
|
111
|
+
- 6
|
112
|
+
- 0
|
113
|
+
version: 1.6.0
|
114
|
+
type: :development
|
115
|
+
version_requirements: *id006
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
name: rcov
|
118
|
+
prerelease: false
|
119
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
version: "0"
|
128
|
+
type: :development
|
129
|
+
version_requirements: *id007
|
130
|
+
- !ruby/object:Gem::Dependency
|
131
|
+
name: diesel
|
132
|
+
prerelease: false
|
133
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
hash: 9
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
- 1
|
142
|
+
version: "0.1"
|
143
|
+
type: :development
|
144
|
+
version_requirements: *id008
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: sqlite3
|
147
|
+
prerelease: false
|
148
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
hash: 3
|
154
|
+
segments:
|
155
|
+
- 0
|
156
|
+
version: "0"
|
157
|
+
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.
|
160
|
+
email: patrick.robertson@velir.com
|
161
|
+
executables: []
|
162
|
+
|
163
|
+
extensions: []
|
164
|
+
|
165
|
+
extra_rdoc_files:
|
166
|
+
- LICENSE.txt
|
167
|
+
- README.md
|
168
|
+
files:
|
169
|
+
- .document
|
170
|
+
- .rspec
|
171
|
+
- Gemfile
|
172
|
+
- Gemfile.lock
|
173
|
+
- LICENSE.txt
|
174
|
+
- README.md
|
175
|
+
- Rakefile
|
176
|
+
- VERSION
|
177
|
+
- lib/mobile_path.rb
|
178
|
+
- 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
|
183
|
+
homepage: http://github.com/Velir/mobile_path
|
184
|
+
licenses:
|
185
|
+
- MIT
|
186
|
+
post_install_message:
|
187
|
+
rdoc_options: []
|
188
|
+
|
189
|
+
require_paths:
|
190
|
+
- lib
|
191
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
192
|
+
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
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ">="
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
hash: 3
|
206
|
+
segments:
|
207
|
+
- 0
|
208
|
+
version: "0"
|
209
|
+
requirements: []
|
210
|
+
|
211
|
+
rubyforge_project:
|
212
|
+
rubygems_version: 1.6.2
|
213
|
+
signing_key:
|
214
|
+
specification_version: 3
|
215
|
+
summary: Simple way to give your Rails app mobile views.
|
216
|
+
test_files: []
|
217
|
+
|