Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added semi-static pages via high-voltage
- Loading branch information
Tammer Saleh
committed
Oct 20, 2009
1 parent
6e994e5
commit 376163b
Showing
19 changed files
with
262 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class PagesController < HighVoltage::PagesController | ||
skip_before_filter :require_user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PagesHelper | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
ActionController::Routing::Routes.draw do |map| | ||
map.resource :user_session | ||
map.resources :users | ||
map.root :controller => :users, :action => :index | ||
map.resources :pages, :controller => 'pages', :only => [:show] | ||
|
||
map.root :controller => "pages", :action => "show", :id => "home" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'test_helper' | ||
|
||
class PagesControllerTest < ActionController::TestCase | ||
as_a_visitor do | ||
%w(home).each do |page| | ||
context "on GET to /pages/#{page}" do | ||
setup { get :show, :id => page } | ||
|
||
should_respond_with :success | ||
should_render_template page | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class PagesHelperTest < ActionView::TestCase | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2009 [name of plugin creator] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
High Voltage | ||
============ | ||
|
||
Rails engine for static pages. | ||
|
||
... but be careful. [Danger!](http://www.youtube.com/watch?v=HD5tnb2RBYg) | ||
|
||
Static pages? | ||
------------- | ||
|
||
Yeah, like "About us", "Directions", marketing pages, etc. | ||
|
||
Installation | ||
------------ | ||
|
||
script/plugin install git://github.com/thoughtbot/high_voltage.git | ||
|
||
Usage | ||
----- | ||
|
||
Write your static pages and put them in the RAILS_ROOT/app/views/pages directory. | ||
|
||
mkdir app/views/pages | ||
touch app/views/pages/about.html.erb | ||
|
||
After putting something interesting there, you can link to it from anywhere in your app with: | ||
|
||
link_to "About", page_path("about") | ||
|
||
Bam. | ||
|
||
Override | ||
-------- | ||
|
||
Most common reasons to override? Authentication, layouts. | ||
|
||
Create a PagesController of your own: | ||
|
||
script/generate controller pages | ||
|
||
Then modify it to subclass from High Voltage, adding whatever you need: | ||
|
||
class PagesController < HighVoltage::PagesController | ||
before_filter :authenticate | ||
layout "danger" | ||
end | ||
|
||
Don't forget to add the new route: | ||
|
||
map.resources :pages, | ||
:controller => 'pages', | ||
:only => [:show] | ||
|
||
Testing | ||
------- | ||
|
||
Just a suggestion, but you can test your pages using Shoulda pretty easily: | ||
|
||
class PagesControllerTest < ActionController::TestCase | ||
tests PagesController | ||
|
||
%w(earn_money screencast about contact).each do |page| | ||
context "on GET to /pages/#{page}" do | ||
setup { get :show, :id => page } | ||
|
||
should_respond_with :success | ||
should_render_template page | ||
end | ||
end | ||
end | ||
|
||
Enjoy! | ||
|
||
Copyright (c) 2009 Thoughtbot, released under the MIT license | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
|
||
desc 'Default: run unit tests.' | ||
task :default => :test | ||
|
||
desc 'Test the nothing_to_see_here_move_along plugin.' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.libs << 'test' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = true | ||
end | ||
|
||
desc 'Generate documentation for the nothing_to_see_here_move_along plugin.' | ||
Rake::RDocTask.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'NothingToSeeHereMoveAlong' | ||
rdoc.options << '--line-numbers' << '--inline-source' | ||
rdoc.rdoc_files.include('README') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end |
26 changes: 26 additions & 0 deletions
26
gold/vendor/plugins/high_voltage/app/controllers/high_voltage/pages_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class HighVoltage::PagesController < ApplicationController | ||
unloadable | ||
before_filter :ensure_valid | ||
|
||
def show | ||
render :template => current_page | ||
end | ||
|
||
protected | ||
|
||
def ensure_valid | ||
unless template_exists?(current_page) | ||
render :nothing => true, :status => 404 and return false | ||
end | ||
end | ||
|
||
def current_page | ||
"pages/#{params[:id].to_s.downcase}" | ||
end | ||
|
||
def template_exists?(path) | ||
view_paths.find_template(path, response.template.template_format) | ||
rescue ActionView::MissingTemplate | ||
false | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
gold/vendor/plugins/high_voltage/config/high_voltage_routes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ActionController::Routing::Routes.draw do |map| | ||
map.resources :pages, | ||
:controller => 'high_voltage/pages', | ||
:only => [:show] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'high_voltage' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Install hook code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module HighVoltage | ||
end | ||
|
||
require 'high_voltage/extensions/routes' | ||
|
15 changes: 15 additions & 0 deletions
15
gold/vendor/plugins/high_voltage/lib/high_voltage/extensions/routes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
if defined?(ActionController::Routing::RouteSet) | ||
class ActionController::Routing::RouteSet | ||
def load_routes_with_high_voltage! | ||
lib_path = File.dirname(__FILE__) | ||
high_voltage_routes = File.join(lib_path, *%w[.. .. .. config high_voltage_routes.rb]) | ||
unless configuration_files.include?(high_voltage_routes) | ||
add_configuration_file(high_voltage_routes) | ||
end | ||
load_routes_without_high_voltage! | ||
end | ||
|
||
alias_method_chain :load_routes!, :high_voltage | ||
end | ||
end | ||
|
4 changes: 4 additions & 0 deletions
4
gold/vendor/plugins/high_voltage/tasks/nothing_to_see_here_move_along_tasks.rake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# desc "Explaining what the task does" | ||
# task :nothing_to_see_here_move_along do | ||
# # Task goes here | ||
# end |
44 changes: 44 additions & 0 deletions
44
gold/vendor/plugins/high_voltage/test/pages_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'test_helper' | ||
|
||
class ApplicationController < ActionController::Base | ||
end | ||
|
||
require "high_voltage/pages_controller" | ||
require File.join(File.dirname(__FILE__), '..', 'config', 'high_voltage_routes') | ||
|
||
class HighVoltage::PagesControllerTest < ActionController::TestCase | ||
|
||
HighVoltage::PagesController.view_paths << "/tmp" | ||
|
||
context "on GET to a page that exists" do | ||
setup do | ||
@filename = '/tmp/pages/exists.html.erb' | ||
|
||
FileUtils.mkdir(File.dirname(@filename)) | ||
File.open(@filename, 'w') do |file| | ||
file << "hello <%= 'world' %>" | ||
end | ||
assert File.exists?(@filename) | ||
|
||
get :show, :id => 'exists' | ||
end | ||
|
||
should_respond_with :success | ||
should_render_template 'exists' | ||
|
||
teardown do | ||
begin | ||
FileUtils.rm(@filename) | ||
FileUtils.rmdir(File.dirname(@filename)) | ||
rescue StandardError => e | ||
puts "Error while removing files: #{e}" | ||
end | ||
end | ||
end | ||
|
||
context "on GET to /pages/invalid" do | ||
setup { get :show, :id => "invalid" } | ||
should_respond_with :missing | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ENV['RAILS_ENV'] = 'test' | ||
|
||
require 'rubygems' | ||
require 'active_support' | ||
require 'active_support/test_case' | ||
require 'action_controller' | ||
require 'test_help' | ||
require 'high_voltage' | ||
|
||
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'app', 'controllers') | ||
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'app', 'models') | ||
|
||
require 'shoulda' | ||
require 'shoulda/rails' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Uninstall hook code here |