high_voltage 0.9.1 → 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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 [name of plugin creator]
1
+ Copyright 2010 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/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
+ ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
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, :with => :invalid_page
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 invalid_page
14
- render :nothing => true, :status => 404
19
+ def current_page
20
+ "pages/#{clean_path}"
15
21
  end
16
22
 
17
- def current_page
18
- "pages/#{params[:id].to_s.downcase}"
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
1
  Rails.application.routes.draw do
2
- resources :pages, :controller => 'high_voltage/pages', :only => :show
2
+ match '/pages/*id' => 'high_voltage/pages#show', :as => :page
3
3
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: high_voltage
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 9
9
- - 1
10
- version: 0.9.1
4
+ prerelease:
5
+ version: 1.0.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Dan Croak
@@ -15,11 +10,13 @@ authors:
15
10
  - Tammer Saleh
16
11
  - Nick Quaranto
17
12
  - Tristan Dunn
13
+ - Chad Pytel
14
+ - Joe Ferris
18
15
  autorequire:
19
16
  bindir: bin
20
17
  cert_chain: []
21
18
 
22
- date: 2010-04-20 00:00:00 -04:00
19
+ date: 2011-06-29 00:00:00 -04:00
23
20
  default_executable:
24
21
  dependencies: []
25
22
 
@@ -32,14 +29,12 @@ extensions: []
32
29
  extra_rdoc_files: []
33
30
 
34
31
  files:
32
+ - MIT-LICENSE
33
+ - README.md
35
34
  - app/controllers/high_voltage/pages_controller.rb
36
35
  - config/routes.rb
37
- - init.rb
38
- - install.rb
39
36
  - lib/high_voltage/engine.rb
40
37
  - lib/high_voltage.rb
41
- - MIT-LICENSE
42
- - README.markdown
43
38
  has_rdoc: true
44
39
  homepage: http://github.com/thoughtbot/high_voltage
45
40
  licenses: []
@@ -54,23 +49,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
49
  requirements:
55
50
  - - ">="
56
51
  - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
52
  version: "0"
61
53
  required_rubygems_version: !ruby/object:Gem::Requirement
62
54
  none: false
63
55
  requirements:
64
56
  - - ">="
65
57
  - !ruby/object:Gem::Version
66
- hash: 3
67
- segments:
68
- - 0
69
58
  version: "0"
70
59
  requirements: []
71
60
 
72
61
  rubyforge_project:
73
- rubygems_version: 1.3.7
62
+ rubygems_version: 1.6.2
74
63
  signing_key:
75
64
  specification_version: 3
76
65
  summary: Simple static page rendering controller
data/README.markdown DELETED
@@ -1,90 +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
- Routes
33
- ------
34
-
35
- By default, the static page routes will be like /pages/:id (where :id is the view filename).
36
-
37
- If you want to route to a static page in another location (for example, a homepage), do this:
38
-
39
- map.root :controller => 'pages', :action => 'show', :id => 'home'
40
-
41
- In that case, you'd need an app/views/pages/home.html.erb file.
42
-
43
- Generally speaking, you need to route to the 'show' action with an :id param of the view filename.
44
-
45
- You'll notice in your config/routes.rb file that the High Voltage routes are generated by:
46
-
47
- HighVoltage::Routes.draw(map)
48
-
49
- Override
50
- --------
51
-
52
- Most common reasons to override? Authentication, layouts.
53
-
54
- Create a PagesController of your own:
55
-
56
- script/generate controller pages
57
-
58
- Then modify it to subclass from High Voltage, adding whatever you need:
59
-
60
- class PagesController < HighVoltage::PagesController
61
- before_filter :authenticate
62
- layout "danger"
63
- end
64
-
65
- Testing
66
- -------
67
-
68
- Just a suggestion, but you can test your pages using Shoulda pretty easily:
69
-
70
- class PagesControllerTest < ActionController::TestCase
71
- tests PagesController
72
-
73
- %w(earn_money screencast about contact).each do |page|
74
- context "on GET to /pages/#{page}" do
75
- setup { get :show, :id => page }
76
-
77
- should_respond_with :success
78
- should_render_template page
79
- end
80
- end
81
- end
82
-
83
- If you're not using a custom PagesController be sure to test <code>HighVoltage::PagesController</code> instead.
84
-
85
- Enjoy!
86
-
87
- License
88
- -------
89
-
90
- 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,7 +0,0 @@
1
- line = "HighVoltage::Routes.draw(map)"
2
- path = "config/routes.rb"
3
-
4
- puts "inserting #{line} into #{path}"
5
-
6
- content = File.read(path).sub(/^(end\s*)$/) {|match| " #{line}\n#{match}" }
7
- File.open(path, 'wb') { |file| file.write(content) }