high_voltage 1.2.3 → 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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NWVlZTI0NjBiNWVhZTlhNzhkOWNiMzdiYTg3ZDBiYmFkM2M0NGJlZQ==
5
- data.tar.gz: !binary |-
6
- Y2YwZGEzMmI5ZGRkOGQ1MjYyMGU2ZDE0ZjFjYTJmNTM0ODllNGYwMw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MWFlZGU0YzFmOWE5Yzk0NDFhZmU4ZjhiODNlMjAxN2M5MzNjNTU2MWEyMDhi
10
- ZThiNDlkNGFlYzBiMGYwMzU1MzNjYmQ4OTNkODBjYjg0OTI5YjQyZTQ4OTQz
11
- Y2E5MGIwZDFhMjhhYWQyNTBiMzZhODIyZDlmZmY3MTFmYzNiMWE=
12
- data.tar.gz: !binary |-
13
- YjExZjI0Mzc2NTI5ZTJmNjc4OTdhZWZmZmY2Y2EwZTgxOTBkMDQyZDBmNTky
14
- YmQ2NzA0NmJhM2Q3OTJhNDA1YTdjMjllYjQ1MTA5YjhhYjdjOGY5NTM4YjFk
15
- MzEzYjIzMzdiOTcyYmMzZWFjNTRmYTRkZDk3ODA1ZWYyNjc0MzQ=
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,13 +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.20.gemfile
8
- - gemfiles/rails_3.1.12.gemfile
9
- - gemfiles/rails_3.2.13.gemfile
10
- - gemfiles/rails_4.0.0.rc1.gemfile
11
- matrix:
12
- allow_failures:
13
- - gemfile: gemfiles/rails_4.0.0.rc1.gemfile
8
+ - 2.0.0
data/Appraisals CHANGED
@@ -1,5 +1,16 @@
1
- ['4.0.0.rc1', '3.2.13', '3.1.12', '3.0.20'].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,31 +1,16 @@
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
14
  capybara (2.0.3)
30
15
  mime-types (>= 1.16)
31
16
  nokogiri (>= 1.3.3)
@@ -35,49 +20,50 @@ GEM
35
20
  xpath (~> 1.0.0)
36
21
  childprocess (0.3.9)
37
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.8.1)
42
- i18n (0.5.0)
32
+ ffi (1.9.0)
33
+ method_source (0.8.1)
43
34
  mime-types (1.23)
44
- multi_json (1.7.3)
45
- nokogiri (1.5.9)
46
- rack (1.2.3)
47
- rack-mount (0.6.14)
48
- rack (>= 1.0.0)
49
- rack-test (0.5.7)
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)
50
48
  rack (>= 1.0)
51
- railties (3.0.10)
52
- actionpack (= 3.0.10)
53
- activesupport (= 3.0.10)
54
- rake (>= 0.8.7)
55
- rdoc (~> 3.4)
56
- thor (~> 0.14.4)
57
- rake (0.9.2.2)
58
- rdoc (3.9.4)
59
- rspec (2.6.0)
60
- rspec-core (~> 2.6.0)
61
- rspec-expectations (~> 2.6.0)
62
- rspec-mocks (~> 2.6.0)
63
- rspec-core (2.6.4)
64
- 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)
65
56
  diff-lcs (~> 1.1.2)
66
- rspec-mocks (2.6.0)
67
- rspec-rails (2.6.1)
68
- actionpack (~> 3.0)
69
- activesupport (~> 3.0)
70
- railties (~> 3.0)
71
- rspec (~> 2.6.0)
57
+ rspec-mocks (2.1.0)
58
+ rspec-rails (2.1.0)
59
+ rspec (~> 2.1.0)
72
60
  rubyzip (0.9.9)
73
- selenium-webdriver (2.32.1)
61
+ selenium-webdriver (2.33.0)
74
62
  childprocess (>= 0.2.5)
75
63
  multi_json (~> 1.0)
76
64
  rubyzip
77
65
  websocket (~> 1.0.4)
78
- sqlite3 (1.3.4)
79
- thor (0.14.6)
80
- tzinfo (0.3.29)
66
+ slop (3.4.5)
81
67
  websocket (1.0.7)
82
68
  xpath (1.0.0)
83
69
  nokogiri (~> 1.3)
@@ -86,8 +72,9 @@ PLATFORMS
86
72
  ruby
87
73
 
88
74
  DEPENDENCIES
75
+ activesupport (>= 3.1.0)
89
76
  appraisal
90
77
  capybara (= 2.0.3)
91
78
  high_voltage!
79
+ pry-debugger
92
80
  rspec-rails
