high_voltage 1.0.1 → 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.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +8 -0
  4. data/Appraisals +16 -0
  5. data/CONTRIBUTING.md +38 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +80 -0
  8. data/MIT-LICENSE +1 -1
  9. data/NEWS.md +23 -0
  10. data/README.md +206 -66
  11. data/Rakefile +19 -0
  12. data/app/controllers/concerns/high_voltage/static_page.rb +41 -0
  13. data/app/controllers/high_voltage/pages_controller.rb +1 -26
  14. data/config/routes.rb +3 -1
  15. data/high_voltage.gemspec +24 -0
  16. data/lib/high_voltage/constraints/root_route.rb +22 -0
  17. data/lib/high_voltage/engine.rb +9 -2
  18. data/lib/high_voltage/page_finder.rb +37 -0
  19. data/lib/high_voltage/route_drawers/default.rb +15 -0
  20. data/lib/high_voltage/route_drawers/root.rb +16 -0
  21. data/lib/high_voltage/version.rb +3 -0
  22. data/lib/high_voltage.rb +29 -0
  23. data/spec/constraints/root_route_spec.rb +25 -0
  24. data/spec/controllers/action_caching_controller_spec.rb +23 -0
  25. data/spec/controllers/alternative_finder_controller_spec.rb +12 -0
  26. data/spec/controllers/page_caching_controller_spec.rb +20 -0
  27. data/spec/controllers/pages_controller_spec.rb +128 -0
  28. data/spec/controllers/subclassed_pages_controller_spec.rb +40 -0
  29. data/spec/dummy/Rakefile +7 -0
  30. data/spec/dummy/app/controllers/alternative_finder_controller.rb +14 -0
  31. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  32. data/spec/dummy/app/controllers/subclassed_pages_controller.rb +3 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  34. data/spec/dummy/app/views/layouts/alternate.html.erb +14 -0
  35. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/spec/dummy/app/views/other/wrong.html.erb +1 -0
  37. data/spec/dummy/app/views/other_pages/also_dir/also_nested.html.erb +1 -0
  38. data/spec/dummy/app/views/other_pages/also_exists.html.erb +1 -0
  39. data/spec/dummy/app/views/other_pages/also_exists_but_references_nonexistent_partial.html.erb +2 -0
  40. data/spec/dummy/app/views/pages/also_dir/also_nested.html.erb +1 -0
  41. data/spec/dummy/app/views/pages/also_exists.html.erb +1 -0
  42. data/spec/dummy/app/views/pages/also_exists_but_references_nonexistent_partial.html.erb +2 -0
  43. data/spec/dummy/app/views/pages/dir/nested.html.erb +1 -0
  44. data/spec/dummy/app/views/pages/exists.html.erb +1 -0
  45. data/spec/dummy/app/views/pages/exists_but_references_nonexistent_partial.html.erb +2 -0
  46. data/spec/dummy/app/views/pages/rot13.html.erb +1 -0
  47. data/spec/dummy/config/application.rb +43 -0
  48. data/spec/dummy/config/boot.rb +10 -0
  49. data/spec/dummy/config/environment.rb +5 -0
  50. data/spec/dummy/config/environments/development.rb +25 -0
  51. data/spec/dummy/config/environments/production.rb +49 -0
  52. data/spec/dummy/config/environments/test.rb +29 -0
  53. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/spec/dummy/config/initializers/inflections.rb +10 -0
  55. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  56. data/spec/dummy/config/initializers/secret_key_base.rb +1 -0
  57. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  58. data/spec/dummy/config/initializers/session_store.rb +8 -0
  59. data/spec/dummy/config/locales/en.yml +5 -0
  60. data/spec/dummy/config/routes.rb +4 -0
  61. data/spec/dummy/config.ru +4 -0
  62. data/spec/dummy/public/404.html +26 -0
  63. data/spec/dummy/public/422.html +26 -0
  64. data/spec/dummy/public/500.html +26 -0
  65. data/spec/dummy/public/favicon.ico +0 -0
  66. data/spec/dummy/public/javascripts/application.js +2 -0
  67. data/spec/dummy/public/javascripts/controls.js +965 -0
  68. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  69. data/spec/dummy/public/javascripts/effects.js +1123 -0
  70. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  71. data/spec/dummy/public/javascripts/rails.js +191 -0
  72. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  73. data/spec/dummy/script/rails +6 -0
  74. data/spec/high_voltage/page_finder_spec.rb +52 -0
  75. data/spec/high_voltage_spec.rb +11 -0
  76. data/spec/integration/navigation_spec.rb +9 -0
  77. data/spec/minimal_spec_helper.rb +5 -0
  78. data/spec/routing/routes_spec.rb +142 -0
  79. data/spec/spec_helper.rb +19 -0
  80. data/spec/support/caching.rb +12 -0
  81. data/spec/support/concern_reload.rb +11 -0
  82. metadata +218 -15
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 ADDED
@@ -0,0 +1,9 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/log/*.log
6
+ spec/dummy/tmp/
7
+ *.swp
8
+ gemfiles/
9
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language:
2
+ - ruby
3
+ install:
4
+ - 'bundle install'
5
+ rvm:
6
+ - 1.9.2
7
+ - 1.9.3
8
+ - 2.0.0
data/Appraisals ADDED
@@ -0,0 +1,16 @@
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
15
+ end
16
+ end
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,38 @@
1
+ We love pull requests. Here's a quick guide:
2
+
3
+ 1. Fork the repo.
4
+
5
+ 2. Run the tests. We only take pull requests with passing tests, and it's great
6
+ to know that you have a clean slate: `bundle && rake`
7
+
8
+ 3. Add a test for your change. Only refactoring and documentation changes
9
+ require no new tests. If you are adding functionality or fixing a bug, we need
10
+ a test!
11
+
12
+ 4. Make the test pass.
13
+
14
+ 5. Push to your fork and submit a pull request.
15
+
16
+
17
+ At this point you're waiting on us. We like to at least comment on, if not
18
+ accept, pull requests within three business days (and, typically, one business
19
+ day). We may suggest some changes or improvements or alternatives.
20
+
21
+ Some things that will increase the chance that your pull request is accepted,
22
+ taken straight from the Ruby on Rails guide:
23
+
24
+ * Use Rails idioms and helpers
25
+ * Include tests that fail without your code, and pass with it
26
+ * Update the documentation, the surrounding one, examples elsewhere, guides,
27
+ whatever is affected by your contribution
28
+
29
+ Syntax:
30
+
31
+ * Two spaces, no tabs.
32
+ * No trailing whitespace. Blank lines should not have any space.
33
+ * Prefer &&/|| over and/or.
34
+ * MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
35
+ * a = b and not a=b.
36
+ * Follow the conventions you see used in the source already.
37
+
38
+ And in case we didn't emphasize it enough: we love tests!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ high_voltage (2.0.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ activesupport (3.1.12)
10
+ multi_json (~> 1.0)
11
+ appraisal (0.5.2)
12
+ bundler
13
+ rake
14
+ capybara (2.0.3)
15
+ mime-types (>= 1.16)
16
+ nokogiri (>= 1.3.3)
17
+ rack (>= 1.0.0)
18
+ rack-test (>= 0.5.4)
19
+ selenium-webdriver (~> 2.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)
31
+ diff-lcs (1.1.3)
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)
48
+ rack (>= 1.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)
56
+ diff-lcs (~> 1.1.2)
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)
64
+ rubyzip
65
+ websocket (~> 1.0.4)
66
+ slop (3.4.5)
67
+ websocket (1.0.7)
68
+ xpath (1.0.0)
69
+ nokogiri (~> 1.3)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ activesupport (>= 3.1.0)
76
+ appraisal
77
+ capybara (= 2.0.3)
78
+ high_voltage!
79
+ pry-debugger
80
+ rspec-rails
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2010 thoughtbot, inc.
1
+ Copyright 2010-2013 thoughtbot, inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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 [![Build Status](http://travis-ci.org/thoughtbot/high_voltage.png)](http://travis-ci.org/thoughtbot/high_voltage)
1
+ # High Voltage [![Build Status](https://travis-ci.org/thoughtbot/high_voltage.png)](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
- gem "high_voltage"
17
+ ```ruby
18
+ gem 'high_voltage'
19
+ ```
20
20
 
21
21
  For Rails versions prior to 3.0, use the 0.9.2 tag of high_voltage:
22
22
 
23
23
  https://github.com/thoughtbot/high_voltage/tree/v0.9.2
24
24
 
25
- Usage
26
- -----
25
+ ## Usage
27
26
 
28
27
  Write your static pages and put them in the RAILS_ROOT/app/views/pages directory.
29
28
 
@@ -32,108 +31,249 @@ Write your static pages and put them in the RAILS_ROOT/app/views/pages directory
32
31
 
33
32
  After putting something interesting there, you can link to it from anywhere in your app with:
34
33
 
35
- link_to "About", page_path("about")
36
-
37
- This will also work, if you like the more explicit style:
38
-
39
- link_to "About", page_path(:id => "about")
34
+ ```ruby
35
+ link_to 'About', page_path('about')
36
+ ```
40
37
 
41
38
  You can nest pages in a directory structure, if that makes sense from a URL perspective for you:
42
39
 
43
- link_to "Q4 Reports", page_path("about/corporate/policies/HR/en_US/biz/sales/Quarter-Four")
40
+ ```ruby
41
+ link_to 'Q4 Reports', page_path('about/corporate/policies/HR/en_US/biz/sales/Quarter-Four')
42
+ ```
44
43
 
45
44
  Bam.
46
45
 
47
- Routes
48
- ------
46
+ ## Routes
49
47
 
50
48
  By default, the static page routes will be like /pages/:id (where :id is the view filename).
51
49
 
52
50
  If you want to route to a static page in another location (for example, a homepage), do this:
53
51
 
54
- match 'pages/home' => 'high_voltage/pages#show', :id => 'home'
52
+ ```ruby
53
+ get 'pages/home' => 'high_voltage/pages#show', id: 'home'
54
+ ```
55
55
 
56
- In that case, you'd need an app/views/pages/home.html.erb file.
56
+ In that case, you'd need an `app/views/pages/home.html.erb` file.
57
57
 
58
58
  Generally speaking, you need to route to the 'show' action with an :id param of the view filename.
59
59
 
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. For example, this will work for top-level routes (we will
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
- match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get
65
+ #### Specifying a root path
67
66
 
68
- You can route the root url to a high voltage page like this:
67
+ You can route the root route to a High Voltage page like this:
69
68
 
70
- root :to => 'high_voltage/pages#show', :id => 'home'
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
- Override
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
113
+
114
+ The default routes can be completely removed by changing the `HighVoltage.routes`
115
+ to `false`:
116
+
117
+ ```ruby
118
+ # config/initializers/high_voltage.rb
119
+ HighVoltage.routes = false
120
+ ```
121
+
122
+ #### Content path
123
+
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
76
158
 
77
159
  Most common reasons to override?
78
160
 
79
161
  * You need authentication around the pages to make sure a user is signed in.
80
162
  * You need to render different layouts for different pages.
163
+ * You need to render a partial from the `app/views/pages` directory.
81
164
 
82
- Create a PagesController of your own:
165
+ Create a `PagesController` of your own:
83
166
 
84
167
  $ rails generate controller pages
85
168
 
86
- Override the default route:
169
+ Disable the default routes:
87
170
 
88
- # in config/routes.rb
89
- resources :pages
171
+ ```ruby
172
+ # config/initializers/high_voltage.rb
173
+ HighVoltage.routes = false
174
+ ```
90
175
 
91
- Then modify it to subclass from High Voltage, adding whatever you need:
176
+ Define a route for the new `PagesController`:
92
177
 
93
- class PagesController < HighVoltage::PagesController
94
- before_filter :authenticate
95
- layout :layout_for_page
178
+ ```ruby
179
+ # config/routes.rb
180
+ get "/pages/*id" => 'pages#show', :as => :page, :format => false
96
181
 
97
- protected
98
- def layout_for_page
99
- case params[:id]
100
- when 'home'
101
- 'home'
102
- else
103
- 'application'
104
- end
105
- end
106
- end
182
+ # if routing the root path, update for your controller
183
+ root :to => 'pages#show', :id => 'home'
184
+ ```
107
185
 
108
- Testing
109
- -------
186
+ Then modify new `PagesController` to include the High Voltage static page concern:
110
187
 
111
- Just a suggestion, but you can test your pages using Shoulda pretty easily:
188
+ ```ruby
189
+ # app/controllers/pages_controller.rb
190
+ class PagesController < ApplicationController
191
+ include HighVoltage::StaticPage
112
192
 
113
- class PagesControllerTest < ActionController::TestCase
114
- tests PagesController
193
+ before_filter :authenticate
194
+ layout :layout_for_page
115
195
 
116
- %w(earn_money screencast about contact).each do |page|
117
- context "on GET to /pages/#{page}" do
118
- setup { get :show, :id => page }
196
+ private
119
197
 
120
- should_respond_with :success
121
- should_render_template page
122
- end
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
123
257
  end
258
+
259
+ it { should respond_with(:success) }
260
+ it { should render_template(page) }
124
261
  end
262
+ end
263
+ end
264
+ ```
125
265
 
126
- If you're not using a custom PagesController be sure to test <code>HighVoltage::PagesController</code> instead.
266
+ If you're not using a custom PagesController be sure to test
267
+ `HighVoltage::PagesController` instead.
127
268
 
128
269
  Enjoy!
129
270
 
130
- Contributing
131
- ------------
271
+ ## Contributing
132
272
 
133
- Please see CONTRIBUTING.md for details.
273
+ Please see [CONTRIBUTING.md](https://github.com/thoughtbot/high_voltage/blob/master/CONTRIBUTING.md)
274
+ for details.
134
275
 
135
- Credits
136
- -------
276
+ ## Credits
137
277
 
138
278
  ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
139
279
 
@@ -143,7 +283,7 @@ Thank you to all [the contributors](https://github.com/thoughtbot/high_voltage/c
143
283
 
144
284
  The names and logos for thoughtbot are trademarks of thoughtbot, inc.
145
285
 
146
- License
147
- -------
286
+ ## License
148
287
 
149
- High Voltage is Copyright © 2009-2011 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
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 ADDED
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'bundler/gem_tasks'
6
+
7
+ require 'rake'
8
+ require 'rspec/core/rake_task'
9
+ require 'appraisal'
10
+
11
+ RSpec::Core::RakeTask.new(:spec)
12
+
13
+ desc 'Default'
14
+ task :default => [:all]
15
+
16
+ desc 'Test the engine under all supported Rails versions'
17
+ task all: ['appraisal:install'] do |t|
18
+ exec 'rake appraisal spec'
19
+ end
@@ -0,0 +1,41 @@
1
+ module HighVoltage::StaticPage
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ layout ->(_) { HighVoltage.layout }
6
+
7
+ rescue_from ActionView::MissingTemplate do |exception|
8
+ if exception.message =~ %r{Missing template #{page_finder.content_path}}
9
+ raise ActionController::RoutingError, "No such page: #{params[:id]}"
10
+ else
11
+ raise exception
12
+ end
13
+ end
14
+
15
+ if respond_to?(:caches_action)
16
+ caches_action :show, if: -> { HighVoltage.action_caching }
17
+ end
18
+
19
+ if respond_to?(:caches_page)
20
+ caches_page :show, if: -> { HighVoltage.page_caching }
21
+ end
22
+
23
+ hide_action :current_page, :page_finder, :page_finder_factory
24
+ end
25
+
26
+ def show
27
+ render template: current_page
28
+ end
29
+
30
+ def current_page
31
+ page_finder.find
32
+ end
33
+
34
+ def page_finder
35
+ page_finder_factory.new(params[:id])
36
+ end
37
+
38
+ def page_finder_factory
39
+ HighVoltage::PageFinder
40
+ end
41
+ end
@@ -1,28 +1,3 @@
1
1
  class HighVoltage::PagesController < ApplicationController
2
-
3
- unloadable
4
-
5
- rescue_from ActionView::MissingTemplate do |exception|
6
- if exception.message =~ %r{Missing template pages/}
7
- raise ActionController::RoutingError, "No such page: #{params[:id]}"
8
- else
9
- raise exception
10
- end
11
- end
12
-
13
- def show
14
- render :template => current_page
15
- end
16
-
17
- protected
18
-
19
- def current_page
20
- "pages/#{clean_path}"
21
- end
22
-
23
- def clean_path
24
- path = Pathname.new "/#{params[:id]}"
25
- path.cleanpath.to_s[1..-1]
26
- end
27
-
2
+ include HighVoltage::StaticPage
28
3
  end
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  Rails.application.routes.draw do
2
- match '/pages/*id' => 'high_voltage/pages#show', :as => :page, :format => false
2
+ if HighVoltage.routes
3
+ get HighVoltage.route_drawer.match_attributes
4
+ end
3
5
  end
@@ -0,0 +1,24 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "high_voltage/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'high_voltage'
6
+ s.version = HighVoltage::VERSION.dup
7
+ s.authors = ['Matt Jankowski', 'Dan Croak', 'Nick Quaranto', 'Chad Pytel', 'Joe Ferris', 'J. Edward Dewyea', 'Tammer Saleh', 'Mike Burns', 'Tristan Dunn']
8
+ s.email = ['support@thoughtbot.com']
9
+ s.homepage = 'http://github.com/thoughtbot/high_voltage'
10
+ s.summary = 'Simple static page rendering controller'
11
+ s.description = 'Fire in the disco. Fire in the ... taco bell.'
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_development_dependency("activesupport", ">= 3.1.0")
20
+ s.add_development_dependency("appraisal")
21
+ s.add_development_dependency("capybara", "= 2.0.3")
22
+ s.add_development_dependency("pry-debugger")
23
+ s.add_development_dependency("rspec-rails")
24
+ end