high_voltage 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -2
- data/.travis.yml +1 -9
- data/Appraisals +14 -3
- data/Gemfile.lock +41 -54
- data/NEWS.md +7 -1
- data/README.md +143 -95
- data/Rakefile +11 -10
- data/app/controllers/high_voltage/pages_controller.rb +12 -0
- data/high_voltage.gemspec +4 -3
- data/lib/high_voltage.rb +6 -0
- data/lib/high_voltage/version.rb +1 -1
- data/spec/constraints/root_route_spec.rb +10 -6
- data/spec/controllers/action_caching_controller_spec.rb +26 -0
- data/spec/controllers/page_caching_controller_spec.rb +22 -0
- data/spec/dummy/config/initializers/secret_key_base.rb +1 -0
- data/spec/routing/routes_spec.rb +2 -10
- data/spec/spec_helper.rb +4 -1
- data/spec/support/caching.rb +12 -0
- metadata +45 -15
- checksums.yaml +0 -15
- data/gemfiles/rails_3.0.20.gemfile +0 -7
- data/gemfiles/rails_3.1.12.gemfile +0 -7
- data/gemfiles/rails_3.2.13.gemfile +0 -7
- data/gemfiles/rails_4.0.0.rc1.gemfile +0 -7
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,13 +1,5 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 1.8.7
|
4
3
|
- 1.9.2
|
5
4
|
- 1.9.3
|
6
|
-
|
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
|
5
|
+
- 2.0.0
|
data/Appraisals
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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.
|
4
|
+
high_voltage (1.2.3)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
40
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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.
|
67
|
-
rspec-rails (2.
|
68
|
-
|
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.
|
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
|
-
|
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,13 @@
|
|
1
|
+
New for 1.2.4:
|
2
|
+
+ Add page and action caching
|
3
|
+
+ Remove redundant link style `page_path(id: 'about')` from README
|
4
|
+
+ Clean up Appraisals for Travis-CI
|
5
|
+
+ Remove Ruby 1.8.7 from test suite
|
6
|
+
|
1
7
|
New for 1.2.3:
|
2
8
|
+ Updates for Rails 4 compatibility.
|
3
9
|
+ Fix for Rails 4 circular dependency error.
|
4
|
-
+ Add ability to load
|
10
|
+
+ Add ability to load High Voltage outside of rails. Require `attribute_accessors`
|
5
11
|
|
6
12
|
New for 1.2.2:
|
7
13
|
+ 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
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
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
|
-
|
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
|
67
|
+
You can route the root url to a High Voltage page like this:
|
73
68
|
|
74
|
-
|
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
|
-
####
|
75
|
+
#### Page title's 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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
114
|
+
The default routes can be completely removed by changing the `HighVoltage.routes`
|
115
|
+
to `false`:
|
103
116
|
|
104
|
-
|
105
|
-
|
117
|
+
```ruby
|
118
|
+
# config/initializers/high_voltage.rb
|
119
|
+
HighVoltage.routes = false
|
120
|
+
```
|
106
121
|
|
107
|
-
|
108
|
-
--------
|
122
|
+
#### Content path
|
109
123
|
|
110
|
-
High Voltage uses a default path and folder of 'pages', i.e. 'url.com/pages/contact'
|
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
|
-
|
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).
|
115
137
|
|
116
|
-
|
117
|
-
|
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
|
+
```
|
146
|
+
|
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,106 @@ 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
169
|
Override the default route:
|
130
170
|
|
131
|
-
|
132
|
-
|
171
|
+
```ruby
|
172
|
+
# config/routes.rb
|
173
|
+
get "/pages/*id" => 'pages#show', :as => :page, :format => false
|
133
174
|
|
134
|
-
|
135
|
-
|
175
|
+
# if routing the root path, update for your controller
|
176
|
+
root :to => 'pages#show', :id => 'home'
|
177
|
+
```
|
136
178
|
|
137
179
|
Then modify it to subclass from High Voltage, adding whatever you need:
|
138
180
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
181
|
+
```ruby
|
182
|
+
# app/controllers/pages_controller.rb
|
183
|
+
class PagesController < HighVoltage::PagesController
|
184
|
+
before_filter :authenticate
|
185
|
+
layout :layout_for_page
|
186
|
+
|
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
|
+
end
|
197
|
+
```
|
153
198
|
|
154
|
-
Custom finding
|
155
|
-
--------------
|
199
|
+
## Custom finding
|
156
200
|
|
157
201
|
You can further control the algorithm used to find pages by overriding
|
158
202
|
the `page_finder_factory` method:
|
159
203
|
|
160
|
-
|
161
|
-
|
204
|
+
```ruby
|
205
|
+
# app/controllers/pages_controller.rb
|
206
|
+
class PagesController < HighVoltage::PagesController
|
207
|
+
private
|
162
208
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
209
|
+
def page_finder_factory
|
210
|
+
Rot13PageFinder
|
211
|
+
end
|
212
|
+
end
|
213
|
+
```
|
167
214
|
|
168
215
|
The easiest thing is to subclass `HighVoltage::PageFinder`, which
|
169
216
|
provides you with `page_id`:
|
170
217
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
218
|
+
```ruby
|
219
|
+
class Rot13PageFinder < HighVoltage::PageFinder
|
220
|
+
def find
|
221
|
+
paths = super.split('/')
|
222
|
+
directory = paths[0..-2]
|
223
|
+
filename = paths[-1].tr('a-z','n-za-m')
|
176
224
|
|
177
|
-
|
178
|
-
|
179
|
-
|
225
|
+
File.join(*directory, filename)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
```
|
180
229
|
|
181
230
|
Use this to create a custom file mapping, clean filenames for your file
|
182
231
|
system, A/B test, and so on.
|
183
232
|
|
184
|
-
Testing
|
185
|
-
-------
|
233
|
+
## Testing
|
186
234
|
|
187
235
|
You can test your static pages using [RSpec](https://github.com/rspec/rspec-rails)
|
188
236
|
and [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers):
|
189
237
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
it { should respond_with(:success) }
|
199
|
-
it { should render_template(page) }
|
200
|
-
end
|
238
|
+
```ruby
|
239
|
+
# spec/controllers/pages_controller_spec.rb
|
240
|
+
describe PagesController, '#show' do
|
241
|
+
%w(earn_money screencast about contact).each do |page|
|
242
|
+
context 'on GET to /pages/#{page}' do
|
243
|
+
before do
|
244
|
+
get :show, :id => page
|
201
245
|
end
|
246
|
+
|
247
|
+
it { should respond_with(:success) }
|
248
|
+
it { should render_template(page) }
|
202
249
|
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
```
|
203
253
|
|
204
254
|
If you're not using a custom PagesController be sure to test
|
205
255
|
`HighVoltage::PagesController` instead.
|
206
256
|
|
207
257
|
Enjoy!
|
208
258
|
|
209
|
-
Contributing
|
210
|
-
------------
|
259
|
+
## Contributing
|
211
260
|
|
212
|
-
Please see CONTRIBUTING.md
|
261
|
+
Please see [CONTRIBUTING.md](https://github.com/thoughtbot/high_voltage/blob/master/CONTRIBUTING.md)
|
262
|
+
for details.
|
213
263
|
|
214
|
-
Credits
|
215
|
-
-------
|
264
|
+
## Credits
|
216
265
|
|
217
266
|
![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
|
218
267
|
|
@@ -222,8 +271,7 @@ Thank you to all [the contributors](https://github.com/thoughtbot/high_voltage/c
|
|
222
271
|
|
223
272
|
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
224
273
|
|
225
|
-
License
|
226
|
-
-------
|
274
|
+
## License
|
227
275
|
|
228
276
|
High Voltage is Copyright © 2009-2013 thoughtbot. It is free software, and may
|
229
277
|
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
|
-
|
9
|
-
|
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
|
-
|
17
|
-
|
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
|
@@ -1,6 +1,18 @@
|
|
1
1
|
class HighVoltage::PagesController < ApplicationController
|
2
2
|
layout Proc.new { |_| HighVoltage.layout }
|
3
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
|
+
|
4
16
|
rescue_from ActionView::MissingTemplate do |exception|
|
5
17
|
if exception.message =~ %r{Missing template #{page_finder.content_path}}
|
6
18
|
raise ActionController::RoutingError, "No such page: #{params[:id]}"
|
data/high_voltage.gemspec
CHANGED
@@ -8,15 +8,16 @@ 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.
|
11
|
+
s.description = 'Fire in the disco. Fire in the ... taco bell.'
|
12
12
|
|
13
13
|
s.files = `git ls-files`.split("\n")
|
14
14
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
|
18
|
+
s.add_development_dependency("activesupport", ">= 3.1.0")
|
18
19
|
s.add_development_dependency("appraisal")
|
19
|
-
s.add_development_dependency("rspec-rails")
|
20
20
|
s.add_development_dependency("capybara", "= 2.0.3")
|
21
|
-
s.add_development_dependency("
|
21
|
+
s.add_development_dependency("pry-debugger")
|
22
|
+
s.add_development_dependency("rspec-rails")
|
22
23
|
end
|
data/lib/high_voltage.rb
CHANGED
data/lib/high_voltage/version.rb
CHANGED
@@ -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 =
|
7
|
-
Dir.stub
|
6
|
+
request = double(path: 'index')
|
7
|
+
Dir.stub(:glob).and_return(['about.html.erb'])
|
8
8
|
|
9
|
-
HighVoltage::Constraints::RootRoute.matches?(request)
|
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 =
|
16
|
-
File.stub
|
17
|
+
request = double(path: 'index')
|
18
|
+
File.stub(:glob).and_return([])
|
19
|
+
|
20
|
+
result = HighVoltage::Constraints::RootRoute.matches?(request)
|
17
21
|
|
18
|
-
|
22
|
+
expect(result).to be_false
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -0,0 +1,26 @@
|
|
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
|
+
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
|
11
|
+
end
|
12
|
+
|
13
|
+
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
|
20
|
+
end
|
21
|
+
|
22
|
+
def action_was_cached(page)
|
23
|
+
ActionController::Base.cache_store.exist?("views/test.host#{page_path(page)}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,22 @@
|
|
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
|
+
|
9
|
+
load('high_voltage/pages_controller.rb')
|
10
|
+
get :show, id: 'exists'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'does not cache the page when page_caching is set to false', enable_caching: true do
|
14
|
+
controller.should_receive(:cache_page).never
|
15
|
+
|
16
|
+
HighVoltage.page_caching = false
|
17
|
+
|
18
|
+
load('high_voltage/pages_controller.rb')
|
19
|
+
get :show, id: 'exists'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
Dummy::Application.config.secret_key_base = '9c0b876ab8f513cc23d354b6d684c88eb9bc5f73ddc8d5843e7c6ac9176c5819adc2620e220980a3cb818de687753f1bfc56c66c4454b74fc7d432813f8e555a'
|
data/spec/routing/routes_spec.rb
CHANGED
@@ -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(
|
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
|
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
|
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
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: high_voltage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Matt Jankowski
|
@@ -16,25 +17,28 @@ authors:
|
|
16
17
|
autorequire:
|
17
18
|
bindir: bin
|
18
19
|
cert_chain: []
|
19
|
-
date: 2013-
|
20
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
23
|
+
name: activesupport
|
23
24
|
requirement: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ! '>='
|
26
28
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
29
|
+
version: 3.1.0
|
28
30
|
type: :development
|
29
31
|
prerelease: false
|
30
32
|
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
31
34
|
requirements:
|
32
35
|
- - ! '>='
|
33
36
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
37
|
+
version: 3.1.0
|
35
38
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
39
|
+
name: appraisal
|
37
40
|
requirement: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ! '>='
|
40
44
|
- !ruby/object:Gem::Version
|
@@ -42,6 +46,7 @@ dependencies:
|
|
42
46
|
type: :development
|
43
47
|
prerelease: false
|
44
48
|
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
45
50
|
requirements:
|
46
51
|
- - ! '>='
|
47
52
|
- !ruby/object:Gem::Version
|
@@ -49,6 +54,7 @@ dependencies:
|
|
49
54
|
- !ruby/object:Gem::Dependency
|
50
55
|
name: capybara
|
51
56
|
requirement: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
52
58
|
requirements:
|
53
59
|
- - '='
|
54
60
|
- !ruby/object:Gem::Version
|
@@ -56,13 +62,31 @@ dependencies:
|
|
56
62
|
type: :development
|
57
63
|
prerelease: false
|
58
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
59
66
|
requirements:
|
60
67
|
- - '='
|
61
68
|
- !ruby/object:Gem::Version
|
62
69
|
version: 2.0.3
|
63
70
|
- !ruby/object:Gem::Dependency
|
64
|
-
name:
|
71
|
+
name: pry-debugger
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: rspec-rails
|
65
88
|
requirement: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
66
90
|
requirements:
|
67
91
|
- - ! '>='
|
68
92
|
- !ruby/object:Gem::Version
|
@@ -70,11 +94,12 @@ dependencies:
|
|
70
94
|
type: :development
|
71
95
|
prerelease: false
|
72
96
|
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
75
100
|
- !ruby/object:Gem::Version
|
76
101
|
version: '0'
|
77
|
-
description: Fire in the disco.
|
102
|
+
description: Fire in the disco. Fire in the ... taco bell.
|
78
103
|
email:
|
79
104
|
- support@thoughtbot.com
|
80
105
|
executables: []
|
@@ -93,10 +118,6 @@ files:
|
|
93
118
|
- Rakefile
|
94
119
|
- app/controllers/high_voltage/pages_controller.rb
|
95
120
|
- 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
121
|
- high_voltage.gemspec
|
101
122
|
- lib/high_voltage.rb
|
102
123
|
- lib/high_voltage/constraints/root_route.rb
|
@@ -106,7 +127,9 @@ files:
|
|
106
127
|
- lib/high_voltage/route_drawers/root.rb
|
107
128
|
- lib/high_voltage/version.rb
|
108
129
|
- spec/constraints/root_route_spec.rb
|
130
|
+
- spec/controllers/action_caching_controller_spec.rb
|
109
131
|
- spec/controllers/alternative_finder_controller_spec.rb
|
132
|
+
- spec/controllers/page_caching_controller_spec.rb
|
110
133
|
- spec/controllers/pages_controller_spec.rb
|
111
134
|
- spec/controllers/subclassed_pages_controller_spec.rb
|
112
135
|
- spec/dummy/Rakefile
|
@@ -137,6 +160,7 @@ files:
|
|
137
160
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
138
161
|
- spec/dummy/config/initializers/inflections.rb
|
139
162
|
- spec/dummy/config/initializers/mime_types.rb
|
163
|
+
- spec/dummy/config/initializers/secret_key_base.rb
|
140
164
|
- spec/dummy/config/initializers/secret_token.rb
|
141
165
|
- spec/dummy/config/initializers/session_store.rb
|
142
166
|
- spec/dummy/config/locales/en.yml
|
@@ -159,32 +183,36 @@ files:
|
|
159
183
|
- spec/minimal_spec_helper.rb
|
160
184
|
- spec/routing/routes_spec.rb
|
161
185
|
- spec/spec_helper.rb
|
186
|
+
- spec/support/caching.rb
|
162
187
|
homepage: http://github.com/thoughtbot/high_voltage
|
163
188
|
licenses: []
|
164
|
-
metadata: {}
|
165
189
|
post_install_message:
|
166
190
|
rdoc_options: []
|
167
191
|
require_paths:
|
168
192
|
- lib
|
169
193
|
required_ruby_version: !ruby/object:Gem::Requirement
|
194
|
+
none: false
|
170
195
|
requirements:
|
171
196
|
- - ! '>='
|
172
197
|
- !ruby/object:Gem::Version
|
173
198
|
version: '0'
|
174
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
|
+
none: false
|
175
201
|
requirements:
|
176
202
|
- - ! '>='
|
177
203
|
- !ruby/object:Gem::Version
|
178
204
|
version: '0'
|
179
205
|
requirements: []
|
180
206
|
rubyforge_project:
|
181
|
-
rubygems_version:
|
207
|
+
rubygems_version: 1.8.23
|
182
208
|
signing_key:
|
183
|
-
specification_version:
|
209
|
+
specification_version: 3
|
184
210
|
summary: Simple static page rendering controller
|
185
211
|
test_files:
|
186
212
|
- spec/constraints/root_route_spec.rb
|
213
|
+
- spec/controllers/action_caching_controller_spec.rb
|
187
214
|
- spec/controllers/alternative_finder_controller_spec.rb
|
215
|
+
- spec/controllers/page_caching_controller_spec.rb
|
188
216
|
- spec/controllers/pages_controller_spec.rb
|
189
217
|
- spec/controllers/subclassed_pages_controller_spec.rb
|
190
218
|
- spec/dummy/Rakefile
|
@@ -215,6 +243,7 @@ test_files:
|
|
215
243
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
216
244
|
- spec/dummy/config/initializers/inflections.rb
|
217
245
|
- spec/dummy/config/initializers/mime_types.rb
|
246
|
+
- spec/dummy/config/initializers/secret_key_base.rb
|
218
247
|
- spec/dummy/config/initializers/secret_token.rb
|
219
248
|
- spec/dummy/config/initializers/session_store.rb
|
220
249
|
- spec/dummy/config/locales/en.yml
|
@@ -237,3 +266,4 @@ test_files:
|
|
237
266
|
- spec/minimal_spec_helper.rb
|
238
267
|
- spec/routing/routes_spec.rb
|
239
268
|
- spec/spec_helper.rb
|
269
|
+
- spec/support/caching.rb
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
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=
|