high_voltage 1.2.2 → 2.0.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.
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/.gitignore CHANGED
@@ -5,5 +5,5 @@ spec/dummy/db/*.sqlite3
5
5
  spec/dummy/log/*.log
6
6
  spec/dummy/tmp/
7
7
  *.swp
8
- gemfiles/*.lock
9
- *.gem
8
+ gemfiles/
9
+ *.gem
data/.travis.yml CHANGED
@@ -1,9 +1,8 @@
1
- language: ruby
1
+ language:
2
+ - ruby
3
+ install:
4
+ - 'bundle install'
2
5
  rvm:
3
- - 1.8.7
4
6
  - 1.9.2
5
7
  - 1.9.3
6
- gemfile:
7
- - gemfiles/rails_3.0.18.gemfile
8
- - gemfiles/rails_3.1.9.gemfile
9
- - gemfiles/rails_3.2.10.gemfile
8
+ - 2.0.0
data/Appraisals CHANGED
@@ -1,5 +1,16 @@
1
- ['3.2.10', '3.1.9', '3.0.18'].each do |rails_version|
2
- appraise "rails_#{rails_version}" do
3
- gem "rails", rails_version
1
+ if RUBY_VERSION >= '2.0'
2
+ rails_versions = ['~> 3.2.13', '~> 4.0.0']
3
+ else
4
+ rails_versions = ['~> 3.1.12', '~> 3.2.13']
5
+ end
6
+
7
+ rails_versions.each do |rails_version|
8
+ appraise "rails#{rails_version.slice(/\d+\.\d+/)}" do
9
+ gem 'rails', rails_version
10
+
11
+ if rails_version == '~> 4.0.0'
12
+ gem 'actionpack-action_caching'
13
+ gem 'actionpack-page_caching'
14
+ end
4
15
  end
5
16
  end
data/Gemfile.lock CHANGED
@@ -1,94 +1,80 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- high_voltage (1.2.2)
4
+ high_voltage (2.0.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- abstract (1.0.0)
10
- actionpack (3.0.10)
11
- activemodel (= 3.0.10)
12
- activesupport (= 3.0.10)
13
- builder (~> 2.1.2)
14
- erubis (~> 2.6.6)
15
- i18n (~> 0.5.0)
16
- rack (~> 1.2.1)
17
- rack-mount (~> 0.6.14)
18
- rack-test (~> 0.5.7)
19
- tzinfo (~> 0.3.23)
20
- activemodel (3.0.10)
21
- activesupport (= 3.0.10)
22
- builder (~> 2.1.2)
23
- i18n (~> 0.5.0)
24
- activesupport (3.0.10)
25
- appraisal (0.4.1)
9
+ activesupport (3.1.12)
10
+ multi_json (~> 1.0)
11
+ appraisal (0.5.2)
26
12
  bundler
27
13
  rake
28
- builder (2.1.2)
29
- capybara (1.1.0)
14
+ capybara (2.0.3)
30
15
  mime-types (>= 1.16)
31
16
  nokogiri (>= 1.3.3)
32
17
  rack (>= 1.0.0)
33
18
  rack-test (>= 0.5.4)
34
19
  selenium-webdriver (~> 2.0)
35
- xpath (~> 0.1.4)
36
- childprocess (0.2.2)
37
- ffi (~> 1.0.6)
20
+ xpath (~> 1.0.0)
21
+ childprocess (0.3.9)
22
+ ffi (~> 1.0, >= 1.0.11)
23
+ coderay (1.0.9)
24
+ columnize (0.3.6)
25
+ debugger (1.6.1)
26
+ columnize (>= 0.3.1)
27
+ debugger-linecache (~> 1.2.0)
28
+ debugger-ruby_core_source (~> 1.2.3)
29
+ debugger-linecache (1.2.0)
30
+ debugger-ruby_core_source (1.2.3)
38
31
  diff-lcs (1.1.3)
39
- erubis (2.6.6)
40
- abstract (>= 1.0.0)
41
- ffi (1.0.9)
42
- i18n (0.5.0)
43
- json_pure (1.5.4)
44
- spruz (~> 0.2.8)
45
- mime-types (1.16)
46
- nokogiri (1.5.0)
47
- rack (1.2.3)
48
- rack-mount (0.6.14)
49
- rack (>= 1.0.0)
50
- rack-test (0.5.7)
32
+ ffi (1.9.0)
33
+ method_source (0.8.1)
34
+ mime-types (1.23)
35
+ mini_portile (0.5.1)
36
+ multi_json (1.7.7)
37
+ nokogiri (1.6.0)
38
+ mini_portile (~> 0.5.0)
39
+ pry (0.9.12.2)
40
+ coderay (~> 1.0.5)
41
+ method_source (~> 0.8)
42
+ slop (~> 3.4)
43
+ pry-debugger (0.2.2)
44
+ debugger (~> 1.3)
45
+ pry (~> 0.9.10)
46
+ rack (1.5.2)
47
+ rack-test (0.6.2)
51
48
  rack (>= 1.0)
52
- railties (3.0.10)
53
- actionpack (= 3.0.10)
54
- activesupport (= 3.0.10)
55
- rake (>= 0.8.7)
56
- rdoc (~> 3.4)
57
- thor (~> 0.14.4)
58
- rake (0.9.2.2)
59
- rdoc (3.9.4)
60
- rspec (2.6.0)
61
- rspec-core (~> 2.6.0)
62
- rspec-expectations (~> 2.6.0)
63
- rspec-mocks (~> 2.6.0)
64
- rspec-core (2.6.4)
65
- rspec-expectations (2.6.0)
49
+ rake (10.1.0)
50
+ rspec (2.1.0)
51
+ rspec-core (~> 2.1.0)
52
+ rspec-expectations (~> 2.1.0)
53
+ rspec-mocks (~> 2.1.0)
54
+ rspec-core (2.1.0)
55
+ rspec-expectations (2.1.0)
66
56
  diff-lcs (~> 1.1.2)
67
- rspec-mocks (2.6.0)
68
- rspec-rails (2.6.1)
69
- actionpack (~> 3.0)
70
- activesupport (~> 3.0)
71
- railties (~> 3.0)
72
- rspec (~> 2.6.0)
73
- rubyzip (0.9.4)
74
- selenium-webdriver (2.5.0)
75
- childprocess (>= 0.2.1)
76
- ffi (>= 1.0.7)
77
- json_pure
57
+ rspec-mocks (2.1.0)
58
+ rspec-rails (2.1.0)
59
+ rspec (~> 2.1.0)
60
+ rubyzip (0.9.9)
61
+ selenium-webdriver (2.33.0)
62
+ childprocess (>= 0.2.5)
63
+ multi_json (~> 1.0)
78
64
  rubyzip
79
- spruz (0.2.13)
80
- sqlite3 (1.3.4)
81
- thor (0.14.6)
82
- tzinfo (0.3.29)
83
- xpath (0.1.4)
65
+ websocket (~> 1.0.4)
66
+ slop (3.4.5)
67
+ websocket (1.0.7)
68
+ xpath (1.0.0)
84
69
  nokogiri (~> 1.3)
85
70
 
86
71
  PLATFORMS
87
72
  ruby
88
73
 
89
74
  DEPENDENCIES
75
+ activesupport (>= 3.1.0)
90
76
  appraisal
91
- capybara (>= 0.4.0)
77
+ capybara (= 2.0.3)
92
78
  high_voltage!
79
+ pry-debugger
93
80
  rspec-rails
94
- sqlite3
data/NEWS.md CHANGED
@@ -1,6 +1,22 @@
1
+ New for 2.0.0:
2
+ + Extract PagesController into a module
3
+ + Update README with module usage instructions
4
+
5
+ New for 1.2.4:
6
+ + Add page and action caching
7
+ + Remove redundant link style `page_path(id: 'about')` from README
8
+ + Clean up Appraisals for Travis-CI
9
+ + Remove Ruby 1.8.7 from test suite
10
+
11
+ New for 1.2.3:
12
+ + Updates for Rails 4 compatibility.
13
+ + Fix for Rails 4 circular dependency error.
14
+ + Add ability to load High Voltage outside of rails. Require `attribute_accessors`
15
+
1
16
  New for 1.2.2:
2
17
  + Bug fix for RootRoute constraint. Support haml, slim, etc.
3
18
  + README updated for root routes.
19
+
4
20
  New for 1.2.1:
5
21
  + Ability to disable HighVoltage routes.
6
22
  + New RootRoute constraint.
data/README.md CHANGED
@@ -4,26 +4,25 @@ Rails engine for static pages.
4
4
 
5
5
  ... but be careful. [Danger!](http://www.youtube.com/watch?v=HD5tnb2RBYg)
6
6
 
7
- Static pages?
8
- -------------
7
+ ## Static pages?
9
8
 
10
9
  Yeah, like "About us", "Directions", marketing pages, etc.
11
10
 
12
- Installation
13
- ------------
11
+ ## Installation
14
12
 
15
13
  $ gem install high_voltage
16
14
 
17
15
  Include in your Gemfile:
18
16
 
19
- gem "high_voltage"
17
+ ```ruby
18
+ gem 'high_voltage'
19
+ ```
20
20
 
21
21
  For Rails versions prior to 3.0, use the 0.9.2 tag of high_voltage:
22
22
 
23
23
  https://github.com/thoughtbot/high_voltage/tree/v0.9.2
24
24
 
25
- Usage
26
- -----
25
+ ## Usage
27
26
 
28
27
  Write your static pages and put them in the RAILS_ROOT/app/views/pages directory.
29
28
 
@@ -32,28 +31,29 @@ Write your static pages and put them in the RAILS_ROOT/app/views/pages directory
32
31
 
33
32
  After putting something interesting there, you can link to it from anywhere in your app with:
34
33
 
35
- link_to "About", page_path("about")
36
-
37
- This will also work, if you like the more explicit style:
38
-
39
- link_to "About", page_path(:id => "about")
34
+ ```ruby
35
+ link_to 'About', page_path('about')
36
+ ```
40
37
 
41
38
  You can nest pages in a directory structure, if that makes sense from a URL perspective for you:
42
39
 
43
- link_to "Q4 Reports", page_path("about/corporate/policies/HR/en_US/biz/sales/Quarter-Four")
40
+ ```ruby
41
+ link_to 'Q4 Reports', page_path('about/corporate/policies/HR/en_US/biz/sales/Quarter-Four')
42
+ ```
44
43
 
45
44
  Bam.
46
45
 
47
- Routes
48
- ------
46
+ ## Routes
49
47
 
50
48
  By default, the static page routes will be like /pages/:id (where :id is the view filename).
51
49
 
52
50
  If you want to route to a static page in another location (for example, a homepage), do this:
53
51
 
54
- match 'pages/home' => 'high_voltage/pages#show', :id => 'home'
52
+ ```ruby
53
+ get 'pages/home' => 'high_voltage/pages#show', id: 'home'
54
+ ```
55
55
 
56
- In that case, you'd need an app/views/pages/home.html.erb file.
56
+ In that case, you'd need an `app/views/pages/home.html.erb` file.
57
57
 
58
58
  Generally speaking, you need to route to the 'show' action with an :id param of the view filename.
59
59
 
@@ -62,22 +62,36 @@ want to generate a named route (with the :as routing option) for some route whic
62
62
  by High Voltage, make sure not to use :page as the name, because that will conflict with the named
63
63
  route generated by High Voltage itself.
64
64
 
65
- For example, this will work for top-level routes (we will
66
- get a named route called `static_path` which does not conflict with the generated `page_path` method):
67
-
68
- match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get
69
-
70
65
  #### Specifying a root path
71
66
 
72
- 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:
73
68
 
74
- root :to => 'high_voltage/pages#show', :id => 'home'
69
+ ```ruby
70
+ root :to => 'high_voltage/pages#show', id: 'home'
71
+ ```
75
72
 
76
73
  Which will render a homepage from app/views/pages/home.html.erb
77
74
 
78
- #### Enabling root domain routes
75
+ #### Page titles and meta-data
76
+
77
+ We suggest using `content_for` and `yield` for setting custom page titles and
78
+ meta-data on High Voltage pages.
79
+
80
+ ```ruby
81
+ # app/views/pages/about.html.erb
82
+ <%= content_for :page_title, 'About Us - Custom page title' %>
83
+ ```
84
+
85
+ Then print the contents of `:title` into the layout:
79
86
 
80
- You can remove the directory `pages` from the URL path and serve up routes from
87
+ ```ruby
88
+ # app/views/layouts/application.html.erb
89
+ <title><%= yield(:page_title) %></title>
90
+ ```
91
+
92
+ #### Top-level routes
93
+
94
+ You can remove the directory `pages` from the URL path and serve up routes from
81
95
  the root of the domain path:
82
96
 
83
97
  http://www.example.com/about
@@ -90,31 +104,57 @@ Would look for corresponding files:
90
104
 
91
105
  This is accomplished by changing the `HighVoltage.route_drawer` to `HighVoltage::RouteDrawers::Root`
92
106
 
93
- # config/initializers/high_voltage.rb
94
- HighVoltage.route_drawer = HighVoltage::RouteDrawers::Root
95
-
96
- Note: This is not a catchall route. It will check the `HighVoltage.content_path`
97
- (by default this is `app/views/pages`) and validate the view exists.
107
+ ```ruby
108
+ # config/initializers/high_voltage.rb
109
+ HighVoltage.route_drawer = HighVoltage::RouteDrawers::Root
110
+ ```
98
111
 
99
112
  #### Disabling routes
100
113
 
101
- The default routes can be completely removed by changing the
102
- `HighVoltage.routes` to `false`
114
+ The default routes can be completely removed by changing the `HighVoltage.routes`
115
+ to `false`:
103
116
 
104
- # config/initializers/high_voltage.rb
105
- HighVoltage.routes = false
117
+ ```ruby
118
+ # config/initializers/high_voltage.rb
119
+ HighVoltage.routes = false
120
+ ```
106
121
 
107
- Customize
108
- --------
122
+ #### Content path
109
123
 
110
- High Voltage uses a default path and folder of 'pages', i.e. 'url.com/pages/contact' , 'app/views/pages'
124
+ High Voltage uses a default path and folder of 'pages', i.e. 'url.com/pages/contact',
125
+ 'app/views/pages'.
111
126
 
112
127
  You can change this in an initializer:
113
128
 
114
- HighVoltage.content_path = "site/"
129
+ ```ruby
130
+ # config/initializers/high_voltage.rb
131
+ HighVoltage.content_path = 'site/'
132
+ ```
133
+
134
+ #### Caching
135
+
136
+ High Voltage supports both [page](http://guides.rubyonrails.org/caching_with_rails.html#page-caching) and [action caching](http://guides.rubyonrails.org/caching_with_rails.html#action-caching).
137
+
138
+ To enable them you can add the following to your initializer:
139
+
140
+ ```ruby
141
+ # config/initializers/high_voltage.rb
142
+ HighVoltage.action_caching = true
143
+ # OR
144
+ HighVoltage.page_caching = true
145
+ ```
115
146
 
116
- Override
117
- --------
147
+ High Voltage will use your default cache store to store action caches.
148
+
149
+ Using caching with Ruby on Rails 4 or higher requires gems:
150
+
151
+ ```ruby
152
+ # Gemfile
153
+ gem 'actionpack-action_caching'
154
+ gem 'actionpack-page_caching'
155
+ ```
156
+
157
+ ## Override
118
158
 
119
159
  Most common reasons to override?
120
160
 
@@ -122,97 +162,118 @@ Most common reasons to override?
122
162
  * You need to render different layouts for different pages.
123
163
  * You need to render a partial from the `app/views/pages` directory.
124
164
 
125
- Create a PagesController of your own:
165
+ Create a `PagesController` of your own:
126
166
 
127
167
  $ rails generate controller pages
128
168
 
129
- 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`:
177
+
178
+ ```ruby
179
+ # config/routes.rb
180
+ get "/pages/*id" => 'pages#show', :as => :page, :format => false
181
+
182
+ # if routing the root path, update for your controller
183
+ root :to => 'pages#show', :id => 'home'
184
+ ```
130
185
 
131
- # in config/routes.rb
132
- match "/pages/*id" => 'pages#show', :as => :page, :format => false
186
+ Then modify new `PagesController` to include the High Voltage static page concern:
133
187
 
134
- # if routing the root path, update for your controller
135
- root :to => 'pages#show', :id => 'home'
188
+ ```ruby
189
+ # app/controllers/pages_controller.rb
190
+ class PagesController < ApplicationController
191
+ include HighVoltage::StaticPage
136
192
 
137
- Then modify it to subclass from High Voltage, adding whatever you need:
193
+ before_filter :authenticate
194
+ layout :layout_for_page
138
195
 
139
- class PagesController < HighVoltage::PagesController
140
- before_filter :authenticate
141
- layout :layout_for_page
196
+ private
142
197
 
143
- protected
144
- def layout_for_page
145
- case params[:id]
146
- when 'home'
147
- 'home'
148
- else
149
- 'application'
150
- end
151
- end
198
+ def layout_for_page
199
+ case params[:id]
200
+ when 'home'
201
+ 'home'
202
+ else
203
+ 'application'
152
204
  end
205
+ end
206
+ end
207
+ ```
153
208
 
154
- Custom finding
155
- --------------
209
+ ## Custom finding
156
210
 
157
211
  You can further control the algorithm used to find pages by overriding
158
212
  the `page_finder_factory` method:
159
213
 
160
- class PagesController < HighVoltage::PagesController
161
- private
214
+ ```ruby
215
+ # app/controllers/pages_controller.rb
216
+ class PagesController < ApplicationController
217
+ include HighVoltage::StaticPage
162
218
 
163
- def page_finder_factory
164
- Rot13PageFinder
165
- end
166
- end
219
+ private
220
+
221
+ def page_finder_factory
222
+ Rot13PageFinder
223
+ end
224
+ end
225
+ ```
167
226
 
168
227
  The easiest thing is to subclass `HighVoltage::PageFinder`, which
169
228
  provides you with `page_id`:
170
229
 
171
- class Rot13PageFinder < HighVoltage::PageFinder
172
- def find
173
- paths = super.split('/')
174
- directory = paths[0..-2]
175
- filename = paths[-1].tr('a-z','n-za-m')
230
+ ```ruby
231
+ class Rot13PageFinder < HighVoltage::PageFinder
232
+ def find
233
+ paths = super.split('/')
234
+ directory = paths[0..-2]
235
+ filename = paths[-1].tr('a-z','n-za-m')
176
236
 
177
- File.join(*directory, filename)
178
- end
179
- end
237
+ File.join(*directory, filename)
238
+ end
239
+ end
240
+ ```
180
241
 
181
242
  Use this to create a custom file mapping, clean filenames for your file
182
243
  system, A/B test, and so on.
183
244
 
184
- Testing
185
- -------
245
+ ## Testing
186
246
 
187
- You can test your static pages using [RSpec](https://github.com/rspec/rspec-rails)
247
+ You can test your static pages using [RSpec](https://github.com/rspec/rspec-rails)
188
248
  and [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers):
189
249
 
190
- # spec/controllers/pages_controller_spec.rb
191
- describe PagesController, '#show' do
192
- %w(earn_money screencast about contact).each do |page|
193
- context 'on GET to /pages/#{page}' do
194
- before do
195
- get :show, :id => page
196
- end
197
-
198
- it { should respond_with(:success) }
199
- it { should render_template(page) }
200
- end
250
+ ```ruby
251
+ # spec/controllers/pages_controller_spec.rb
252
+ describe PagesController, '#show' do
253
+ %w(earn_money screencast about contact).each do |page|
254
+ context 'on GET to /pages/#{page}' do
255
+ before do
256
+ get :show, :id => page
201
257
  end
258
+
259
+ it { should respond_with(:success) }
260
+ it { should render_template(page) }
202
261
  end
262
+ end
263
+ end
264
+ ```
203
265
 
204
266
  If you're not using a custom PagesController be sure to test
205
267
  `HighVoltage::PagesController` instead.
206
268
 
207
269
  Enjoy!
208
270
 
209
- Contributing
210
- ------------
271
+ ## Contributing
211
272
 
212
- Please see CONTRIBUTING.md for details.
273
+ Please see [CONTRIBUTING.md](https://github.com/thoughtbot/high_voltage/blob/master/CONTRIBUTING.md)
274
+ for details.
213
275
 
214
- Credits
215
- -------
276
+ ## Credits
216
277
 
217
278
  ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
218
279
 
@@ -222,8 +283,7 @@ Thank you to all [the contributors](https://github.com/thoughtbot/high_voltage/c
222
283
 
223
284
  The names and logos for thoughtbot are trademarks of thoughtbot, inc.
224
285
 
225
- License
226
- -------
286
+ ## License
227
287
 
228
288
  High Voltage is Copyright © 2009-2013 thoughtbot. It is free software, and may
229
289
  be redistributed under the terms specified in the MIT-LICENSE file.
data/Rakefile CHANGED
@@ -1,18 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
1
4
  require 'bundler/setup'
2
5
  require 'bundler/gem_tasks'
3
- require 'appraisal'
4
6
 
7
+ require 'rake'
5
8
  require 'rspec/core/rake_task'
9
+ require 'appraisal'
10
+
6
11
  RSpec::Core::RakeTask.new(:spec)
7
12
 
8
- task :default do |t|
9
- if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
10
- exec 'rake spec'
11
- else
12
- Rake::Task['appraise'].execute
13
- end
14
- end
13
+ desc 'Default'
14
+ task :default => [:all]
15
15
 
16
- task :appraise => ['appraisal:install'] do |t|
17
- exec 'rake appraisal'
16
+ desc 'Test the engine under all supported Rails versions'
17
+ task all: ['appraisal:install'] do |t|
18
+ exec 'rake appraisal spec'
18
19
  end
@@ -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,30 +1,3 @@
1
1
  class HighVoltage::PagesController < ApplicationController
2
- unloadable
3
- layout Proc.new { |_| HighVoltage.layout }
4
-
5
- rescue_from ActionView::MissingTemplate do |exception|
6
- if exception.message =~ %r{Missing template #{page_finder.content_path}}
7
- raise ActionController::RoutingError, "No such page: #{params[:id]}"
8
- else
9
- raise exception
10
- end
11
- end
12
-
13
- def show
14
- render :template => current_page
15
- end
16
-
17
- private
18
-
19
- def current_page
20
- page_finder.find
21
- end
22
-
23
- def page_finder
24
- page_finder_factory.new(params[:id])
25
- end
26
-
27
- def page_finder_factory
28
- HighVoltage::PageFinder
29
- end
2
+ include HighVoltage::StaticPage
30
3
  end
data/high_voltage.gemspec CHANGED
@@ -8,15 +8,17 @@ Gem::Specification.new do |s|
8
8
  s.email = ['support@thoughtbot.com']
9
9
  s.homepage = 'http://github.com/thoughtbot/high_voltage'
10
10
  s.summary = 'Simple static page rendering controller'
11
- s.description = 'Fire in the disco. Fire in the ... taco bell.'
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")
15
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
17
  s.require_paths = ["lib"]
17
18
 
19
+ s.add_development_dependency("activesupport", ">= 3.1.0")
18
20
  s.add_development_dependency("appraisal")
21
+ s.add_development_dependency("capybara", "= 2.0.3")
22
+ s.add_development_dependency("pry-debugger")
19
23
  s.add_development_dependency("rspec-rails")
20
- s.add_development_dependency("capybara", ">= 0.4.0")
21
- s.add_development_dependency("sqlite3")
22
24
  end
@@ -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.2'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
data/lib/high_voltage.rb CHANGED
@@ -3,6 +3,7 @@ require 'high_voltage/constraints/root_route'
3
3
  require 'high_voltage/page_finder'
4
4
  require 'high_voltage/route_drawers/default'
5
5
  require 'high_voltage/route_drawers/root'
6
+ require 'active_support/core_ext/module/attribute_accessors'
6
7
 
7
8
  module HighVoltage
8
9
  mattr_accessor :layout
@@ -17,6 +18,12 @@ module HighVoltage
17
18
  mattr_accessor :routes
18
19
  @@routes = true
19
20
 
21
+ mattr_accessor :action_caching
22
+ @@action_caching = false
23
+
24
+ mattr_accessor :page_caching
25
+ @@page_caching = false
26
+
20
27
  def self.setup
21
28
  yield self
22
29
  end
@@ -3,19 +3,23 @@ require 'spec_helper'
3
3
  describe HighVoltage::Constraints::RootRoute, '.matches?' do
4
4
  context 'view file exists' do
5
5
  it 'should return true' do
6
- request = stub(:path => 'index')
7
- Dir.stub!(:glob).and_return(['about.html.erb'])
6
+ request = double(path: 'index')
7
+ Dir.stub(:glob).and_return(['about.html.erb'])
8
8
 
9
- HighVoltage::Constraints::RootRoute.matches?(request).should be_true
9
+ result = HighVoltage::Constraints::RootRoute.matches?(request)
10
+
11
+ expect(result).to be_true
10
12
  end
11
13
  end
12
14
 
13
15
  context 'view file does not exist' do
14
16
  it 'should return false' do
15
- request = stub(:path => 'index')
16
- File.stub!(:glob).and_return([])
17
+ request = double(path: 'index')
18
+ File.stub(:glob).and_return([])
19
+
20
+ result = HighVoltage::Constraints::RootRoute.matches?(request)
17
21
 
18
- HighVoltage::Constraints::RootRoute.matches?(request).should be_false
22
+ expect(result).to be_false
19
23
  end
20
24
  end
21
25
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe HighVoltage::PagesController, 'action_caching' do
4
+ it 'caches the action when action_caching is set to true', enable_caching: true do
5
+ expect do
6
+ HighVoltage.action_caching = true
7
+ concern_reload
8
+ get :show, id: :exists
9
+ end.to change { action_was_cached(:exists) }
10
+ end
11
+
12
+ it 'does not cache the action when action_caching is set to false', enable_caching: true do
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) }
18
+ end
19
+
20
+ def action_was_cached(page)
21
+ ActionController::Base.cache_store.exist?("views/test.host#{page_path(page)}")
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe HighVoltage::PagesController, 'action_caching' do
4
+ it 'caches the page when page_caching is set to true', enable_caching: true do
5
+ controller.should_receive(:cache_page).at_least(:once)
6
+
7
+ HighVoltage.page_caching = true
8
+ concern_reload
9
+ get :show, id: :exists
10
+ end
11
+
12
+ it 'does not cache the page when page_caching is set to false', enable_caching: true do
13
+ controller.should_receive(:cache_page).never
14
+
15
+ HighVoltage.page_caching = false
16
+ concern_reload
17
+ get :show, id: :exists
18
+ end
19
+ end
20
+
@@ -98,21 +98,21 @@ describe HighVoltage::PagesController do
98
98
  end
99
99
 
100
100
  it 'should raise a routing error for an invalid page' do
101
- lambda {
102
- get :show,
103
- :id => 'also_invalid'
101
+ lambda {
102
+ get :show,
103
+ :id => 'also_invalid'
104
104
  }.should raise_error(ActionController::RoutingError)
105
105
  end
106
106
 
107
107
  it 'should raise a routing error for a page in another directory' do
108
108
  lambda {
109
109
  get :show,
110
- :id => '../other/wrong'
110
+ :id => '../other/wrong'
111
111
  }.should raise_error(ActionController::RoutingError)
112
112
  end
113
113
 
114
114
  it 'should raise a routing error for a page in another directory when using a Unicode exploit' do
115
- lambda {
115
+ lambda {
116
116
  get :show,
117
117
  :id => '/\\../other/wrong'
118
118
  }.should raise_error(ActionController::RoutingError)
@@ -7,8 +7,7 @@ Dummy::Application.configure do
7
7
  # and recreated between test runs. Don't rely on the data there!
8
8
  config.cache_classes = true
9
9
 
10
- # Log error messages when you accidentally call methods on nil.
11
- config.whiny_nils = true
10
+ config.eager_load = false
12
11
 
13
12
  # Show full error reports and disable caching
14
13
  config.consider_all_requests_local = true
@@ -0,0 +1 @@
1
+ Dummy::Application.config.secret_key_base = '9c0b876ab8f513cc23d354b6d684c88eb9bc5f73ddc8d5843e7c6ac9176c5819adc2620e220980a3cb818de687753f1bfc56c66c4454b74fc7d432813f8e555a'
@@ -1,4 +1,4 @@
1
1
  Dummy::Application.routes.draw do
2
- match "/subclassed_pages/*id" => 'subclassed_pages#show', :format => false
3
- match "/alternative_finder/*id" => 'alternative_finder#show', :format => false
2
+ get "/subclassed_pages/*id" => 'subclassed_pages#show', :format => false
3
+ get "/alternative_finder/*id" => 'alternative_finder#show', :format => false
4
4
  end
@@ -1,7 +1,11 @@
1
- require 'spec_helper'
1
+ require 'minimal_spec_helper'
2
2
 
3
3
  describe HighVoltage do
4
4
  it 'should be valid' do
5
5
  HighVoltage.should be_a(Module)
6
6
  end
7
+
8
+ it 'should be loadable without preloading rails' do
9
+ expect { require 'high_voltage' }.not_to raise_error
10
+ end
7
11
  end
@@ -0,0 +1,5 @@
1
+ RSpec.configure do |config|
2
+ require 'rspec/expectations'
3
+ config.include RSpec::Matchers
4
+ config.mock_with :rspec
5
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe 'routes' do
4
4
  context 'using default configuration' do
5
5
  it 'should generate normal resource route with id' do
6
- page_path(:id => 'one').should eq '/pages/one'
6
+ page_path('one').should eq '/pages/one'
7
7
  end
8
8
 
9
9
  it 'should generate normal resource route with string' do
@@ -48,7 +48,7 @@ describe 'routes' do
48
48
  end
49
49
  end
50
50
 
51
- context 'using root routing configuration' do
51
+ context 'using top-level routing configuration' do
52
52
  around do |example|
53
53
  cached_high_voltage_route_drawer = HighVoltage.route_drawer
54
54
  HighVoltage.route_drawer = HighVoltage::RouteDrawers::Root
@@ -60,10 +60,6 @@ describe 'routes' do
60
60
  Rails.application.reload_routes!
61
61
  end
62
62
 
63
- it 'should generate normal resource route with id' do
64
- page_path(:id => 'one').should eq '/one'
65
- end
66
-
67
63
  it 'should generate normal resource route with string' do
68
64
  page_path('one').should eq '/one'
69
65
  end
@@ -85,10 +81,6 @@ describe 'routes' do
85
81
  Rails.application.reload_routes!
86
82
  end
87
83
 
88
- it 'should generate normal resource route with id' do
89
- page_path(:id => 'one').should eq '/other_pages/one'
90
- end
91
-
92
84
  it 'should generate normal resource route with string' do
93
85
  page_path('one').should eq '/other_pages/one'
94
86
  end
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,16 @@
1
1
  ENV['RAILS_ENV'] = 'test'
2
2
 
3
3
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ require 'pry'
4
5
  require 'rails/test_help'
5
6
  require 'rspec/rails'
6
7
  require 'capybara/rails'
7
8
 
8
9
  Rails.backtrace_cleaner.remove_silencers!
9
- Capybara.default_driver = :rack_test
10
+ Capybara.default_driver = :rack_test
10
11
  Capybara.default_selector = :css
11
12
 
12
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
13
+ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each {|f| require f}
13
14
 
14
15
  RSpec.configure do |config|
15
16
  require 'rspec/expectations'
@@ -0,0 +1,12 @@
1
+ RSpec.configure do |config|
2
+ config.around(:each, enable_caching: true) do |example|
3
+ ActionController::Base.perform_caching = true
4
+ old_cache_store = ActionController::Base.cache_store
5
+ ActionController::Base.cache_store = :memory_store
6
+
7
+ example.run
8
+
9
+ ActionController::Base.cache_store = old_cache_store
10
+ ActionController::Base.perform_caching = false
11
+ end
12
+ end
@@ -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.2
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matt Jankowski
@@ -17,73 +16,79 @@ authors:
17
16
  autorequire:
18
17
  bindir: bin
19
18
  cert_chain: []
20
- date: 2013-02-17 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
- name: appraisal
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
- version: '0'
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
- version: '0'
34
+ version: 3.1.0
38
35
  - !ruby/object:Gem::Dependency
39
- name: rspec-rails
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
61
- version: 0.4.0
55
+ version: 2.0.3
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
69
- version: 0.4.0
62
+ version: 2.0.3
70
63
  - !ruby/object:Gem::Dependency
71
- name: sqlite3
64
+ name: pry-debugger
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ - !ruby/object:Gem::Dependency
78
+ name: rspec-rails
72
79
  requirement: !ruby/object:Gem::Requirement
73
- none: false
74
80
  requirements:
75
- - - ! '>='
81
+ - - '>='
76
82
  - !ruby/object:Gem::Version
77
83
  version: '0'
78
84
  type: :development
79
85
  prerelease: false
80
86
  version_requirements: !ruby/object:Gem::Requirement
81
- none: false
82
87
  requirements:
83
- - - ! '>='
88
+ - - '>='
84
89
  - !ruby/object:Gem::Version
85
90
  version: '0'
86
- description: Fire in the disco. Fire in the ... taco bell.
91
+ description: Fire in the disco. Fire in the ... taco bell.
87
92
  email:
88
93
  - support@thoughtbot.com
89
94
  executables: []
@@ -100,11 +105,9 @@ files:
100
105
  - NEWS.md
101
106
  - README.md
102
107
  - Rakefile
108
+ - app/controllers/concerns/high_voltage/static_page.rb
103
109
  - app/controllers/high_voltage/pages_controller.rb
104
110
  - config/routes.rb
105
- - gemfiles/rails_3.0.18.gemfile
106
- - gemfiles/rails_3.1.9.gemfile
107
- - gemfiles/rails_3.2.10.gemfile
108
111
  - high_voltage.gemspec
109
112
  - lib/high_voltage.rb
110
113
  - lib/high_voltage/constraints/root_route.rb
@@ -114,7 +117,9 @@ files:
114
117
  - lib/high_voltage/route_drawers/root.rb
115
118
  - lib/high_voltage/version.rb
116
119
  - spec/constraints/root_route_spec.rb
120
+ - spec/controllers/action_caching_controller_spec.rb
117
121
  - spec/controllers/alternative_finder_controller_spec.rb
122
+ - spec/controllers/page_caching_controller_spec.rb
118
123
  - spec/controllers/pages_controller_spec.rb
119
124
  - spec/controllers/subclassed_pages_controller_spec.rb
120
125
  - spec/dummy/Rakefile
@@ -145,6 +150,7 @@ files:
145
150
  - spec/dummy/config/initializers/backtrace_silencers.rb
146
151
  - spec/dummy/config/initializers/inflections.rb
147
152
  - spec/dummy/config/initializers/mime_types.rb
153
+ - spec/dummy/config/initializers/secret_key_base.rb
148
154
  - spec/dummy/config/initializers/secret_token.rb
149
155
  - spec/dummy/config/initializers/session_store.rb
150
156
  - spec/dummy/config/locales/en.yml
@@ -164,35 +170,40 @@ files:
164
170
  - spec/high_voltage/page_finder_spec.rb
165
171
  - spec/high_voltage_spec.rb
166
172
  - spec/integration/navigation_spec.rb
173
+ - spec/minimal_spec_helper.rb
167
174
  - spec/routing/routes_spec.rb
168
175
  - spec/spec_helper.rb
176
+ - spec/support/caching.rb
177
+ - spec/support/concern_reload.rb
169
178
  homepage: http://github.com/thoughtbot/high_voltage
170
- licenses: []
179
+ licenses:
180
+ - MIT
181
+ metadata: {}
171
182
  post_install_message:
172
183
  rdoc_options: []
173
184
  require_paths:
174
185
  - lib
175
186
  required_ruby_version: !ruby/object:Gem::Requirement
176
- none: false
177
187
  requirements:
178
- - - ! '>='
188
+ - - '>='
179
189
  - !ruby/object:Gem::Version
180
190
  version: '0'
181
191
  required_rubygems_version: !ruby/object:Gem::Requirement
182
- none: false
183
192
  requirements:
184
- - - ! '>='
193
+ - - '>='
185
194
  - !ruby/object:Gem::Version
186
195
  version: '0'
187
196
  requirements: []
188
197
  rubyforge_project:
189
- rubygems_version: 1.8.24
198
+ rubygems_version: 2.0.0
190
199
  signing_key:
191
- specification_version: 3
200
+ specification_version: 4
192
201
  summary: Simple static page rendering controller
193
202
  test_files:
194
203
  - spec/constraints/root_route_spec.rb
204
+ - spec/controllers/action_caching_controller_spec.rb
195
205
  - spec/controllers/alternative_finder_controller_spec.rb
206
+ - spec/controllers/page_caching_controller_spec.rb
196
207
  - spec/controllers/pages_controller_spec.rb
197
208
  - spec/controllers/subclassed_pages_controller_spec.rb
198
209
  - spec/dummy/Rakefile
@@ -223,6 +234,7 @@ test_files:
223
234
  - spec/dummy/config/initializers/backtrace_silencers.rb
224
235
  - spec/dummy/config/initializers/inflections.rb
225
236
  - spec/dummy/config/initializers/mime_types.rb
237
+ - spec/dummy/config/initializers/secret_key_base.rb
226
238
  - spec/dummy/config/initializers/secret_token.rb
227
239
  - spec/dummy/config/initializers/session_store.rb
228
240
  - spec/dummy/config/locales/en.yml
@@ -242,6 +254,8 @@ test_files:
242
254
  - spec/high_voltage/page_finder_spec.rb
243
255
  - spec/high_voltage_spec.rb
244
256
  - spec/integration/navigation_spec.rb
257
+ - spec/minimal_spec_helper.rb
245
258
  - spec/routing/routes_spec.rb
246
259
  - spec/spec_helper.rb
247
- has_rdoc:
260
+ - spec/support/caching.rb
261
+ - spec/support/concern_reload.rb
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "3.0.18"
6
-
7
- gemspec :path=>"../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "3.1.9"
6
-
7
- gemspec :path=>"../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "3.2.10"
6
-
7
- gemspec :path=>"../"