93
- sqlite3
data/NEWS.md CHANGED
@@ -1,7 +1,17 @@
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
+
1
11
  New for 1.2.3:
2
12
  + Updates for Rails 4 compatibility.
3
13
  + Fix for Rails 4 circular dependency error.
4
- + Add ability to load HighVolage outside of rails. Require `attribute_accessors`
14
+ + Add ability to load High Voltage outside of rails. Require `attribute_accessors`
5
15
 
6
16
  New for 1.2.2:
7
17
  + Bug fix for RootRoute constraint. Support haml, slim, etc.
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
- get '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,20 +62,34 @@ 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
- get '/: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:
86
+
87
+ ```ruby
88
+ # app/views/layouts/application.html.erb
89
+ <title><%= yield(:page_title) %></title>
90
+ ```
91
+
92
+ #### Top-level routes
79
93
 
80
94
  You can remove the directory `pages` from the URL path and serve up routes from
81
95
  the root of the domain path:
@@ -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
- get "/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
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,29 +1,3 @@
1
1
  class HighVoltage::PagesController < ApplicationController
2
- layout Proc.new { |_| HighVoltage.layout }
3
-
4
- rescue_from ActionView::MissingTemplate do |exception|
5
- if exception.message =~ %r{Missing template #{page_finder.content_path}}
6
- raise ActionController::RoutingError, "No such page: #{params[:id]}"
7
- else
8
- raise exception
9
- end
10
- end
11
-
12
- def show
13
- render :template => current_page
14
- end
15
-
16
- private
17
-
18
- def current_page
19
- page_finder.find
20
- end
21
-
22
- def page_finder
23
- page_finder_factory.new(params[:id])
24
- end
25
-
26
- def page_finder_factory
27
- HighVoltage::PageFinder
28
- end
2
+ include HighVoltage::StaticPage
29
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")
19
- s.add_development_dependency("rspec-rails")
20
21
  s.add_development_dependency("capybara", "= 2.0.3")
21
- s.add_development_dependency("sqlite3")
22
+ s.add_development_dependency("pry-debugger")
23
+ s.add_development_dependency("rspec-rails")
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.3'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
data/lib/high_voltage.rb CHANGED
@@ -18,6 +18,12 @@ module HighVoltage
18
18
  mattr_accessor :routes
19
19
  @@routes = true
20
20
 
21
+ mattr_accessor :action_caching
22
+ @@action_caching = false
23
+
24
+ mattr_accessor :page_caching
25
+ @@page_caching = false
26
+
21
27
  def self.setup
22
28
  yield self
23
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
+
@@ -0,0 +1 @@
1
+ Dummy::Application.config.secret_key_base = '9c0b876ab8f513cc23d354b6d684c88eb9bc5f73ddc8d5843e7c6ac9176c5819adc2620e220980a3cb818de687753f1bfc56c66c4454b74fc7d432813f8e555a'
@@ -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,14 +1,17 @@
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
 
13
+ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each {|f| require f}
14
+
12
15
  RSpec.configure do |config|
13
16
  require 'rspec/expectations'
14
17
  config.include RSpec::Matchers
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: high_voltage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Jankowski
@@ -16,34 +16,34 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2013-06-15 00:00:00.000000000 Z
19
+ date: 2013-10-05 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: appraisal
22
+ name: activesupport
23
23
  requirement: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ! '>='
25
+ - - '>='
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: 3.1.0
28
28
  type: :development
29
29
  prerelease: false
30
30
  version_requirements: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ! '>='
32
+ - - '>='
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 3.1.0
35
35
  - !ruby/object:Gem::Dependency
36
- name: rspec-rails
36
+ name: appraisal
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ! '>='
39
+ - - '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  type: :development
43
43
  prerelease: false
44
44
  version_requirements: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ! '>='
46
+ - - '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  - !ruby/object:Gem::Dependency
@@ -61,20 +61,34 @@ dependencies:
61
61
  - !ruby/object:Gem::Version
62
62
  version: 2.0.3
63
63
  - !ruby/object:Gem::Dependency
64
- 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
65
79
  requirement: !ruby/object:Gem::Requirement
66
80
  requirements:
67
- - - ! '>='
81
+ - - '>='
68
82
  - !ruby/object:Gem::Version
69
83
  version: '0'
70
84
  type: :development
71
85
  prerelease: false
72
86
  version_requirements: !ruby/object:Gem::Requirement
73
87
  requirements:
74
- - - ! '>='
88
+ - - '>='
75
89
  - !ruby/object:Gem::Version
76
90
  version: '0'
77
- description: Fire in the disco. Fire in the ... taco bell.
91
+ description: Fire in the disco. Fire in the ... taco bell.
78
92
  email:
79
93
  - support@thoughtbot.com
80
94
  executables: []
@@ -91,12 +105,9 @@ files:
91
105
  - NEWS.md
92
106
  - README.md
93
107
  - Rakefile
108
+ - app/controllers/concerns/high_voltage/static_page.rb
94
109
  - app/controllers/high_voltage/pages_controller.rb
95
110
  - config/routes.rb
96
- - gemfiles/rails_3.0.20.gemfile
97
- - gemfiles/rails_3.1.12.gemfile
98
- - gemfiles/rails_3.2.13.gemfile
99
- - gemfiles/rails_4.0.0.rc1.gemfile
100
111
  - high_voltage.gemspec
101
112
  - lib/high_voltage.rb
102
113
  - lib/high_voltage/constraints/root_route.rb
@@ -106,7 +117,9 @@ files:
106
117
  - lib/high_voltage/route_drawers/root.rb
107
118
  - lib/high_voltage/version.rb
108
119
  - spec/constraints/root_route_spec.rb
120
+ - spec/controllers/action_caching_controller_spec.rb
109
121
  - spec/controllers/alternative_finder_controller_spec.rb
122
+ - spec/controllers/page_caching_controller_spec.rb
110
123
  - spec/controllers/pages_controller_spec.rb
111
124
  - spec/controllers/subclassed_pages_controller_spec.rb
112
125
  - spec/dummy/Rakefile
@@ -137,6 +150,7 @@ files:
137
150
  - spec/dummy/config/initializers/backtrace_silencers.rb
138
151
  - spec/dummy/config/initializers/inflections.rb
139
152
  - spec/dummy/config/initializers/mime_types.rb
153
+ - spec/dummy/config/initializers/secret_key_base.rb
140
154
  - spec/dummy/config/initializers/secret_token.rb
141
155
  - spec/dummy/config/initializers/session_store.rb
142
156
  - spec/dummy/config/locales/en.yml
@@ -159,8 +173,11 @@ files:
159
173
  - spec/minimal_spec_helper.rb
160
174
  - spec/routing/routes_spec.rb
161
175
  - spec/spec_helper.rb
176
+ - spec/support/caching.rb
177
+ - spec/support/concern_reload.rb
162
178
  homepage: http://github.com/thoughtbot/high_voltage
163
- licenses: []
179
+ licenses:
180
+ - MIT
164
181
  metadata: {}
165
182
  post_install_message:
166
183
  rdoc_options: []
@@ -168,23 +185,25 @@ require_paths:
168
185
  - lib
169
186
  required_ruby_version: !ruby/object:Gem::Requirement
170
187
  requirements:
171
- - - ! '>='
188
+ - - '>='
172
189
  - !ruby/object:Gem::Version
173
190
  version: '0'
174
191
  required_rubygems_version: !ruby/object:Gem::Requirement
175
192
  requirements:
176
- - - ! '>='
193
+ - - '>='
177
194
  - !ruby/object:Gem::Version
178
195
  version: '0'
179
196
  requirements: []
180
197
  rubyforge_project:
181
- rubygems_version: 2.0.3
198
+ rubygems_version: 2.0.0
182
199
  signing_key:
183
200
  specification_version: 4
184
201
  summary: Simple static page rendering controller
185
202
  test_files:
186
203
  - spec/constraints/root_route_spec.rb
204
+ - spec/controllers/action_caching_controller_spec.rb
187
205
  - spec/controllers/alternative_finder_controller_spec.rb
206
+ - spec/controllers/page_caching_controller_spec.rb
188
207
  - spec/controllers/pages_controller_spec.rb
189
208
  - spec/controllers/subclassed_pages_controller_spec.rb
190
209
  - spec/dummy/Rakefile
@@ -215,6 +234,7 @@ test_files:
215
234
  - spec/dummy/config/initializers/backtrace_silencers.rb
216
235
  - spec/dummy/config/initializers/inflections.rb
217
236
  - spec/dummy/config/initializers/mime_types.rb
237
+ - spec/dummy/config/initializers/secret_key_base.rb
218
238
  - spec/dummy/config/initializers/secret_token.rb
219
239
  - spec/dummy/config/initializers/session_store.rb
220
240
  - spec/dummy/config/locales/en.yml
@@ -237,3 +257,5 @@ test_files:
237
257
  - spec/minimal_spec_helper.rb
238
258
  - spec/routing/routes_spec.rb
239
259
  - spec/spec_helper.rb
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.20"
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.12"
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.13"
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", "4.0.0.rc1"
6
-
7
- gemspec :path=>"../"