high_voltage 0.9.0 → 1.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.
- data/MIT-LICENSE +1 -1
- data/README.md +136 -0
- data/app/controllers/high_voltage/pages_controller.rb +12 -5
- data/config/routes.rb +2 -2
- metadata +10 -16
- data/README.markdown +0 -73
- data/init.rb +0 -1
- data/install.rb +0 -1
data/MIT-LICENSE
CHANGED
data/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
High Voltage
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
Rails engine for static pages.
|
|
5
|
+
|
|
6
|
+
... but be careful. [Danger!](http://www.youtube.com/watch?v=HD5tnb2RBYg)
|
|
7
|
+
|
|
8
|
+
Static pages?
|
|
9
|
+
-------------
|
|
10
|
+
|
|
11
|
+
Yeah, like "About us", "Directions", marketing pages, etc.
|
|
12
|
+
|
|
13
|
+
Installation
|
|
14
|
+
------------
|
|
15
|
+
|
|
16
|
+
$ gem install high_voltage
|
|
17
|
+
|
|
18
|
+
Include in your Gemfile:
|
|
19
|
+
|
|
20
|
+
gem "high_voltage"
|
|
21
|
+
|
|
22
|
+
For Rails versions prior to 3.0, use the rails2 branch of high_voltage:
|
|
23
|
+
https://github.com/thoughtbot/high_voltage/tree/rails2
|
|
24
|
+
|
|
25
|
+
Usage
|
|
26
|
+
-----
|
|
27
|
+
|
|
28
|
+
Write your static pages and put them in the RAILS_ROOT/app/views/pages directory.
|
|
29
|
+
|
|
30
|
+
$ mkdir app/views/pages
|
|
31
|
+
$ touch app/views/pages/about.html.erb
|
|
32
|
+
|
|
33
|
+
After putting something interesting there, you can link to it from anywhere in your app with:
|
|
34
|
+
|
|
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")
|
|
40
|
+
|
|
41
|
+
You can nest pages in a directory structure, if that makes sense from a URL perspective for you:
|
|
42
|
+
|
|
43
|
+
link_to "Q4 Reports", page_path("about/corporate/policies/HR/en_US/biz/sales/Quarter-Four")
|
|
44
|
+
|
|
45
|
+
Bam.
|
|
46
|
+
|
|
47
|
+
Routes
|
|
48
|
+
------
|
|
49
|
+
|
|
50
|
+
By default, the static page routes will be like /pages/:id (where :id is the view filename).
|
|
51
|
+
|
|
52
|
+
If you want to route to a static page in another location (for example, a homepage), do this:
|
|
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.
|
|
57
|
+
|
|
58
|
+
Generally speaking, you need to route to the 'show' action with an :id param of the view filename.
|
|
59
|
+
|
|
60
|
+
You can route the root url to a high voltage page like this:
|
|
61
|
+
|
|
62
|
+
root :to => 'high_voltage/pages#show', :id => 'home'
|
|
63
|
+
|
|
64
|
+
Which will render a homepage from app/views/pages/home.html.erb
|
|
65
|
+
|
|
66
|
+
Override
|
|
67
|
+
--------
|
|
68
|
+
|
|
69
|
+
Most common reasons to override?
|
|
70
|
+
|
|
71
|
+
* You need authentication around the pages to make sure a user is signed in.
|
|
72
|
+
* You need to render different layouts for different pages.
|
|
73
|
+
|
|
74
|
+
Create a PagesController of your own:
|
|
75
|
+
|
|
76
|
+
$ rails generate controller pages
|
|
77
|
+
|
|
78
|
+
Override the default route:
|
|
79
|
+
|
|
80
|
+
# in config/routes.rb
|
|
81
|
+
resources :pages
|
|
82
|
+
|
|
83
|
+
Then modify it to subclass from High Voltage, adding whatever you need:
|
|
84
|
+
|
|
85
|
+
class PagesController < HighVoltage::PagesController
|
|
86
|
+
before_filter :authenticate
|
|
87
|
+
layout :layout_for_page
|
|
88
|
+
|
|
89
|
+
protected
|
|
90
|
+
def layout_for_page
|
|
91
|
+
case params[:id]
|
|
92
|
+
when 'home'
|
|
93
|
+
'home'
|
|
94
|
+
else
|
|
95
|
+
'application'
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
Testing
|
|
101
|
+
-------
|
|
102
|
+
|
|
103
|
+
Just a suggestion, but you can test your pages using Shoulda pretty easily:
|
|
104
|
+
|
|
105
|
+
class PagesControllerTest < ActionController::TestCase
|
|
106
|
+
tests PagesController
|
|
107
|
+
|
|
108
|
+
%w(earn_money screencast about contact).each do |page|
|
|
109
|
+
context "on GET to /pages/#{page}" do
|
|
110
|
+
setup { get :show, :id => page }
|
|
111
|
+
|
|
112
|
+
should_respond_with :success
|
|
113
|
+
should_render_template page
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
If you're not using a custom PagesController be sure to test <code>HighVoltage::PagesController</code> instead.
|
|
119
|
+
|
|
120
|
+
Enjoy!
|
|
121
|
+
|
|
122
|
+
Credits
|
|
123
|
+
-------
|
|
124
|
+
|
|
125
|
+

|
|
126
|
+
|
|
127
|
+
High Voltage is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
|
|
128
|
+
|
|
129
|
+
Thank you to all [the contributors](https://github.com/thoughtbot/high_voltage/contributors)!
|
|
130
|
+
|
|
131
|
+
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
|
132
|
+
|
|
133
|
+
License
|
|
134
|
+
-------
|
|
135
|
+
|
|
136
|
+
High Voltage is Copyright © 2009-2011 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
|
@@ -2,7 +2,13 @@ class HighVoltage::PagesController < ApplicationController
|
|
|
2
2
|
|
|
3
3
|
unloadable
|
|
4
4
|
|
|
5
|
-
rescue_from ActionView::MissingTemplate
|
|
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
|
|
6
12
|
|
|
7
13
|
def show
|
|
8
14
|
render :template => current_page
|
|
@@ -10,12 +16,13 @@ class HighVoltage::PagesController < ApplicationController
|
|
|
10
16
|
|
|
11
17
|
protected
|
|
12
18
|
|
|
13
|
-
def
|
|
14
|
-
|
|
19
|
+
def current_page
|
|
20
|
+
"pages/#{clean_path}"
|
|
15
21
|
end
|
|
16
22
|
|
|
17
|
-
def
|
|
18
|
-
"
|
|
23
|
+
def clean_path
|
|
24
|
+
path = Pathname.new "/#{params[:id]}"
|
|
25
|
+
path.cleanpath.to_s[1..-1]
|
|
19
26
|
end
|
|
20
27
|
|
|
21
28
|
end
|
data/config/routes.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Rails.application.routes.draw do
|
|
2
|
-
|
|
1
|
+
Rails.application.routes.draw do
|
|
2
|
+
match '/pages/*id' => 'high_voltage/pages#show', :as => :page
|
|
3
3
|
end
|
metadata
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: high_voltage
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
prerelease:
|
|
5
|
-
|
|
6
|
-
- 0
|
|
7
|
-
- 9
|
|
8
|
-
- 0
|
|
9
|
-
version: 0.9.0
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 1.0.0
|
|
10
6
|
platform: ruby
|
|
11
7
|
authors:
|
|
12
8
|
- Dan Croak
|
|
@@ -14,11 +10,13 @@ authors:
|
|
|
14
10
|
- Tammer Saleh
|
|
15
11
|
- Nick Quaranto
|
|
16
12
|
- Tristan Dunn
|
|
13
|
+
- Chad Pytel
|
|
14
|
+
- Joe Ferris
|
|
17
15
|
autorequire:
|
|
18
16
|
bindir: bin
|
|
19
17
|
cert_chain: []
|
|
20
18
|
|
|
21
|
-
date:
|
|
19
|
+
date: 2011-06-29 00:00:00 -04:00
|
|
22
20
|
default_executable:
|
|
23
21
|
dependencies: []
|
|
24
22
|
|
|
@@ -31,14 +29,12 @@ extensions: []
|
|
|
31
29
|
extra_rdoc_files: []
|
|
32
30
|
|
|
33
31
|
files:
|
|
32
|
+
- MIT-LICENSE
|
|
33
|
+
- README.md
|
|
34
34
|
- app/controllers/high_voltage/pages_controller.rb
|
|
35
35
|
- config/routes.rb
|
|
36
|
-
- init.rb
|
|
37
|
-
- install.rb
|
|
38
36
|
- lib/high_voltage/engine.rb
|
|
39
37
|
- lib/high_voltage.rb
|
|
40
|
-
- MIT-LICENSE
|
|
41
|
-
- README.markdown
|
|
42
38
|
has_rdoc: true
|
|
43
39
|
homepage: http://github.com/thoughtbot/high_voltage
|
|
44
40
|
licenses: []
|
|
@@ -49,23 +45,21 @@ rdoc_options: []
|
|
|
49
45
|
require_paths:
|
|
50
46
|
- lib
|
|
51
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
none: false
|
|
52
49
|
requirements:
|
|
53
50
|
- - ">="
|
|
54
51
|
- !ruby/object:Gem::Version
|
|
55
|
-
segments:
|
|
56
|
-
- 0
|
|
57
52
|
version: "0"
|
|
58
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
|
+
none: false
|
|
59
55
|
requirements:
|
|
60
56
|
- - ">="
|
|
61
57
|
- !ruby/object:Gem::Version
|
|
62
|
-
segments:
|
|
63
|
-
- 0
|
|
64
58
|
version: "0"
|
|
65
59
|
requirements: []
|
|
66
60
|
|
|
67
61
|
rubyforge_project:
|
|
68
|
-
rubygems_version: 1.
|
|
62
|
+
rubygems_version: 1.6.2
|
|
69
63
|
signing_key:
|
|
70
64
|
specification_version: 3
|
|
71
65
|
summary: Simple static page rendering controller
|
data/README.markdown
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
High Voltage
|
|
2
|
-
============
|
|
3
|
-
|
|
4
|
-
Rails engine for static pages.
|
|
5
|
-
|
|
6
|
-
... but be careful. [Danger!](http://www.youtube.com/watch?v=HD5tnb2RBYg)
|
|
7
|
-
|
|
8
|
-
Static pages?
|
|
9
|
-
-------------
|
|
10
|
-
|
|
11
|
-
Yeah, like "About us", "Directions", marketing pages, etc.
|
|
12
|
-
|
|
13
|
-
Installation
|
|
14
|
-
------------
|
|
15
|
-
|
|
16
|
-
$ gem install high_voltage
|
|
17
|
-
|
|
18
|
-
Usage
|
|
19
|
-
-----
|
|
20
|
-
|
|
21
|
-
Write your static pages and put them in the RAILS_ROOT/app/views/pages directory.
|
|
22
|
-
|
|
23
|
-
mkdir app/views/pages
|
|
24
|
-
touch app/views/pages/about.html.erb
|
|
25
|
-
|
|
26
|
-
After putting something interesting there, you can link to it from anywhere in your app with:
|
|
27
|
-
|
|
28
|
-
link_to "About", page_path("about")
|
|
29
|
-
|
|
30
|
-
Bam.
|
|
31
|
-
|
|
32
|
-
Override
|
|
33
|
-
--------
|
|
34
|
-
|
|
35
|
-
Most common reasons to override? Authentication, layouts.
|
|
36
|
-
|
|
37
|
-
Create a PagesController of your own:
|
|
38
|
-
|
|
39
|
-
script/generate controller pages
|
|
40
|
-
|
|
41
|
-
Then modify it to subclass from High Voltage, adding whatever you need:
|
|
42
|
-
|
|
43
|
-
class PagesController < HighVoltage::PagesController
|
|
44
|
-
before_filter :authenticate
|
|
45
|
-
layout "danger"
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
Testing
|
|
49
|
-
-------
|
|
50
|
-
|
|
51
|
-
Just a suggestion, but you can test your pages using Shoulda pretty easily:
|
|
52
|
-
|
|
53
|
-
class PagesControllerTest < ActionController::TestCase
|
|
54
|
-
tests PagesController
|
|
55
|
-
|
|
56
|
-
%w(earn_money screencast about contact).each do |page|
|
|
57
|
-
context "on GET to /pages/#{page}" do
|
|
58
|
-
setup { get :show, :id => page }
|
|
59
|
-
|
|
60
|
-
should_respond_with :success
|
|
61
|
-
should_render_template page
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
If you're not using a custom PagesController be sure to test <code>HighVoltage::PagesController</code> instead.
|
|
67
|
-
|
|
68
|
-
Enjoy!
|
|
69
|
-
|
|
70
|
-
License
|
|
71
|
-
-------
|
|
72
|
-
|
|
73
|
-
Copyright (c) thoughtbot, inc -- released under the MIT license.
|
data/init.rb
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require 'high_voltage'
|
data/install.rb
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Install hook code here
|