high_voltage 1.2.0 → 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 +7 -0
- data/.gitignore +2 -2
- data/.travis.yml +5 -6
- data/Appraisals +14 -3
- data/Gemfile.lock +53 -67
- data/MIT-LICENSE +1 -1
- data/NEWS.md +23 -0
- data/README.md +201 -71
- data/Rakefile +11 -10
- data/app/controllers/concerns/high_voltage/static_page.rb +41 -0
- data/app/controllers/high_voltage/pages_controller.rb +1 -35
- data/config/routes.rb +3 -2
- data/high_voltage.gemspec +5 -3
- data/lib/high_voltage/constraints/root_route.rb +22 -0
- data/lib/high_voltage/engine.rb +9 -2
- data/lib/high_voltage/page_finder.rb +37 -0
- data/lib/high_voltage/route_drawers/default.rb +15 -0
- data/lib/high_voltage/route_drawers/root.rb +16 -0
- data/lib/high_voltage/version.rb +1 -1
- data/lib/high_voltage.rb +19 -2
- data/spec/constraints/root_route_spec.rb +25 -0
- data/spec/controllers/action_caching_controller_spec.rb +23 -0
- data/spec/controllers/alternative_finder_controller_spec.rb +12 -0
- data/spec/controllers/page_caching_controller_spec.rb +20 -0
- data/spec/controllers/pages_controller_spec.rb +56 -40
- data/spec/controllers/subclassed_pages_controller_spec.rb +19 -20
- data/spec/dummy/app/controllers/alternative_finder_controller.rb +14 -0
- data/spec/dummy/app/controllers/subclassed_pages_controller.rb +0 -4
- data/spec/dummy/app/views/pages/also_dir/also_nested.html.erb +1 -0
- data/spec/dummy/app/views/pages/also_exists.html.erb +1 -0
- data/spec/dummy/app/views/pages/also_exists_but_references_nonexistent_partial.html.erb +2 -0
- data/spec/dummy/app/views/pages/rot13.html.erb +1 -0
- data/spec/dummy/config/application.rb +0 -1
- data/spec/dummy/config/environments/test.rb +1 -7
- data/spec/dummy/config/initializers/secret_key_base.rb +1 -0
- data/spec/dummy/config/routes.rb +2 -1
- data/spec/high_voltage/page_finder_spec.rb +52 -0
- data/spec/high_voltage_spec.rb +7 -3
- data/spec/integration/navigation_spec.rb +3 -3
- data/spec/minimal_spec_helper.rb +5 -0
- data/spec/routing/routes_spec.rb +107 -33
- data/spec/spec_helper.rb +7 -18
- data/spec/support/caching.rb +12 -0
- data/spec/support/concern_reload.rb +11 -0
- metadata +119 -44
- data/gemfiles/rails-3.0.15.gemfile +0 -7
- data/gemfiles/rails-3.1.6.gemfile +0 -7
- data/gemfiles/rails-3.2.6.gemfile +0 -7
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
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,80 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
high_voltage (
|
|
4
|
+
high_voltage (2.0.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)
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
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)
|
|
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.
|
|
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
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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 (
|
|
77
|
+
capybara (= 2.0.3)
|
|
92
78
|
high_voltage!
|
|
79
|
+
pry-debugger
|
|
93
80
|
rspec-rails
|
|
94
|
-
sqlite3
|
data/MIT-LICENSE
CHANGED
data/NEWS.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
|
|
16
|
+
New for 1.2.2:
|
|
17
|
+
+ Bug fix for RootRoute constraint. Support haml, slim, etc.
|
|
18
|
+
+ README updated for root routes.
|
|
19
|
+
|
|
20
|
+
New for 1.2.1:
|
|
21
|
+
+ Ability to disable HighVoltage routes.
|
|
22
|
+
+ New RootRoute constraint.
|
|
23
|
+
+ Updated README, with new TravisCI url.
|
data/README.md
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
# High Voltage [](http://travis-ci.org/thoughtbot/high_voltage)
|
|
2
2
|
|
|
3
3
|
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,56 +31,130 @@ 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
|
|
|
60
|
-
High Voltage will generate a named route method of `page_path` which you can use, as well. If you
|
|
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.
|
|
64
|
-
get a named route called `static_path` which does not conflict with the generated `page_path` method):
|
|
60
|
+
High Voltage will generate a named route method of `page_path` which you can use, as well. If you
|
|
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.
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
#### Specifying a root path
|
|
67
66
|
|
|
68
|
-
You can route the root
|
|
67
|
+
You can route the root route to a High Voltage page like this:
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
```ruby
|
|
70
|
+
root :to => 'high_voltage/pages#show', id: 'home'
|
|
71
|
+
```
|
|
71
72
|
|
|
72
73
|
Which will render a homepage from app/views/pages/home.html.erb
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
93
|
+
|
|
94
|
+
You can remove the directory `pages` from the URL path and serve up routes from
|
|
95
|
+
the root of the domain path:
|
|
96
|
+
|
|
97
|
+
http://www.example.com/about
|
|
98
|
+
http://www.example.com/company
|
|
99
|
+
|
|
100
|
+
Would look for corresponding files:
|
|
101
|
+
|
|
102
|
+
app/views/pages/about.html.erb
|
|
103
|
+
app/views/pages/company.html.erb
|
|
104
|
+
|
|
105
|
+
This is accomplished by changing the `HighVoltage.route_drawer` to `HighVoltage::RouteDrawers::Root`
|
|
106
|
+
|
|
107
|
+
```ruby
|
|
108
|
+
# config/initializers/high_voltage.rb
|
|
109
|
+
HighVoltage.route_drawer = HighVoltage::RouteDrawers::Root
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### Disabling routes
|
|
76
113
|
|
|
77
|
-
|
|
114
|
+
The default routes can be completely removed by changing the `HighVoltage.routes`
|
|
115
|
+
to `false`:
|
|
78
116
|
|
|
79
|
-
|
|
117
|
+
```ruby
|
|
118
|
+
# config/initializers/high_voltage.rb
|
|
119
|
+
HighVoltage.routes = false
|
|
120
|
+
```
|
|
80
121
|
|
|
81
|
-
|
|
122
|
+
#### Content path
|
|
82
123
|
|
|
83
|
-
|
|
84
|
-
|
|
124
|
+
High Voltage uses a default path and folder of 'pages', i.e. 'url.com/pages/contact',
|
|
125
|
+
'app/views/pages'.
|
|
126
|
+
|
|
127
|
+
You can change this in an initializer:
|
|
128
|
+
|
|
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
|
+
```
|
|
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
|
|
85
158
|
|
|
86
159
|
Most common reasons to override?
|
|
87
160
|
|
|
@@ -89,61 +162,118 @@ Most common reasons to override?
|
|
|
89
162
|
* You need to render different layouts for different pages.
|
|
90
163
|
* You need to render a partial from the `app/views/pages` directory.
|
|
91
164
|
|
|
92
|
-
Create a PagesController of your own:
|
|
165
|
+
Create a `PagesController` of your own:
|
|
93
166
|
|
|
94
167
|
$ rails generate controller pages
|
|
95
168
|
|
|
96
|
-
|
|
169
|
+
Disable the default routes:
|
|
97
170
|
|
|
98
|
-
|
|
99
|
-
|
|
171
|
+
```ruby
|
|
172
|
+
# config/initializers/high_voltage.rb
|
|
173
|
+
HighVoltage.routes = false
|
|
174
|
+
```
|
|
100
175
|
|
|
101
|
-
|
|
176
|
+
Define a route for the new `PagesController`:
|
|
102
177
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
178
|
+
```ruby
|
|
179
|
+
# config/routes.rb
|
|
180
|
+
get "/pages/*id" => 'pages#show', :as => :page, :format => false
|
|
106
181
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
when 'home'
|
|
111
|
-
'home'
|
|
112
|
-
else
|
|
113
|
-
'application'
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
182
|
+
# if routing the root path, update for your controller
|
|
183
|
+
root :to => 'pages#show', :id => 'home'
|
|
184
|
+
```
|
|
117
185
|
|
|
118
|
-
|
|
119
|
-
-------
|
|
186
|
+
Then modify new `PagesController` to include the High Voltage static page concern:
|
|
120
187
|
|
|
121
|
-
|
|
188
|
+
```ruby
|
|
189
|
+
# app/controllers/pages_controller.rb
|
|
190
|
+
class PagesController < ApplicationController
|
|
191
|
+
include HighVoltage::StaticPage
|
|
122
192
|
|
|
123
|
-
|
|
124
|
-
|
|
193
|
+
before_filter :authenticate
|
|
194
|
+
layout :layout_for_page
|
|
125
195
|
|
|
126
|
-
|
|
127
|
-
context "on GET to /pages/#{page}" do
|
|
128
|
-
setup { get :show, :id => page }
|
|
196
|
+
private
|
|
129
197
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
198
|
+
def layout_for_page
|
|
199
|
+
case params[:id]
|
|
200
|
+
when 'home'
|
|
201
|
+
'home'
|
|
202
|
+
else
|
|
203
|
+
'application'
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Custom finding
|
|
210
|
+
|
|
211
|
+
You can further control the algorithm used to find pages by overriding
|
|
212
|
+
the `page_finder_factory` method:
|
|
213
|
+
|
|
214
|
+
```ruby
|
|
215
|
+
# app/controllers/pages_controller.rb
|
|
216
|
+
class PagesController < ApplicationController
|
|
217
|
+
include HighVoltage::StaticPage
|
|
218
|
+
|
|
219
|
+
private
|
|
220
|
+
|
|
221
|
+
def page_finder_factory
|
|
222
|
+
Rot13PageFinder
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The easiest thing is to subclass `HighVoltage::PageFinder`, which
|
|
228
|
+
provides you with `page_id`:
|
|
229
|
+
|
|
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')
|
|
236
|
+
|
|
237
|
+
File.join(*directory, filename)
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Use this to create a custom file mapping, clean filenames for your file
|
|
243
|
+
system, A/B test, and so on.
|
|
244
|
+
|
|
245
|
+
## Testing
|
|
246
|
+
|
|
247
|
+
You can test your static pages using [RSpec](https://github.com/rspec/rspec-rails)
|
|
248
|
+
and [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers):
|
|
249
|
+
|
|
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
|
|
133
257
|
end
|
|
258
|
+
|
|
259
|
+
it { should respond_with(:success) }
|
|
260
|
+
it { should render_template(page) }
|
|
134
261
|
end
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
```
|
|
135
265
|
|
|
136
|
-
If you're not using a custom PagesController be sure to test
|
|
266
|
+
If you're not using a custom PagesController be sure to test
|
|
267
|
+
`HighVoltage::PagesController` instead.
|
|
137
268
|
|
|
138
269
|
Enjoy!
|
|
139
270
|
|
|
140
|
-
Contributing
|
|
141
|
-
------------
|
|
271
|
+
## Contributing
|
|
142
272
|
|
|
143
|
-
Please see CONTRIBUTING.md
|
|
273
|
+
Please see [CONTRIBUTING.md](https://github.com/thoughtbot/high_voltage/blob/master/CONTRIBUTING.md)
|
|
274
|
+
for details.
|
|
144
275
|
|
|
145
|
-
Credits
|
|
146
|
-
-------
|
|
276
|
+
## Credits
|
|
147
277
|
|
|
148
278
|

|
|
149
279
|
|
|
@@ -153,7 +283,7 @@ Thank you to all [the contributors](https://github.com/thoughtbot/high_voltage/c
|
|
|
153
283
|
|
|
154
284
|
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
|
155
285
|
|
|
156
|
-
License
|
|
157
|
-
-------
|
|
286
|
+
## License
|
|
158
287
|
|
|
159
|
-
High Voltage is Copyright © 2009-
|
|
288
|
+
High Voltage is Copyright © 2009-2013 thoughtbot. It is free software, and may
|
|
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
|
-
|
|
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
|
|
@@ -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
|