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 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
@@ -5,5 +5,5 @@ spec/dummy/db/*.sqlite3
5
5
  spec/dummy/log/*.log
6
6
  spec/dummy/tmp/
7
7
  *.swp
8
- gemfiles/*.lock
9
- *.gem
8
+ gemfiles/
9
+ *.gem
data/.travis.yml CHANGED
@@ -1,9 +1,8 @@
1
- language: ruby
1
+ language:
2
+ - ruby
3
+ install:
4
+ - 'bundle install'
2
5
  rvm:
3
- - 1.8.7
4
6
  - 1.9.2
5
7
  - 1.9.3
6
- gemfile:
7
- - gemfiles/rails_3.0.18.gemfile
8
- - gemfiles/rails_3.1.9.gemfile
9
- - gemfiles/rails_3.2.10.gemfile
8
+ - 2.0.0
data/Appraisals CHANGED
@@ -1,5 +1,16 @@
1
- ['3.2.10', '3.1.9', '3.0.18'].each do |rails_version|
2
- appraise "rails_#{rails_version}" do
3
- gem "rails", rails_version
1
+ if RUBY_VERSION >= '2.0'
2
+ rails_versions = ['~> 3.2.13', '~> 4.0.0']
3
+ else
4
+ rails_versions = ['~> 3.1.12', '~> 3.2.13']
5
+ end
6
+
7
+ rails_versions.each do |rails_version|
8
+ appraise "rails#{rails_version.slice(/\d+\.\d+/)}" do
9
+ gem 'rails', rails_version
10
+
11
+ if rails_version == '~> 4.0.0'
12
+ gem 'actionpack-action_caching'
13
+ gem 'actionpack-page_caching'
14
+ end
4
15
  end
5
16
  end
data/Gemfile.lock CHANGED
@@ -1,94 +1,70 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- high_voltage (1.2.2)
4
+ high_voltage (2.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- abstract (1.0.0)
10
- actionpack (3.0.10)
11
- activemodel (= 3.0.10)
12
- activesupport (= 3.0.10)
13
- builder (~> 2.1.2)
14
- erubis (~> 2.6.6)
15
- i18n (~> 0.5.0)
16
- rack (~> 1.2.1)
17
- rack-mount (~> 0.6.14)
18
- rack-test (~> 0.5.7)
19
- tzinfo (~> 0.3.23)
20
- activemodel (3.0.10)
21
- activesupport (= 3.0.10)
22
- builder (~> 2.1.2)
23
- i18n (~> 0.5.0)
24
- activesupport (3.0.10)
25
- appraisal (0.4.1)
9
+ activesupport (3.1.12)
10
+ multi_json (~> 1.0)
11
+ appraisal (0.5.2)
26
12
  bundler
27
13
  rake
28
- builder (2.1.2)
29
- capybara (1.1.0)
14
+ capybara (2.0.3)
30
15
  mime-types (>= 1.16)
31
16
  nokogiri (>= 1.3.3)
32
17
  rack (>= 1.0.0)
33
18
  rack-test (>= 0.5.4)
34
19
  selenium-webdriver (~> 2.0)
35
- xpath (~> 0.1.4)
36
- childprocess (0.2.2)
37
- ffi (~> 1.0.6)
20
+ xpath (~> 1.0.0)
21
+ childprocess (0.3.9)
22
+ ffi (~> 1.0, >= 1.0.11)
23
+ coderay (1.0.9)
38
24
  diff-lcs (1.1.3)
39
- erubis (2.6.6)
40
- abstract (>= 1.0.0)
41
- ffi (1.0.9)
42
- i18n (0.5.0)
43
- json_pure (1.5.4)
44
- spruz (~> 0.2.8)
45
- mime-types (1.16)
46
- nokogiri (1.5.0)
47
- rack (1.2.3)
48
- rack-mount (0.6.14)
49
- rack (>= 1.0.0)
50
- rack-test (0.5.7)
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
- railties (3.0.10)
53
- actionpack (= 3.0.10)
54
- activesupport (= 3.0.10)
55
- rake (>= 0.8.7)
56
- rdoc (~> 3.4)
57
- thor (~> 0.14.4)
58
- rake (0.9.2.2)
59
- rdoc (3.9.4)
60
- rspec (2.6.0)
61
- rspec-core (~> 2.6.0)
62
- rspec-expectations (~> 2.6.0)
63
- rspec-mocks (~> 2.6.0)
64
- rspec-core (2.6.4)
65
- rspec-expectations (2.6.0)
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.6.0)
68
- rspec-rails (2.6.1)
69
- actionpack (~> 3.0)
70
- activesupport (~> 3.0)
71
- railties (~> 3.0)
72
- rspec (~> 2.6.0)
73
- rubyzip (0.9.4)
74
- selenium-webdriver (2.5.0)
75
- childprocess (>= 0.2.1)
76
- ffi (>= 1.0.7)
77
- json_pure
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
- spruz (0.2.13)
80
- sqlite3 (1.3.4)
81
- thor (0.14.6)
82
- tzinfo (0.3.29)
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 (>= 0.4.0)
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
- gem "high_voltage"
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
- 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
+ ## 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
- match 'pages/home' => 'high_voltage/pages#show', :id => 'home'
55
-
56
- In that case, you'd need an app/views/pages/home.html.erb file.
54
+ ```ruby
55
+ get 'pages/home' => 'high_voltage/pages#show', id: 'home'
56
+ ```
57
57
 
58
- Generally speaking, you need to route to the 'show' action with an :id param of the view filename.
58
+ In that case, you'd need an `app/views/pages/home.html.erb` file.
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.
60
+ Generally speaking, you need to route to the 'show' action with an `:id` param of the view filename.
64
61
 
65
- For example, this will work for top-level routes (we will
66
- get a named route called `static_path` which does not conflict with the generated `page_path` method):
67
-
68
- match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get
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 route the root url to a high voltage page like this:
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
- root :to => 'high_voltage/pages#show', :id => 'home'
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
- Which will render a homepage from app/views/pages/home.html.erb
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
- #### Enabling root domain routes
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 changing the `HighVoltage.route_drawer` to `HighVoltage::RouteDrawers::Root`
96
+ This is accomplished by setting the `route_drawer` to `HighVoltage::RouteDrawers::Root`
92
97
 
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.
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 changing the
102
- `HighVoltage.routes` to `false`
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
- # config/initializers/high_voltage.rb
105
- HighVoltage.routes = false
116
+ #### Page titles and meta-data
106
117
 
107
- Customize
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
- High Voltage uses a default path and folder of 'pages', i.e. 'url.com/pages/contact' , 'app/views/pages'
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
- HighVoltage.content_path = "site/"
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
- Override
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
- Override the default route:
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
- # in config/routes.rb
132
- match "/pages/*id" => 'pages#show', :as => :page, :format => false
206
+ # if routing the root path, update for your controller
207
+ root to: 'pages#show', id: 'home'
208
+ ```
133
209
 
134
- # if routing the root path, update for your controller
135
- root :to => 'pages#show', :id => 'home'
210
+ Then modify new `PagesController` to include the High Voltage static page concern:
136
211
 
137
- Then modify it to subclass from High Voltage, adding whatever you need:
212
+ ```ruby
213
+ # app/controllers/pages_controller.rb
214
+ class PagesController < ApplicationController
215
+ include HighVoltage::StaticPage
138
216
 
139
- class PagesController < HighVoltage::PagesController
140
- before_filter :authenticate
141
- layout :layout_for_page
217
+ before_filter :authenticate
218
+ layout :layout_for_page
142
219
 
143
- protected
144
- def layout_for_page
145
- case params[:id]
146
- when 'home'
147
- 'home'
148
- else
149
- 'application'
150
- end
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
- class PagesController < HighVoltage::PagesController
161
- private
238
+ ```ruby
239
+ # app/controllers/pages_controller.rb
240
+ class PagesController < ApplicationController
241
+ include HighVoltage::StaticPage
162
242
 
163
- def page_finder_factory
164
- Rot13PageFinder
165
- end
166
- end
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
- 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')
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
- File.join(*directory, filename)
178
- end
179
- end
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
- # 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
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 for details.
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
  ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
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
- 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