mobile-enhancements 0.0.2 → 0.0.3
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 +3 -3
- data/lib/mobile_enhancements/helper_delegation.rb +3 -0
- data/lib/mobile_enhancements/railtie.rb +4 -1
- data/lib/mobile_enhancements/url_helper.rb +18 -0
- data/lib/mobile_enhancements/version.rb +1 -1
- data/spec/controllers/test_controller_spec.rb +48 -0
- data/spec/internal/app/controllers/test_controller.rb +12 -0
- data/spec/internal/config/routes.rb +4 -1
- metadata +2 -1
data/README.md
CHANGED
@@ -31,17 +31,17 @@ In your config/routes.rb file:
|
|
31
31
|
|
32
32
|
```ruby
|
33
33
|
YourApp::Application.routes.draw do
|
34
|
-
#
|
34
|
+
# accessible via /items and /mobile/items
|
35
35
|
mobile_optional do
|
36
36
|
resource :items
|
37
37
|
end
|
38
38
|
|
39
|
-
#
|
39
|
+
# only accessible via /mobile/barcode_scanner
|
40
40
|
mobile_only do
|
41
41
|
get :barcode_scanner, to: "scans#new"
|
42
42
|
end
|
43
43
|
|
44
|
-
#
|
44
|
+
# only accessible via /guides (normal routing)
|
45
45
|
resource :guides
|
46
46
|
end
|
47
47
|
```
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "forwardable"
|
2
2
|
require "mobile_enhancements"
|
3
3
|
require "mobile_enhancements/request_helper"
|
4
|
+
require "mobile_enhancements/url_helper"
|
4
5
|
|
5
6
|
module MobileEnhancements
|
6
7
|
module HelperDelegation
|
@@ -11,6 +12,8 @@ module MobileEnhancements
|
|
11
12
|
if base.respond_to?(:helper_method)
|
12
13
|
base.helper_method *RequestHelper.delegated_methods
|
13
14
|
end
|
15
|
+
# include the UrlHelper
|
16
|
+
base.send(:include, UrlHelper)
|
14
17
|
end
|
15
18
|
|
16
19
|
private
|
@@ -19,7 +19,10 @@ module MobileEnhancements
|
|
19
19
|
# setup the format calculation
|
20
20
|
ActionController::Base.class_eval do
|
21
21
|
before_filter do |controller|
|
22
|
-
|
22
|
+
if controller.mobile_request?
|
23
|
+
controller.request.format = controller.determine_format
|
24
|
+
controller.params["mobile"] = MobileEnhancements.configuration.mobile_path_prefix
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module MobileEnhancements
|
2
|
+
module UrlHelper
|
3
|
+
def url_for(*args)
|
4
|
+
# ignore our direct calls for desktop/mobile URLs
|
5
|
+
if args.size == 1 && args.first.frozen?
|
6
|
+
super
|
7
|
+
# if it's from a mobile
|
8
|
+
elsif mobile_request?
|
9
|
+
# mobilify the url
|
10
|
+
mobile_url(super)
|
11
|
+
# if it's a desktop request
|
12
|
+
else
|
13
|
+
# process as normal
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -9,6 +9,30 @@ describe TestController do
|
|
9
9
|
expect(@response.body).to eq "two, #{MobileEnhancements.configuration.mobile_format}"
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
describe "GET /#{MobileEnhancements.configuration.mobile_path_prefix}/path_checking" do
|
14
|
+
before { get :path_checking, mobile: MobileEnhancements.configuration.mobile_path_prefix }
|
15
|
+
|
16
|
+
it "should render a mobile URL" do
|
17
|
+
expect(@response.body).to eq "http://test.host/#{MobileEnhancements.configuration.mobile_path_prefix}/two"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "GET /#{MobileEnhancements.configuration.mobile_path_prefix}/redirect_checking" do
|
22
|
+
before { get :redirect_checking, mobile: MobileEnhancements.configuration.mobile_path_prefix }
|
23
|
+
|
24
|
+
it "should redirect to a mobile URL" do
|
25
|
+
expect(@response.headers["Location"]).to eq "http://test.host/#{MobileEnhancements.configuration.mobile_path_prefix}/two"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "GET /#{MobileEnhancements.configuration.mobile_path_prefix}/fixed_redirect_checking" do
|
30
|
+
before { get :fixed_redirect_checking, mobile: MobileEnhancements.configuration.mobile_path_prefix }
|
31
|
+
|
32
|
+
it "should redirect to a mobile URL" do
|
33
|
+
expect(@response.headers["Location"]).to eq "http://test.host/#{MobileEnhancements.configuration.mobile_path_prefix}/two"
|
34
|
+
end
|
35
|
+
end
|
12
36
|
end
|
13
37
|
|
14
38
|
context "via the desktop UI" do
|
@@ -19,5 +43,29 @@ describe TestController do
|
|
19
43
|
expect(@response.body).to eq "two, html"
|
20
44
|
end
|
21
45
|
end
|
46
|
+
|
47
|
+
describe "GET /path_checking" do
|
48
|
+
before { get :path_checking }
|
49
|
+
|
50
|
+
it "should render a desktop URL" do
|
51
|
+
expect(@response.body).to eq "http://test.host/two"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "GET /redirect_checking" do
|
56
|
+
before { get :redirect_checking }
|
57
|
+
|
58
|
+
it "should redirect to a desktop URL" do
|
59
|
+
expect(@response.headers["Location"]).to eq "http://test.host/two"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "GET /fixed_redirect_checking" do
|
64
|
+
before { get :fixed_redirect_checking }
|
65
|
+
|
66
|
+
it "should redirect to a mobile URL" do
|
67
|
+
expect(@response.headers["Location"]).to eq "http://test.host/#{MobileEnhancements.configuration.mobile_path_prefix}/two"
|
68
|
+
end
|
69
|
+
end
|
22
70
|
end
|
23
71
|
end
|
@@ -5,4 +5,16 @@ class TestController < ActionController::Base
|
|
5
5
|
alias_method :two, :one
|
6
6
|
alias_method :three, :one
|
7
7
|
alias_method :four, :one
|
8
|
+
|
9
|
+
def path_checking
|
10
|
+
render text: optional_mobile_url
|
11
|
+
end
|
12
|
+
|
13
|
+
def redirect_checking
|
14
|
+
redirect_to(optional_mobile_url)
|
15
|
+
end
|
16
|
+
|
17
|
+
def fixed_redirect_checking
|
18
|
+
redirect_to(mobile_url(optional_mobile_url))
|
19
|
+
end
|
8
20
|
end
|
@@ -2,7 +2,10 @@ Rails.application.routes.draw do
|
|
2
2
|
get "one", to: "test#one"
|
3
3
|
|
4
4
|
mobile_optional do
|
5
|
-
get "two", to: "test#two"
|
5
|
+
get "two", to: "test#two", as: :optional_mobile
|
6
|
+
get "five", to: "test#path_checking"
|
7
|
+
get "six", to: "test#redirect_checking"
|
8
|
+
get "seven", to: "test#fixed_redirect_checking"
|
6
9
|
end
|
7
10
|
|
8
11
|
mobile_only do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobile-enhancements
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/mobile_enhancements/railtie.rb
|
146
146
|
- lib/mobile_enhancements/request_helper.rb
|
147
147
|
- lib/mobile_enhancements/route_helpers.rb
|
148
|
+
- lib/mobile_enhancements/url_helper.rb
|
148
149
|
- lib/mobile_enhancements/version.rb
|
149
150
|
- mobile-enhancements.gemspec
|
150
151
|
- spec/controllers/test_controller_spec.rb
|