high_voltage 1.2.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 200549e039d8c31dc74ed8c376f5dd684314aa56
4
+ data.tar.gz: 9bbe74af83cbb6ef5478451581df294b8830b82a
5
+ SHA512:
6
+ metadata.gz: 13a625a99201f9969aa48524fd001bd2eadbee5c42a0fc7fd0e956dbcaf875dd46dbafbcf407709e6042f1aa7576b9469f5f813bc95fe9cef1a96b6efb8c93f1
7
+ data.tar.gz: ce011d7615d5f6e85450f1458aa901c49d69f0ad543ef6f73b26e543bebafc6ebd6d0532584f115f3d18a015e8023e3277067ea796f2ac0d8543e2bc5015fa19
data/.travis.yml CHANGED
@@ -1,4 +1,7 @@
1
- language: ruby
1
+ language:
2
+ - ruby
3
+ install:
4
+ - 'bundle install'
2
5
  rvm:
3
6
  - 1.9.2
4
7
  - 1.9.3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- high_voltage (1.2.3)
4
+ high_voltage (2.0.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/NEWS.md CHANGED
@@ -1,3 +1,7 @@
1
+ New for 2.0.0:
2
+ + Extract PagesController into a module
3
+ + Update README with module usage instructions
4
+
1
5
  New for 1.2.4:
2
6
  + Add page and action caching
3
7
  + Remove redundant link style `page_path(id: 'about')` from README
data/README.md CHANGED
@@ -64,7 +64,7 @@ route generated by High Voltage itself.
64
64
 
65
65
  #### Specifying a root path
66
66
 
67
- You can route the root url to a High Voltage page like this:
67
+ You can route the root route to a High Voltage page like this:
68
68
 
69
69
  ```ruby
70
70
  root :to => 'high_voltage/pages#show', id: 'home'
@@ -72,7 +72,7 @@ root :to => 'high_voltage/pages#show', id: 'home'
72
72
 
73
73
  Which will render a homepage from app/views/pages/home.html.erb
74
74
 
75
- #### Page title's and meta-data
75
+ #### Page titles and meta-data
76
76
 
77
77
  We suggest using `content_for` and `yield` for setting custom page titles and
78
78
  meta-data on High Voltage pages.
@@ -166,7 +166,14 @@ Create a `PagesController` of your own:
166
166
 
167
167
  $ rails generate controller pages
168
168
 
169
- Override the default route:
169
+ Disable the default routes:
170
+
171
+ ```ruby
172
+ # config/initializers/high_voltage.rb
173
+ HighVoltage.routes = false
174
+ ```
175
+
176
+ Define a route for the new `PagesController`:
170
177
 
171
178
  ```ruby
172
179
  # config/routes.rb
@@ -176,23 +183,26 @@ get "/pages/*id" => 'pages#show', :as => :page, :format => false
176
183
  root :to => 'pages#show', :id => 'home'
177
184
  ```
178
185
 
179
- Then modify it to subclass from High Voltage, adding whatever you need:
186
+ Then modify new `PagesController` to include the High Voltage static page concern:
180
187
 
181
188
  ```ruby
182
189
  # app/controllers/pages_controller.rb
183
- class PagesController < HighVoltage::PagesController
190
+ class PagesController < ApplicationController
191
+ include HighVoltage::StaticPage
192
+
184
193
  before_filter :authenticate
185
194
  layout :layout_for_page
186
195
 
187
- protected
188
- def layout_for_page
189
- case params[:id]
190
- when 'home'
191
- 'home'
192
- else
193
- 'application'
194
- end
195
- end
196
+ private
197
+
198
+ def layout_for_page
199
+ case params[:id]
200
+ when 'home'
201
+ 'home'
202
+ else
203
+ 'application'
204
+ end
205
+ end
196
206
  end
197
207
  ```
198
208
 
@@ -203,7 +213,9 @@ the `page_finder_factory` method:
203
213
 
204
214
  ```ruby
205
215
  # app/controllers/pages_controller.rb
206
- class PagesController < HighVoltage::PagesController
216
+ class PagesController < ApplicationController
217
+ include HighVoltage::StaticPage
218
+
207
219
  private
208
220
 
209
221
  def page_finder_factory
@@ -0,0 +1,41 @@
1
+ module HighVoltage::StaticPage
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ layout ->(_) { HighVoltage.layout }
6
+
7
+ rescue_from ActionView::MissingTemplate do |exception|
8
+ if exception.message =~ %r{Missing template #{page_finder.content_path}}
9
+ raise ActionController::RoutingError, "No such page: #{params[:id]}"
10
+ else
11
+ raise exception
12
+ end
13
+ end
14
+
15
+ if respond_to?(:caches_action)
16
+ caches_action :show, if: -> { HighVoltage.action_caching }
17
+ end
18
+
19
+ if respond_to?(:caches_page)
20
+ caches_page :show, if: -> { HighVoltage.page_caching }
21
+ end
22
+
23
+ hide_action :current_page, :page_finder, :page_finder_factory
24
+ end
25
+
26
+ def show
27
+ render template: current_page
28
+ end
29
+
30
+ def current_page
31
+ page_finder.find
32
+ end
33
+
34
+ def page_finder
35
+ page_finder_factory.new(params[:id])
36
+ end
37
+
38
+ def page_finder_factory
39
+ HighVoltage::PageFinder
40
+ end
41
+ end
@@ -1,41 +1,3 @@
1
1
  class HighVoltage::PagesController < ApplicationController
2
- layout Proc.new { |_| HighVoltage.layout }
3
-
4
- if respond_to?('caches_action')
5
- caches_action :show, if: Proc.new {
6
- HighVoltage.action_caching
7
- }
8
- end
9
-
10
- if respond_to?('caches_page')
11
- caches_page :show, if: Proc.new {
12
- HighVoltage.page_caching
13
- }
14
- end
15
-
16
- rescue_from ActionView::MissingTemplate do |exception|
17
- if exception.message =~ %r{Missing template #{page_finder.content_path}}
18
- raise ActionController::RoutingError, "No such page: #{params[:id]}"
19
- else
20
- raise exception
21
- end
22
- end
23
-
24
- def show
25
- render :template => current_page
26
- end
27
-
28
- private
29
-
30
- def current_page
31
- page_finder.find
32
- end
33
-
34
- def page_finder
35
- page_finder_factory.new(params[:id])
36
- end
37
-
38
- def page_finder_factory
39
- HighVoltage::PageFinder
40
- end
2
+ include HighVoltage::StaticPage
41
3
  end
data/high_voltage.gemspec CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.homepage = 'http://github.com/thoughtbot/high_voltage'
10
10
  s.summary = 'Simple static page rendering controller'
11
11
  s.description = 'Fire in the disco. Fire in the ... taco bell.'
12
+ s.license = 'MIT'
12
13
 
13
14
  s.files = `git ls-files`.split("\n")
14
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,4 +1,13 @@
1
1
  module HighVoltage
2
2
  class Engine < Rails::Engine
3
+ initializer 'Require concerns path' do |app|
4
+ concerns_path = 'app/controllers/concerns'
5
+
6
+ unless app.paths.keys.include?(concerns_path)
7
+ app.paths.add(concerns_path)
8
+ end
9
+
10
+ require 'concerns/high_voltage/static_page'
11
+ end
3
12
  end
4
13
  end
@@ -1,3 +1,3 @@
1
1
  module HighVoltage
2
- VERSION = '1.2.4'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -2,25 +2,22 @@ require 'spec_helper'
2
2
 
3
3
  describe HighVoltage::PagesController, 'action_caching' do
4
4
  it 'caches the action when action_caching is set to true', enable_caching: true do
5
- HighVoltage.action_caching = true
6
-
7
- load('high_voltage/pages_controller.rb')
8
- get :show, id: 'exists'
9
-
10
- action_was_cached(:exists).should be_true
5
+ expect do
6
+ HighVoltage.action_caching = true
7
+ concern_reload
8
+ get :show, id: :exists
9
+ end.to change { action_was_cached(:exists) }
11
10
  end
12
11
 
13
12
  it 'does not cache the action when action_caching is set to false', enable_caching: true do
14
- HighVoltage.action_caching = false
15
-
16
- load('high_voltage/pages_controller.rb')
17
- get :show, id: 'exists'
18
-
19
- action_was_cached(:exists).should be_false
13
+ expect do
14
+ HighVoltage.action_caching = false
15
+ concern_reload
16
+ get :show, id: :exists
17
+ end.to_not change { action_was_cached(:exists) }
20
18
  end
21
19
 
22
20
  def action_was_cached(page)
23
21
  ActionController::Base.cache_store.exist?("views/test.host#{page_path(page)}")
24
22
  end
25
23
  end
26
-
@@ -5,18 +5,16 @@ describe HighVoltage::PagesController, 'action_caching' do
5
5
  controller.should_receive(:cache_page).at_least(:once)
6
6
 
7
7
  HighVoltage.page_caching = true
8
-
9
- load('high_voltage/pages_controller.rb')
10
- get :show, id: 'exists'
8
+ concern_reload
9
+ get :show, id: :exists
11
10
  end
12
11
 
13
12
  it 'does not cache the page when page_caching is set to false', enable_caching: true do
14
13
  controller.should_receive(:cache_page).never
15
14
 
16
15
  HighVoltage.page_caching = false
17
-
18
- load('high_voltage/pages_controller.rb')
19
- get :show, id: 'exists'
16
+ concern_reload
17
+ get :show, id: :exists
20
18
  end
21
19
  end
22
20
 
@@ -0,0 +1,11 @@
1
+ def concern_reload
2
+ HighVoltage::PagesController.class_eval do
3
+ if respond_to?(:caches_action)
4
+ caches_action :show, if: -> { HighVoltage.action_caching }
5
+ end
6
+
7
+ if respond_to?(:caches_page)
8
+ caches_page :show, if: -> { HighVoltage.page_caching }
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: high_voltage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matt Jankowski
@@ -17,44 +16,39 @@ authors:
17
16
  autorequire:
18
17
  bindir: bin
19
18
  cert_chain: []
20
- date: 2013-07-19 00:00:00.000000000 Z
19
+ date: 2013-10-05 00:00:00.000000000 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: activesupport
24
23
  requirement: !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
- - - ! '>='
25
+ - - '>='
28
26
  - !ruby/object:Gem::Version
29
27
  version: 3.1.0
30
28
  type: :development
31
29
  prerelease: false
32
30
  version_requirements: !ruby/object:Gem::Requirement
33
- none: false
34
31
  requirements:
35
- - - ! '>='
32
+ - - '>='
36
33
  - !ruby/object:Gem::Version
37
34
  version: 3.1.0
38
35
  - !ruby/object:Gem::Dependency
39
36
  name: appraisal
40
37
  requirement: !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
- - - ! '>='
39
+ - - '>='
44
40
  - !ruby/object:Gem::Version
45
41
  version: '0'
46
42
  type: :development
47
43
  prerelease: false
48
44
  version_requirements: !ruby/object:Gem::Requirement
49
- none: false
50
45
  requirements:
51
- - - ! '>='
46
+ - - '>='
52
47
  - !ruby/object:Gem::Version
53
48
  version: '0'
54
49
  - !ruby/object:Gem::Dependency
55
50
  name: capybara
56
51
  requirement: !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
53
  - - '='
60
54
  - !ruby/object:Gem::Version
@@ -62,7 +56,6 @@ dependencies:
62
56
  type: :development
63
57
  prerelease: false
64
58
  version_requirements: !ruby/object:Gem::Requirement
65
- none: false
66
59
  requirements:
67
60
  - - '='
68
61
  - !ruby/object:Gem::Version
@@ -70,33 +63,29 @@ dependencies:
70
63
  - !ruby/object:Gem::Dependency
71
64
  name: pry-debugger
72
65
  requirement: !ruby/object:Gem::Requirement
73
- none: false
74
66
  requirements:
75
- - - ! '>='
67
+ - - '>='
76
68
  - !ruby/object:Gem::Version
77
69
  version: '0'
78
70
  type: :development
79
71
  prerelease: false
80
72
  version_requirements: !ruby/object:Gem::Requirement
81
- none: false
82
73
  requirements:
83
- - - ! '>='
74
+ - - '>='
84
75
  - !ruby/object:Gem::Version
85
76
  version: '0'
86
77
  - !ruby/object:Gem::Dependency
87
78
  name: rspec-rails
88
79
  requirement: !ruby/object:Gem::Requirement
89
- none: false
90
80
  requirements:
91
- - - ! '>='
81
+ - - '>='
92
82
  - !ruby/object:Gem::Version
93
83
  version: '0'
94
84
  type: :development
95
85
  prerelease: false
96
86
  version_requirements: !ruby/object:Gem::Requirement
97
- none: false
98
87
  requirements:
99
- - - ! '>='
88
+ - - '>='
100
89
  - !ruby/object:Gem::Version
101
90
  version: '0'
102
91
  description: Fire in the disco. Fire in the ... taco bell.
@@ -116,6 +105,7 @@ files:
116
105
  - NEWS.md
117
106
  - README.md
118
107
  - Rakefile
108
+ - app/controllers/concerns/high_voltage/static_page.rb
119
109
  - app/controllers/high_voltage/pages_controller.rb
120
110
  - config/routes.rb
121
111
  - high_voltage.gemspec
@@ -184,29 +174,30 @@ files:
184
174
  - spec/routing/routes_spec.rb
185
175
  - spec/spec_helper.rb
186
176
  - spec/support/caching.rb
177
+ - spec/support/concern_reload.rb
187
178
  homepage: http://github.com/thoughtbot/high_voltage
188
- licenses: []
179
+ licenses:
180
+ - MIT
181
+ metadata: {}
189
182
  post_install_message:
190
183
  rdoc_options: []
191
184
  require_paths:
192
185
  - lib
193
186
  required_ruby_version: !ruby/object:Gem::Requirement
194
- none: false
195
187
  requirements:
196
- - - ! '>='
188
+ - - '>='
197
189
  - !ruby/object:Gem::Version
198
190
  version: '0'
199
191
  required_rubygems_version: !ruby/object:Gem::Requirement
200
- none: false
201
192
  requirements:
202
- - - ! '>='
193
+ - - '>='
203
194
  - !ruby/object:Gem::Version
204
195
  version: '0'
205
196
  requirements: []
206
197
  rubyforge_project:
207
- rubygems_version: 1.8.23
198
+ rubygems_version: 2.0.0
208
199
  signing_key:
209
- specification_version: 3
200
+ specification_version: 4
210
201
  summary: Simple static page rendering controller
211
202
  test_files:
212
203
  - spec/constraints/root_route_spec.rb
@@ -267,3 +258,4 @@ test_files:
267
258
  - spec/routing/routes_spec.rb
268
259
  - spec/spec_helper.rb
269
260
  - spec/support/caching.rb
261
+ - spec/support/concern_reload.rb