mobile-enhancements 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1 +1,13 @@
1
+ #!/usr/bin/env rake
1
2
  require "bundler/gem_tasks"
3
+
4
+ require "rspec/core/rake_task"
5
+
6
+ desc "Runs all the specs"
7
+ task default: %w(spec)
8
+
9
+ desc "Run specs"
10
+ RSpec::Core::RakeTask.new do |t|
11
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
12
+ # Put spec opts in a file named .rspec in root
13
+ end
@@ -47,12 +47,25 @@ module MobileEnhancements
47
47
  end
48
48
 
49
49
  class Options
50
+ # force format to pass through
51
+ def format(*args)
52
+ method_missing("format", *args)
53
+ end
54
+
55
+ def read_attribute(name)
56
+ (@properties ||= {})[name]
57
+ end
58
+
59
+ def write_attribute(name, value)
60
+ (@properties ||= {})[name] = value
61
+ end
62
+
50
63
  def method_missing(name, *args, &block)
51
64
  case args.size
52
65
  when 0
53
- (@properties ||= {})[name]
66
+ read_attribute(name)
54
67
  when 1
55
- (@properties ||= {})[name] = args.first
68
+ write_attribute(name, args.first)
56
69
  else
57
70
  super
58
71
  end
@@ -16,6 +16,12 @@ module MobileEnhancements
16
16
  if format = MobileEnhancements.configuration.mobile_format
17
17
  # register it as an alias to the HTML mime-type
18
18
  Mime::Type.register_alias "text/html", format
19
+ # setup the format calculation
20
+ ActionController::Base.class_eval do
21
+ before_filter do |controller|
22
+ controller.request.format = controller.determine_format
23
+ end
24
+ end
19
25
  end
20
26
  end
21
27
 
@@ -7,10 +7,10 @@ module MobileEnhancements
7
7
  def self.delegated_methods
8
8
  instance_methods.select do |name|
9
9
  name =~ /^(desktop|mobile)\_/
10
- end << :determine_layout
10
+ end + [:determine_layout, :determine_format]
11
11
  end
12
12
 
13
- def_delegators :configuration, :mobile_path_prefix, :mobile_layout, :desktop_layout
13
+ def_delegators :configuration, :mobile_path_prefix, :mobile_layout, :desktop_layout, :mobile_format
14
14
 
15
15
  attr_reader :request, :configuration
16
16
 
@@ -24,6 +24,11 @@ module MobileEnhancements
24
24
  mobile_request? ? mobile_layout : desktop_layout
25
25
  end
26
26
 
27
+ # returns what format should be used by the request
28
+ def determine_format
29
+ mobile_request? ? mobile_format.to_sym : request.format.to_sym
30
+ end
31
+
27
32
  # strips any mobile prefix from the url
28
33
  def desktop_url(url = request.url)
29
34
  desktop_path(url)
@@ -1,3 +1,3 @@
1
1
  module MobileEnhancements
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_development_dependency "rake"
21
+ s.add_development_dependency "rails"
21
22
  s.add_development_dependency "rb-fsevent"
22
23
  s.add_development_dependency "guard-rspec"
23
24
  s.add_development_dependency "rspec-rails"
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe TestController do
4
+ context "via the mobile UI" do
5
+ describe "GET /#{MobileEnhancements.configuration.mobile_path_prefix}/two" do
6
+ before { get :two, mobile: MobileEnhancements.configuration.mobile_path_prefix }
7
+
8
+ it "should render 'two, #{MobileEnhancements.configuration.mobile_format}'" do
9
+ expect(@response.body).to eq "two, #{MobileEnhancements.configuration.mobile_format}"
10
+ end
11
+ end
12
+ end
13
+
14
+ context "via the desktop UI" do
15
+ describe "GET /two" do
16
+ before { get :two }
17
+
18
+ it "should render 'two, html'" do
19
+ expect(@response.body).to eq "two, html"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,7 +1,8 @@
1
1
  class TestController < ActionController::Base
2
2
  def one
3
- render text: __method__
3
+ render text: [action_name, request.format.to_sym].join(", ")
4
4
  end
5
5
  alias_method :two, :one
6
6
  alias_method :three, :one
7
+ alias_method :four, :one
7
8
  end
@@ -4,6 +4,6 @@ MobileEnhancements.configure do
4
4
  mobile do
5
5
  prefix "m"
6
6
  layout "application"
7
- mime_type "mob"
7
+ format "mobile"
8
8
  end
9
9
  end
@@ -7,5 +7,6 @@ Rails.application.routes.draw do
7
7
 
8
8
  mobile_only do
9
9
  get "three", to: "test#three"
10
+ root to: "test#four"
10
11
  end
11
12
  end
@@ -18,15 +18,23 @@ describe MobileEnhancements::Configuration do
18
18
  subject.mobile do
19
19
  prefix "m"
