Permalink
Browse files

Removed extraneous spaces in source

  • Loading branch information...
1 parent b358e81 commit 1e137a96f2d00dc30ef08f72945c3a234f4e7a50 @njonsson committed Mar 14, 2006
Showing with 92 additions and 91 deletions.
  1. +6 −6 USAGE
  2. +6 −6 templates/controller.rb
  3. +25 −25 templates/functional_test.rb
  4. +1 −1 templates/routes.rb
  5. +23 −22 trestle_generator.gemspec
  6. +31 −31 trestle_generator.rb
View
12 USAGE
@@ -4,17 +4,17 @@ Description:
model does not exist, it creates the model as well. The generated code is
equivalent to the "scaffold :model" declaration, making it easy to migrate
when you wish to customize your controller and views.
-
+
The generator takes a model name, an optional controller name, and a
list of views as arguments. Trestle actions and views are created
automatically. Any views left over generate empty stubs.
-
+
The trestle actions are:
list, new, show, edit, destroy
-
+
The trestle views are:
list, new, show, edit
-
+
If a controller name is not given, the plural form of the model name
will be used. The model and controller names may be given in CamelCase
or under_score and should not be suffixed with 'Model' or 'Controller'.
@@ -23,13 +23,13 @@ Description:
Example:
./script/generate trestle Account Bank debit credit
-
+
This will generate an Account model and BankController with a full test
suite and a basic user interface. Now create the accounts table in your
database and browse to http://localhost/bank/ -- voila, you're on Rails!
Modules Example:
./script/generate trestle CreditCard 'admin/credit_card' suspend late_fee
-
+
This will generate a CreditCard model and CreditCardController controller
in the admin module.
View
@@ -3,11 +3,11 @@ class <%= controller_class_name %>Controller < ApplicationController
:params => :id,
:add_flash => { :notice => 'Missing <%= singular_name %> ID.' },
:redirect_to => { :action => 'list<%= suffix %>' }
-
+
<% for action in nontrestle_actions -%>
def <%= action %><%= suffix %>
end
-
+
<% end -%>
def destroy<%= suffix %>
if request.post?
@@ -19,7 +19,7 @@ def destroy<%= suffix %>
redirect_to :action => 'edit<%= suffix %>', :id => params[:id]
end
end
-
+
def edit<%= suffix %>
if request.post?
@<%= singular_name %> = <%= model_name %>.find(params[:id])
@@ -31,11 +31,11 @@ def edit<%= suffix %>
@<%= singular_name %> = <%= model_name %>.find(params[:id])
end
end
-
+
def list<%= suffix %>
@<%= singular_name %>_pages, @<%= plural_name %> = paginate(:<%= plural_name %>)
end
-
+
def new<%= suffix %>
if request.post?
@<%= singular_name %> = <%= model_name %>.new(params[:<%= singular_name %>])
@@ -47,7 +47,7 @@ def new<%= suffix %>
@<%= singular_name %> = <%= model_name %>.new
end
end
-
+
def show<%= suffix %>
@<%= singular_name %> = <%= model_name %>.find(params[:id])
end
@@ -6,92 +6,92 @@ class <%= controller_class_name %>Controller; def rescue_action(e) raise e end;
class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
fixtures :<%= table_name %>
-
+
def setup
@controller = <%= controller_class_name %>Controller.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
-
+
<% for action in nontrestle_actions -%>
def test_<%= action %>
get '<%= action %>'
assert_response :success
assert_template '<%= action %>'
end
-
+
<% end -%>
def test_destroy<%= suffix %>_using_get
assert_not_nil <%= model_name %>.find(1)
-
+
get 'destroy<%= suffix %>', :id => 1
assert_response :redirect
assert_redirected_to :action => 'edit<%= suffix %>'
-
+
assert_not_nil <%= model_name %>.find(1)
end
-
+
def test_destroy<%= suffix %>_using_post
assert_not_nil <%= model_name %>.find(1)
-
+
post 'destroy<%= suffix %>', :id => 1
assert_response :redirect
assert_redirected_to :action => 'list<%= suffix %>'
-
+
assert_raise(ActiveRecord::RecordNotFound) { <%= model_name %>.find(1) }
end
-
+
def test_edit<%= suffix %>_using_get
get 'edit<%= suffix %>', :id => 1
-
+
assert_response :success
assert_template 'edit<%= suffix %>'
-
+
assert_not_nil assigns(:<%= singular_name %>)
assert assigns(:<%= singular_name %>).valid?
end
-
+
def test_edit<%= suffix %>_using_post
post 'edit<%= suffix %>', :id => 1
assert_response :redirect
assert_redirected_to :action => 'show<%= suffix %>', :id => 1
end
-
+
def test_list<%= suffix %>
get 'list<%= suffix %>'
-
+
assert_response :success
assert_template '<%= plural_name %>/list<%= suffix %>'
-
+
assert_not_nil assigns(:<%= plural_name %>)
end
-
+
def test_new<%= suffix %>_using_get
get 'new<%= suffix %>'
-
+
assert_response :success
assert_template 'new<%= suffix %>'
-
+
assert_not_nil assigns(:<%= singular_name %>)
end
-
+
def test_new<%= suffix %>_using_post
num_<%= plural_name %> = <%= model_name %>.count
-
+
post 'new<%= suffix %>', :<%= singular_name %> => {}
-
+
assert_response :redirect
assert_redirected_to :action => 'list<%= suffix %>'
-
+
assert_equal num_<%= plural_name %> + 1, <%= model_name %>.count
end
-
+
def test_show<%= suffix %>
get 'show<%= suffix %>', :id => 1
-
+
assert_response :success
assert_template '<%= plural_name %>/show<%= suffix %>'
-
+
assert_not_nil assigns(:<%= singular_name %>)
assert assigns(:<%= singular_name %>).valid?
end
View
@@ -1,7 +1,7 @@
ActionController::Routing::Routes.draw do |map|
# Add your own custom routes here.
# The priority is based upon order of creation: first created -> highest priority.
-
+
# Here's a sample route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
# Keep in mind you can assign values other than :controller and :action
View
@@ -9,17 +9,17 @@ spec = Gem::Specification.new do |s|
s.description = <<-EOF
Don’t drive your train across a gorge with nothing but a scaffold underneath
it. Use a trestle instead!
-
+
The trestle generator is drop-in replacement for the Rails scaffold
generator. Unlike scaffolding, trestle controllers protect your models from
state-changing HTTP GET requests. They also have streamlined URLs that make
your application more usable.
-
+
SAFETY The trestle generator requires the HTTP POST method for actions that
change data. Well-behaved web applications protect themselves against errant
HTTP GET requests such as come from Google Web Accelerator and the like.
Scaffolded controllers fail to do this.
-
+
USABILITY Trestle controllers have just five actions (list, new, show,
edit, and destroy). The scaffold generator produces controllers that have
eight actions. Fewer actions exposed to the outside world is better if the
@@ -29,56 +29,57 @@ spec = Gem::Specification.new do |s|
scaffold-generated code. Less work for you means your application gets built
sooner. Tobias Lütke’s postback_generator RubyGem had the same idea, but
trestle goes further.
-
+
A scaffold for a database table named ‘people’ has the following HTTP
interface:
-
+
/people - Lists existing person records
-
+
/people/list - Lists existing person records
-
+
/people/new - Shows an empty person form
-
+
/people/create - Creates a new person record from request parameters
-
+
/people/show/99 - Shows the person record having ID 99
-
+
/people/edit/99 - Shows a person form for the person record having ID 99
-
+
/people/update/99 - Updates the person record having ID 99 using request
parameters
-
+
/people/destroy/99 - Deletes the person record having ID 99, even for HTTP
GET!
-
+
Contrast this with the HTTP interface of the equivalent trestle controller:
-
+
/people - GET or POST lists existing person records
-
+
/people/new - GET shows an empty person form
-
+
/people/new - POST creates a new person record from request
parameters
-
+
/people/99 - GET or POST shows the person record having ID 99
-
+
/people/99/edit - GET shows a person form for the person record having ID 99
-
+
/people/99/edit - POST updates the person record having ID 99 using request
parameters
+
/people/99/destroy - GET redirects to /people/99/edit with a notice that the
user must click the form’s Destroy button in order to
destroy a record
-
+
/people/99/destroy - POST deletes the person record having ID 99 after
prompting the user for confirmation
-
+
Notice the hierarchical nature of trestle URLs. Because the ID comes before
the verb, the user can click the Up One Level button on the Google Toolbar
to explore the application. (The Up One Level button clips one element off
the end of the current URL.) Scaffold URLs do not play nicely with the Up
One Level button.
-
+
Trestle controllers are pain relief to users who like the Up One Level
button. But for a user who likes to type URLs in by hand, it also shows a
friendly notice if his request is missing an ID. This is one more way to
Oops, something went wrong.

0 comments on commit 1e137a9

Please sign in to comment.