high_voltage 1.2.2 → 2.1.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 +7 -0
- data/.gitignore +2 -2
- data/.travis.yml +5 -6
- data/Appraisals +14 -3
- data/Gemfile.lock +43 -67
- data/NEWS.md +22 -0
- data/README.md +188 -104
- data/Rakefile +11 -10
- data/app/controllers/concerns/high_voltage/static_page.rb +42 -0
- data/app/controllers/high_voltage/pages_controller.rb +1 -28
- data/config/routes.rb +5 -0
- data/high_voltage.gemspec +5 -3
- data/lib/high_voltage/configuration.rb +33 -0
- data/lib/high_voltage/engine.rb +9 -0
- data/lib/high_voltage/version.rb +1 -1
- data/lib/high_voltage.rb +5 -17
- data/spec/constraints/root_route_spec.rb +10 -6
- data/spec/controllers/action_caching_controller_spec.rb +27 -0
- data/spec/controllers/page_caching_controller_spec.rb +28 -0
- data/spec/controllers/pages_controller_spec.rb +8 -18
- data/spec/dummy/config/environments/test.rb +1 -2
- data/spec/dummy/config/initializers/secret_key_base.rb +1 -0
- data/spec/dummy/config/routes.rb +2 -2
- data/spec/dummy/public/pages/exists.html +0 -0
- data/spec/high_voltage/configuration_spec.rb +25 -0
- data/spec/high_voltage_spec.rb +5 -1
- data/spec/minimal_spec_helper.rb +5 -0
- data/spec/requests/home_page_spec.rb +13 -0
- data/spec/routing/routes_spec.rb +47 -57
- data/spec/spec_helper.rb +13 -5
- data/spec/support/caching.rb +15 -0
- data/spec/support/concern_reload.rb +11 -0
- metadata +61 -40
- data/gemfiles/rails_3.0.18.gemfile +0 -7
- data/gemfiles/rails_3.1.9.gemfile +0 -7
- data/gemfiles/rails_3.2.10.gemfile +0 -7
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 6132908ee3ceb8d0bd92c7904926e07aa25d33fa
|
|
4
|
+
data.tar.gz: 7380d36e82d395f54ba6a360ec6bf22d3a6d1f61
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 46412825479d480b85bb248ac95c08f8428b8b8e95f0c1365ff5430377d197cfcf9faf1a3ba83f94fccb34ee4bf5c9c19ee43d3d2b49a88ec53549096a148c9d
|
|
7
|
+
data.tar.gz: 012bbf16df86ae556196514c59c21b963d9300a82245663ec0ae2eee0c007e66ceac20e21dba0072d9abd3cfac81af36ee82dd109864883cca6af97f80b2a38a
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
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,94 +1,70 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
high_voltage (1.
|
|
4
|
+
high_voltage (2.1.0)
|
|
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
|
-
|
|
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.
|
|
36
|
-
childprocess (0.
|
|
37
|
-
ffi (~> 1.0.
|
|
20
|
+
xpath (~> 1.0.0)
|
|
21
|
+
childprocess (0.3.9)
|
|
22
|
+
ffi (~> 1.0, >= 1.0.11)
|
|
23
|
+
coderay (1.0.9)
|
|
38
24
|
diff-lcs (1.1.3)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
rack
|
|
25
|
+
ffi (1.9.0)
|
|
26
|
+
method_source (0.8.1)
|
|
27
|
+
mime-types (1.23)
|
|
28
|
+
mini_portile (0.5.1)
|
|
29
|
+
multi_json (1.7.7)
|
|
30
|
+
nokogiri (1.6.0)
|
|
31
|
+
mini_portile (~> 0.5.0)
|
|
32
|
+
pry (0.9.12.2)
|
|
33
|
+
coderay (~> 1.0.5)
|
|
34
|
+
method_source (~> 0.8)
|
|
35
|
+
slop (~> 3.4)
|
|
36
|
+
rack (1.5.2)
|
|
37
|
+
rack-test (0.6.2)
|
|
51
38
|
rack (>= 1.0)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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)
|
|
39
|
+
rake (10.1.0)
|
|
40
|
+
rspec (2.1.0)
|
|
41
|
+
rspec-core (~> 2.1.0)
|
|
42
|
+
rspec-expectations (~> 2.1.0)
|
|
43
|
+
rspec-mocks (~> 2.1.0)
|
|
44
|
+
rspec-core (2.1.0)
|
|
45
|
+
rspec-expectations (2.1.0)
|
|
66
46
|
diff-lcs (~> 1.1.2)
|
|
67
|
-
rspec-mocks (2.
|
|
68
|
-
rspec-rails (2.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
selenium-webdriver (2.5.0)
|
|
75
|
-
childprocess (>= 0.2.1)
|
|
76
|
-
ffi (>= 1.0.7)
|
|
77
|
-
json_pure
|
|
47
|
+
rspec-mocks (2.1.0)
|
|
48
|
+
rspec-rails (2.1.0)
|
|
49
|
+
rspec (~> 2.1.0)
|
|
50
|
+
rubyzip (0.9.9)
|
|
51
|
+
selenium-webdriver (2.33.0)
|
|
52
|
+
childprocess (>= 0.2.5)
|
|
53
|
+
multi_json (~> 1.0)
|
|
78
54
|
rubyzip
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
xpath (0.1.4)
|
|
55
|
+
websocket (~> 1.0.4)
|
|
56
|
+
slop (3.4.5)
|
|
57
|
+
websocket (1.0.7)
|
|
58
|
+
xpath (1.0.0)
|
|
84
59
|
nokogiri (~> 1.3)
|
|
85
60
|
|
|
86
61
|
PLATFORMS
|
|
87
62
|
ruby
|
|
88
63
|
|
|
89
64
|
DEPENDENCIES
|
|
65
|
+
activesupport (>= 3.1.0)
|
|
90
66
|
appraisal
|
|
91
|
-
capybara (
|
|
67
|
+
capybara (= 2.0.3)
|
|
92
68
|
high_voltage!
|
|
69
|
+
pry
|
|
93
70
|
rspec-rails
|
|
94
|
-
sqlite3
|
data/NEWS.md
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
|
+
New for 2.1.0:
|
|
2
|
+
+ Extract configuration options into a module
|
|
3
|
+
+ Add ability to configure whether layout is cached with action_caching
|
|
4
|
+
+ Add ability to configure a `home_page` for root routing to High Voltage
|
|
5
|
+
+ Update README with new block style config
|
|
6
|
+
|
|
7
|
+
New for 2.0.0:
|
|
8
|
+
+ Extract PagesController into a module
|
|
9
|
+
+ Update README with module usage instructions
|
|
10
|
+
|
|
11
|
+
New for 1.2.4:
|
|
12
|
+
+ Add page and action caching
|
|
13
|
+
+ Remove redundant link style `page_path(id: 'about')` from README
|
|
14
|
+
+ Clean up Appraisals for Travis-CI
|
|
15
|
+
+ Remove Ruby 1.8.7 from test suite
|
|
16
|
+
|
|
17
|
+
New for 1.2.3:
|
|
18
|
+
+ Updates for Rails 4 compatibility.
|
|
19
|
+
+ Fix for Rails 4 circular dependency error.
|
|
20
|
+
+ Add ability to load High Voltage outside of rails. Require `attribute_accessors`
|
|
21
|
+
|
|
1
22
|
New for 1.2.2:
|
|
2
23
|
+ Bug fix for RootRoute constraint. Support haml, slim, etc.
|
|
3
24
|
+ README updated for root routes.
|
|
25
|
+
|
|
4
26
|
New for 1.2.1:
|
|
5
27
|
+ Ability to disable HighVoltage routes.
|
|
6
28
|
+ 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
|
-
|
|
17
|
+
```ruby
|
|
18
|
+
gem 'high_voltage', '~> 2.1.0'
|
|
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,52 +31,58 @@ 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
|
-
|
|
48
|
-
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
#### Routing overview
|
|
49
49
|
|
|
50
50
|
By default, the static page routes will be like /pages/:id (where :id is the view filename).
|
|
51
51
|
|
|
52
52
|
If you want to route to a static page in another location (for example, a homepage), do this:
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
```ruby
|
|
55
|
+
get 'pages/home' => 'high_voltage/pages#show', id: 'home'
|
|
56
|
+
```
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
In that case, you'd need an `app/views/pages/home.html.erb` file.
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
want to generate a named route (with the :as routing option) for some route which will be handled
|
|
62
|
-
by High Voltage, make sure not to use :page as the name, because that will conflict with the named
|
|
63
|
-
route generated by High Voltage itself.
|
|
60
|
+
Generally speaking, you need to route to the 'show' action with an `:id` param of the view filename.
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get
|
|
62
|
+
High Voltage will generate a named route method of `page_path`. If you want to generate
|
|
63
|
+
your own named route (with the :as routing option), make sure not to use `:page`
|
|
64
|
+
as it will conflict with the High Voltage named route.
|
|
69
65
|
|
|
70
66
|
#### Specifying a root path
|
|
71
67
|
|
|
72
|
-
You can
|
|
68
|
+
You can configure the root route to a High Voltage page like this:
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
# config/initializers/high_voltage.rb
|
|
72
|
+
HighVoltage.configure do |config|
|
|
73
|
+
config.home_page = 'home'
|
|
74
|
+
end
|
|
75
|
+
```
|
|
73
76
|
|
|
74
|
-
|
|
77
|
+
Which will render the page from `app/views/pages/home.html.erb` when the '/'
|
|
78
|
+
route of the site is accessed.
|
|
75
79
|
|
|
76
|
-
|
|
80
|
+
Note: High Voltage also creates a search engine friendly 301 redirect. Any attempt to
|
|
81
|
+
access the path '/home' will be redirected to '/'.
|
|
77
82
|
|
|
78
|
-
####
|
|
83
|
+
#### Top-level routes
|
|
79
84
|
|
|
80
|
-
You can remove the directory `pages` from the URL path and serve up routes from
|
|
85
|
+
You can remove the directory `pages` from the URL path and serve up routes from
|
|
81
86
|
the root of the domain path:
|
|
82
87
|
|
|
83
88
|
http://www.example.com/about
|
|
@@ -88,33 +93,90 @@ Would look for corresponding files:
|
|
|
88
93
|
app/views/pages/about.html.erb
|
|
89
94
|
app/views/pages/company.html.erb
|
|
90
95
|
|
|
91
|
-
This is accomplished by
|
|
96
|
+
This is accomplished by setting the `route_drawer` to `HighVoltage::RouteDrawers::Root`
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
```ruby
|
|
99
|
+
# config/initializers/high_voltage.rb
|
|
100
|
+
HighVoltage.configure do |config|
|
|
101
|
+
config.route_drawer = HighVoltage::RouteDrawers::Root
|
|
102
|
+
end
|
|
103
|
+
```
|
|
98
104
|
|
|
99
105
|
#### Disabling routes
|
|
100
106
|
|
|
101
|
-
The default routes can be completely removed by
|
|
102
|
-
|
|
107
|
+
The default routes can be completely removed by setting the `routes` to `false`:
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
# config/initializers/high_voltage.rb
|
|
111
|
+
HighVoltage.configure do |config|
|
|
112
|
+
config.routes = false
|
|
113
|
+
end
|
|
114
|
+
```
|
|
103
115
|
|
|
104
|
-
|
|
105
|
-
HighVoltage.routes = false
|
|
116
|
+
#### Page titles and meta-data
|
|
106
117
|
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
We suggest using `content_for` and `yield` for setting custom page titles and
|
|
119
|
+
meta-data on High Voltage pages.
|
|
109
120
|
|
|
110
|
-
|
|
121
|
+
```ruby
|
|
122
|
+
# app/views/pages/about.html.erb
|
|
123
|
+
<%= content_for :page_title, 'About Us - Custom page title' %>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Then print the contents of `:title` into the layout:
|
|
127
|
+
|
|
128
|
+
```ruby
|
|
129
|
+
# app/views/layouts/application.html.erb
|
|
130
|
+
<title><%= yield(:page_title) %></title>
|
|
131
|
+
```
|
|
132
|
+
#### Content path
|
|
133
|
+
|
|
134
|
+
High Voltage uses a default path and folder of 'pages', i.e. 'url.com/pages/contact',
|
|
135
|
+
'app/views/pages'.
|
|
111
136
|
|
|
112
137
|
You can change this in an initializer:
|
|
113
138
|
|
|
114
|
-
|
|
139
|
+
```ruby
|
|
140
|
+
# config/initializers/high_voltage.rb
|
|
141
|
+
HighVoltage.configure do |config|
|
|
142
|
+
config.content_path = 'site/'
|
|
143
|
+
end
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
#### Caching
|
|
147
|
+
|
|
148
|
+
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).
|
|
149
|
+
|
|
150
|
+
To enable action-caching you can add the following to your initializer:
|
|
151
|
+
|
|
152
|
+
```ruby
|
|
153
|
+
# config/initializers/high_voltage.rb
|
|
154
|
+
HighVolgate.configure do |config|
|
|
155
|
+
config.action_caching = true
|
|
156
|
+
config.action_caching_layout = false # optionally do not cache layout. default is true.
|
|
157
|
+
end
|
|
158
|
+
```
|
|
115
159
|
|
|
116
|
-
|
|
117
|
-
|
|
160
|
+
To enable page-caching:
|
|
161
|
+
|
|
162
|
+
```ruby
|
|
163
|
+
# config/initializers/high_voltage.rb
|
|
164
|
+
HighVolgate.configure do |config|
|
|
165
|
+
config.page_caching = true
|
|
166
|
+
end
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
High Voltage will use your default cache store to store action caches.
|
|
170
|
+
|
|
171
|
+
Using caching with Ruby on Rails 4 or higher requires gems:
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
# Gemfile
|
|
175
|
+
gem 'actionpack-action_caching'
|
|
176
|
+
gem 'actionpack-page_caching'
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Override
|
|
118
180
|
|
|
119
181
|
Most common reasons to override?
|
|
120
182
|
|
|
@@ -122,97 +184,120 @@ Most common reasons to override?
|
|
|
122
184
|
* You need to render different layouts for different pages.
|
|
123
185
|
* You need to render a partial from the `app/views/pages` directory.
|
|
124
186
|
|
|
125
|
-
Create a PagesController of your own:
|
|
187
|
+
Create a `PagesController` of your own:
|
|
126
188
|
|
|
127
189
|
$ rails generate controller pages
|
|
128
190
|
|
|
129
|
-
|
|
191
|
+
Disable the default routes:
|
|
192
|
+
|
|
193
|
+
```ruby
|
|
194
|
+
# config/initializers/high_voltage.rb
|
|
195
|
+
HighVoltage.configure do |config|
|
|
196
|
+
config.routes = false
|
|
197
|
+
end
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Define a route for the new `PagesController`:
|
|
201
|
+
|
|
202
|
+
```ruby
|
|
203
|
+
# config/routes.rb
|
|
204
|
+
get "/pages/*id" => 'pages#show', as: :page, format: false
|
|
130
205
|
|
|
131
|
-
|
|
132
|
-
|
|
206
|
+
# if routing the root path, update for your controller
|
|
207
|
+
root to: 'pages#show', id: 'home'
|
|
208
|
+
```
|
|
133
209
|
|
|
134
|
-
|
|
135
|
-
root :to => 'pages#show', :id => 'home'
|
|
210
|
+
Then modify new `PagesController` to include the High Voltage static page concern:
|
|
136
211
|
|
|
137
|
-
|
|
212
|
+
```ruby
|
|
213
|
+
# app/controllers/pages_controller.rb
|
|
214
|
+
class PagesController < ApplicationController
|
|
215
|
+
include HighVoltage::StaticPage
|
|
138
216
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
layout :layout_for_page
|
|
217
|
+
before_filter :authenticate
|
|
218
|
+
layout :layout_for_page
|
|
142
219
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
end
|
|
220
|
+
private
|
|
221
|
+
|
|
222
|
+
def layout_for_page
|
|
223
|
+
case params[:id]
|
|
224
|
+
when 'home'
|
|
225
|
+
'home'
|
|
226
|
+
else
|
|
227
|
+
'application'
|
|
152
228
|
end
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
```
|
|
153
232
|
|
|
154
|
-
Custom finding
|
|
155
|
-
--------------
|
|
233
|
+
## Custom finding
|
|
156
234
|
|
|
157
235
|
You can further control the algorithm used to find pages by overriding
|
|
158
236
|
the `page_finder_factory` method:
|
|
159
237
|
|
|
160
|
-
|
|
161
|
-
|
|
238
|
+
```ruby
|
|
239
|
+
# app/controllers/pages_controller.rb
|
|
240
|
+
class PagesController < ApplicationController
|
|
241
|
+
include HighVoltage::StaticPage
|
|
162
242
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
243
|
+
private
|
|
244
|
+
|
|
245
|
+
def page_finder_factory
|
|
246
|
+
Rot13PageFinder
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
```
|
|
167
250
|
|
|
168
251
|
The easiest thing is to subclass `HighVoltage::PageFinder`, which
|
|
169
252
|
provides you with `page_id`:
|
|
170
253
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
254
|
+
```ruby
|
|
255
|
+
class Rot13PageFinder < HighVoltage::PageFinder
|
|
256
|
+
def find
|
|
257
|
+
paths = super.split('/')
|
|
258
|
+
directory = paths[0..-2]
|
|
259
|
+
filename = paths[-1].tr('a-z','n-za-m')
|
|
176
260
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
261
|
+
File.join(*directory, filename)
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
```
|
|
180
265
|
|
|
181
266
|
Use this to create a custom file mapping, clean filenames for your file
|
|
182
267
|
system, A/B test, and so on.
|
|
183
268
|
|
|
184
|
-
Testing
|
|
185
|
-
-------
|
|
269
|
+
## Testing
|
|
186
270
|
|
|
187
|
-
You can test your static pages using [RSpec](https://github.com/rspec/rspec-rails)
|
|
271
|
+
You can test your static pages using [RSpec](https://github.com/rspec/rspec-rails)
|
|
188
272
|
and [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers):
|
|
189
273
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
it { should respond_with(:success) }
|
|
199
|
-
it { should render_template(page) }
|
|
200
|
-
end
|
|
274
|
+
```ruby
|
|
275
|
+
# spec/controllers/pages_controller_spec.rb
|
|
276
|
+
describe PagesController, '#show' do
|
|
277
|
+
%w(earn_money screencast about contact).each do |page|
|
|
278
|
+
context 'on GET to /pages/#{page}' do
|
|
279
|
+
before do
|
|
280
|
+
get :show, id: page
|
|
201
281
|
end
|
|
282
|
+
|
|
283
|
+
it { should respond_with(:success) }
|
|
284
|
+
it { should render_template(page) }
|
|
202
285
|
end
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
```
|
|
203
289
|
|
|
204
290
|
If you're not using a custom PagesController be sure to test
|
|
205
291
|
`HighVoltage::PagesController` instead.
|
|
206
292
|
|
|
207
293
|
Enjoy!
|
|
208
294
|
|
|
209
|
-
Contributing
|
|
210
|
-
------------
|
|
295
|
+
## Contributing
|
|
211
296
|
|
|
212
|
-
Please see CONTRIBUTING.md
|
|
297
|
+
Please see [CONTRIBUTING.md](https://github.com/thoughtbot/high_voltage/blob/master/CONTRIBUTING.md)
|
|
298
|
+
for details.
|
|
213
299
|
|
|
214
|
-
Credits
|
|
215
|
-
-------
|
|
300
|
+
## Credits
|
|
216
301
|
|
|
217
302
|

|
|
218
303
|
|
|
@@ -222,8 +307,7 @@ Thank you to all [the contributors](https://github.com/thoughtbot/high_voltage/c
|
|
|
222
307
|
|
|
223
308
|
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
|
224
309
|
|
|
225
|
-
License
|
|
226
|
-
-------
|
|
310
|
+
## License
|
|
227
311
|
|
|
228
312
|
High Voltage is Copyright © 2009-2013 thoughtbot. It is free software, and may
|
|
229
313
|
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
|