20
20
  layout "mob"
21
+ format "mbl"
21
22
  end
22
23
  end
23
24
 
24
25
  it "should store the prefix" do
25
26
  expect(subject.mobile.prefix).to eq "m"
27
+ expect(subject.mobile_path_prefix).to eq "m"
26
28
  end
27
29
 
28
30
  it "should store the layout" do
29
31
  expect(subject.mobile.layout).to eq "mob"
32
+ expect(subject.mobile_layout).to eq "mob"
33
+ end
34
+
35
+ it "should store the format" do
36
+ expect(subject.mobile.format).to eq "mbl"
37
+ expect(subject.mobile_format).to eq :mbl
30
38
  end
31
39
 
32
40
  it "should raise method missing for undefined options" do
@@ -43,6 +51,7 @@ describe MobileEnhancements::Configuration do
43
51
 
44
52
  it "should store the layout" do
45
53
  expect(subject.desktop.layout).to eq "desktop"
54
+ expect(subject.desktop_layout).to eq "desktop"
46
55
  end
47
56
  end
48
57
  end
@@ -1,13 +1,13 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "standard routing" do
4
- it "routes /guides to guides#index" do
4
+ it "routes /one to test#one" do
5
5
  expect(get: "/one").to route_to("test#one")
6
6
  end
7
7
  end
8
8
 
9
9
  describe "mobile-optional routing" do
10
- it "routes /items to items#index" do
10
+ it "routes /two to test#two" do
11
11
  expect(get: "/two").to route_to({
12
12
  controller: "test",
13
13
  action: "two",
@@ -15,7 +15,7 @@ describe "mobile-optional routing" do
15
15
  })
16
16
  end
17
17
 
18
- it "routes /mobile/items to mobile#index" do
18
+ it "routes /#{MobileEnhancements.configuration.mobile_path_prefix}/two to test#two" do
19
19
  expect(get: "/#{MobileEnhancements.configuration.mobile_path_prefix}/two").to route_to({
20
20
  controller: "test",
21
21
  action: "two",
@@ -25,15 +25,23 @@ describe "mobile-optional routing" do
25
25
  end
26
26
 
27
27
  describe "mobile-only routing" do
28
- it "does not route /pages to pages#index" do
28
+ it "does not route /three" do
29
29
  expect(get: "/three").not_to be_routable
30
30
  end
31
31
 
32
- it "routes /mobile/pages to pages#index" do
32
+ it "routes /#{MobileEnhancements.configuration.mobile_path_prefix}/three to test#three" do
33
33
  expect(get: "/#{MobileEnhancements.configuration.mobile_path_prefix}/three").to route_to({
34
34
  controller: "test",
35
35
  action: "three",
36
36
  mobile: MobileEnhancements.configuration.mobile_path_prefix
37
37
  })
38
38
  end
39
+
40
+ it "routes /#{MobileEnhancements.configuration.mobile_path_prefix} to test#four" do
41
+ expect(get: "/#{MobileEnhancements.configuration.mobile_path_prefix}").to route_to({
42
+ controller: "test",
43
+ action: "four",
44
+ mobile: MobileEnhancements.configuration.mobile_path_prefix
45
+ })
46
+ end
39
47
  end
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-19 00:00:00.000000000 Z
12
+ date: 2012-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rb-fsevent
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -131,6 +147,7 @@ files:
131
147
  - lib/mobile_enhancements/route_helpers.rb
132
148
  - lib/mobile_enhancements/version.rb
133
149
  - mobile-enhancements.gemspec
150
+ - spec/controllers/test_controller_spec.rb
134
151
  - spec/internal/app/controllers/test_controller.rb
135
152
  - spec/internal/config/initializers/mobile_enhancements.rb
136
153
  - spec/internal/config/routes.rb
@@ -153,18 +170,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
170
  - - ! '>='
154
171
  - !ruby/object:Gem::Version
155
172
  version: '0'
156
- segments:
157
- - 0
158
- hash: -4122015549436335768
159
173
  required_rubygems_version: !ruby/object:Gem::Requirement
160
174
  none: false
161
175
  requirements:
162
176
  - - ! '>='
163
177
  - !ruby/object:Gem::Version
164
178
  version: '0'
165
- segments:
166
- - 0
167
- hash: -4122015549436335768
168
179
  requirements: []
169
180
  rubyforge_project:
170
181
  rubygems_version: 1.8.24
@@ -172,6 +183,7 @@ signing_key:
172
183
  specification_version: 3
173
184
  summary: A few features to aid Rails apps with separate mobile-targeted UIs.
174
185
  test_files:
186
+ - spec/controllers/test_controller_spec.rb
175
187
  - spec/internal/app/controllers/test_controller.rb
176
188
  - spec/internal/config/initializers/mobile_enhancements.rb
177
189
  - spec/internal/config/routes.rb