aboutsummaryrefslogtreecommitdiffstats
path: root/railties/generators/scaffold
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-07 13:14:05 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-07 13:14:05 +0000
commitdaee6fd92ac16878f6806c3382a9e74592aa9656 (patch)
treed477c6502960cb141403f8b4640dd483b487e5df /railties/generators/scaffold
parent838c5a3d82367977d13ced01f9e28c22ccff32ef (diff)
downloadrails-daee6fd92ac16878f6806c3382a9e74592aa9656.tar.gz
rails-daee6fd92ac16878f6806c3382a9e74592aa9656.tar.bz2
rails-daee6fd92ac16878f6806c3382a9e74592aa9656.zip
Added new generator framework that informs about its doings on generation and enables updating and destruction of generated artifacts. See the new script/destroy and script/update for more details #487 [bitsweat]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@518 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/generators/scaffold')
-rw-r--r--railties/generators/scaffold/USAGE27
-rw-r--r--railties/generators/scaffold/scaffold_generator.rb60
-rw-r--r--railties/generators/scaffold/templates/controller.rb54
-rw-r--r--railties/generators/scaffold/templates/fixtures.yml7
-rw-r--r--railties/generators/scaffold/templates/functional_test.rb79
-rw-r--r--railties/generators/scaffold/templates/layout.rhtml11
-rw-r--r--railties/generators/scaffold/templates/style.css53
-rw-r--r--railties/generators/scaffold/templates/view_edit.rhtml7
-rw-r--r--railties/generators/scaffold/templates/view_list.rhtml24
-rw-r--r--railties/generators/scaffold/templates/view_new.rhtml6
-rw-r--r--railties/generators/scaffold/templates/view_show.rhtml8
11 files changed, 0 insertions, 336 deletions
diff --git a/railties/generators/scaffold/USAGE b/railties/generators/scaffold/USAGE
deleted file mode 100644
index a8c9ed8967..0000000000
--- a/railties/generators/scaffold/USAGE
+++ /dev/null
@@ -1,27 +0,0 @@
-GENERATOR
- scaffold - create a model and basic controller
-
-SYNOPSIS
- generate scaffold ModelName [ControllerName] [action ...]
-
-DESCRIPTION
- The scaffold generator takes the name of the new model as the
- first argument, an optional controller name as the second, and
- an optional list of controller actions as the subsequent arguments.
- If the controller name is not specified, the plural form of the model
- name will be used. Any actions with scaffolding code available
- will be generated in your controller; others will be left as stubs.
-
- The generated controller has the same code that "scaffold :model"
- uses, so it's easy to migrate when you want to start customizing
- your controller.
-
-EXAMPLE
- ./script/generate scaffold Account Bank debit credit
-
- This will generate the Account model with unit tests and fixtures,
- the BankController controller with actions, views, and tests for
- index, list, show, new, create, edit, update, and destroy.
-
- Now create the accounts table in your database and browse to
- http://localhost/bank/ -- voila, you're on Rails!
diff --git a/railties/generators/scaffold/scaffold_generator.rb b/railties/generators/scaffold/scaffold_generator.rb
deleted file mode 100644
index 3901d6b2bc..0000000000
--- a/railties/generators/scaffold/scaffold_generator.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-require 'rails_generator'
-
-class ScaffoldGenerator < Rails::Generator::Base
- def generate
- # Model.
- generator('model').generate
-
- # Fixtures.
- template "fixtures.yml", "test/fixtures/#{table_name}.yml"
-
- @controller_class_name = args.empty? ? Inflector.pluralize(class_name) : args.shift.sub(/^[a-z]?/) { |m| m.capitalize }
- @controller_name = Inflector.underscore(@controller_class_name)
-
- # Controller class, functional test, helper, and views.
- template "controller.rb", "app/controllers/#{@controller_name}_controller.rb"
- template "functional_test.rb", "test/functional/#{@controller_name}_controller_test.rb"
- template "controller/helper.rb", "app/helpers/#{@controller_name}_helper.rb"
-
- # Layout and stylesheet.
- unless File.file?("app/views/layouts/#{@controller_name}.rhtml")
- template "layout.rhtml", "app/views/layouts/#{@controller_name}.rhtml"
- end
- unless File.file?("public/stylesheets/scaffold.css")
- template "style.css", "public/stylesheets/scaffold.css"
- end
-
- # Scaffolded views.
- scaffold_views.each do |action|
- template "view_#{action}.rhtml", "app/views/#{@controller_name}/#{action}.rhtml"
- end
-
- # Unscaffolded views.
- unscaffolded_actions.each do |action|
- template "controller/view.rhtml",
- "app/views/#{@controller_name}/#{action}.rhtml",
- binding
- end
- end
-
- def full_class_name
- class_name + "Controller"
- end
-
- protected
- def scaffold_views
- %w(list show new edit)
- end
-
- def scaffold_actions
- scaffold_views + %w(index create update destroy)
- end
-
- def unscaffolded_actions
- args - scaffold_actions
- end
-
- def suffix
- "_#{singular_name}" if options[:suffix]
- end
-end
diff --git a/railties/generators/scaffold/templates/controller.rb b/railties/generators/scaffold/templates/controller.rb
deleted file mode 100644
index 7ccb517bee..0000000000
--- a/railties/generators/scaffold/templates/controller.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-class <%= @controller_class_name %>Controller < ApplicationController
-<% unless suffix -%>
- def index
- list
- render_action 'list'
- end
-<% end -%>
-
-<% for action in unscaffolded_actions -%>
- def <%= action %><%= suffix %>
- end
-
-<% end -%>
- def list<%= suffix %>
- @<%= plural_name %> = <%= class_name %>.find_all
- end
-
- def show<%= suffix %>
- @<%= singular_name %> = <%= class_name %>.find(@params['id'])
- end
-
- def new<%= suffix %>
- @<%= singular_name %> = <%= class_name %>.new
- end
-
- def create<%= suffix %>
- @<%= singular_name %> = <%= class_name %>.new(@params['<%= singular_name %>'])
- if @<%= singular_name %>.save
- flash['notice'] = '<%= class_name %> was successfully created.'
- redirect_to :action => 'list<%= suffix %>'
- else
- render_action 'new<%= suffix %>'
- end
- end
-
- def edit<%= suffix %>
- @<%= singular_name %> = <%= class_name %>.find(@params['id'])
- end
-
- def update
- @<%= singular_name %> = <%= class_name %>.find(@params['<%= singular_name %>']['id'])
- if @<%= singular_name %>.update_attributes(@params['<%= singular_name %>'])
- flash['notice'] = '<%= class_name %> was successfully updated.'
- redirect_to :action => 'show<%= suffix %>', :id => @<%= singular_name %>.id
- else
- render_action 'edit<%= suffix %>'
- end
- end
-
- def destroy<%= suffix %>
- <%= class_name %>.find(@params['id']).destroy
- redirect_to :action => 'list<%= suffix %>'
- end
-end
diff --git a/railties/generators/scaffold/templates/fixtures.yml b/railties/generators/scaffold/templates/fixtures.yml
deleted file mode 100644
index ea67f36ad8..0000000000
--- a/railties/generators/scaffold/templates/fixtures.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-first_<%= singular_name %>:
- id: 1
-
-another_<%= singular_name %>:
- id: 2
diff --git a/railties/generators/scaffold/templates/functional_test.rb b/railties/generators/scaffold/templates/functional_test.rb
deleted file mode 100644
index 004af030be..0000000000
--- a/railties/generators/scaffold/templates/functional_test.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-require '<%= @controller_name %>_controller'
-
-# Re-raise errors caught by the controller.
-class <%= @controller_class_name %>Controller; def rescue_action(e) raise e end; end
-
-class <%= @controller_class_name %>ControllerTest < Test::Unit::TestCase
- fixtures :<%= table_name %>
-
- def setup
- @controller = <%= @controller_class_name %>Controller.new
- @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
- end
-
-<% for action in unscaffolded_actions -%>
- def test_<%= action %>
- process :<%= action %>
- assert_rendered_file '<%= action %>'
- end
-
-<% end -%>
-<% unless suffix -%>
- def test_index
- process :index
- assert_rendered_file 'list'
- end
-
-<% end -%>
- def test_list<%= suffix %>
- process :list<%= suffix %>
- assert_rendered_file 'list<%= suffix %>'
- assert_template_has '<%= plural_name %>'
- end
-
- def test_show<%= suffix %>
- process :show<%= suffix %>, 'id' => 1
- assert_rendered_file 'show'
- assert_template_has '<%= singular_name %>'
- assert_valid_record '<%= singular_name %>'
- end
-
- def test_new<%= suffix %>
- process :new<%= suffix %>
- assert_rendered_file 'new<%= suffix %>'
- assert_template_has '<%= singular_name %>'
- end
-
- def test_create
- num_<%= plural_name %> = <%= class_name %>.find_all.size
-
- process :create<%= suffix %>, '<%= singular_name %>' => { }
- assert_redirected_to :action => 'list<%= suffix %>'
-
- assert_equal num_<%= plural_name %> + 1, <%= class_name %>.find_all.size
- end
-
- def test_edit<%= suffix %>
- process :edit<%= suffix %>, 'id' => 1
- assert_rendered_file 'edit<%= suffix %>'
- assert_template_has '<%= singular_name %>'
- assert_valid_record '<%= singular_name %>'
- end
-
- def test_update<%= suffix %>
- process :update<%= suffix %>, '<%= singular_name %>' => { 'id' => 1 }
- assert_redirected_to :action => 'show<%= suffix %>', :id => 1
- end
-
- def test_destroy<%= suffix %>
- assert_not_nil <%= class_name %>.find(1)
-
- process :destroy, 'id' => 1
- assert_redirected_to :action => 'list<%= suffix %>'
-
- assert_raise(ActiveRecord::RecordNotFound) {
- <%= singular_name %> = <%= class_name %>.find(1)
- }
- end
-end
diff --git a/railties/generators/scaffold/templates/layout.rhtml b/railties/generators/scaffold/templates/layout.rhtml
deleted file mode 100644
index 59d5585b51..0000000000
--- a/railties/generators/scaffold/templates/layout.rhtml
+++ /dev/null
@@ -1,11 +0,0 @@
-<html>
-<head>
- <title>Scaffolding: <%%= controller.controller_name %>#<%%= controller.action_name %></title>
- <link href="/stylesheets/scaffold.css" rel="stylesheet" type="text/css" />
-</head>
-<body>
-
-<%%= @content_for_layout %>
-
-</body>
-</html>
diff --git a/railties/generators/scaffold/templates/style.css b/railties/generators/scaffold/templates/style.css
deleted file mode 100644
index 8f512501bf..0000000000
--- a/railties/generators/scaffold/templates/style.css
+++ /dev/null
@@ -1,53 +0,0 @@
-body { background-color: #fff; color: #333; }
-
-body, p, ol, ul, td {
- font-family: verdana, arial, helvetica, sans-serif;
- font-size: 13px;
- line-height: 18px;
-}
-
-pre {
- background-color: #eee;
- padding: 10px;
- font-size: 11px;
-}
-
-a { color: #000; }
-a:visited { color: #666; }
-a:hover { color: #fff; background-color:#000; }
-
-.fieldWithErrors {
- padding: 2px;
- background-color: red;
- display: table;
-}
-
-#ErrorExplanation {
- width: 400px;
- border: 2px solid #red;
- padding: 7px;
- padding-bottom: 12px;
- margin-bottom: 20px;
- background-color: #f0f0f0;
-}
-
-#ErrorExplanation h2 {
- text-align: left;
- font-weight: bold;
- padding: 5px 5px 5px 15px;
- font-size: 12px;
- margin: -7px;
- background-color: #c00;
- color: #fff;
-}
-
-#ErrorExplanation p {
- color: #333;
- margin-bottom: 0;
- padding: 5px;
-}
-
-#ErrorExplanation ul li {
- font-size: 12px;
- list-style: square;
-}
diff --git a/railties/generators/scaffold/templates/view_edit.rhtml b/railties/generators/scaffold/templates/view_edit.rhtml
deleted file mode 100644
index 260b0ebda1..0000000000
--- a/railties/generators/scaffold/templates/view_edit.rhtml
+++ /dev/null
@@ -1,7 +0,0 @@
-<h1>Editing <%= singular_name %></h1>
-
-<%%= error_messages_for '<%= singular_name %>' %>
-<%%= form '<%= singular_name %>', :action => 'update<%= suffix %>' %>
-
-<%%= link_to 'Show', :action => 'show<%= suffix %>', :id => @<%= singular_name %>.id %> |
-<%%= link_to 'Back', :action => 'list<%= suffix %>' %>
diff --git a/railties/generators/scaffold/templates/view_list.rhtml b/railties/generators/scaffold/templates/view_list.rhtml
deleted file mode 100644
index 068fd67472..0000000000
--- a/railties/generators/scaffold/templates/view_list.rhtml
+++ /dev/null
@@ -1,24 +0,0 @@
-<h1>Listing <%= plural_name %></h1>
-
-<table>
- <tr>
-<%% for column in <%= class_name %>.content_columns %>
- <th><%%= column.human_name %></th>
-<%% end %>
- </tr>
-
-<%% for <%= singular_name %> in @<%= plural_name %> %>
- <tr>
- <%% for column in <%= class_name %>.content_columns %>
- <td><%%=h <%= singular_name %>[column.name] %></td>
- <%% end %>
- <td><%%= link_to 'Show', :action => 'show<%= suffix %>', :id => <%= singular_name %>.id %></td>
- <td><%%= link_to 'Edit', :action => 'edit<%= suffix %>', :id => <%= singular_name %>.id %></td>
- <td><%%= link_to 'Destroy', :action => 'destroy<%= suffix %>', :id => <%= singular_name %>.id %></td>
- </tr>
-<%% end %>
-</table>
-
-<br />
-
-<%%= link_to 'New <%= singular_name %>', :action => 'new<%= suffix %>' %>
diff --git a/railties/generators/scaffold/templates/view_new.rhtml b/railties/generators/scaffold/templates/view_new.rhtml
deleted file mode 100644
index df68c1abbf..0000000000
--- a/railties/generators/scaffold/templates/view_new.rhtml
+++ /dev/null
@@ -1,6 +0,0 @@
-<h1>New <%= @singular_name %></h1>
-
-<%%= error_messages_for '<%= singular_name %>' %>
-<%%= form '<%= singular_name %>', :action => 'create<%= suffix %>' %>
-
-<%%= link_to 'Back', :action => 'list<%= suffix %>' %>
diff --git a/railties/generators/scaffold/templates/view_show.rhtml b/railties/generators/scaffold/templates/view_show.rhtml
deleted file mode 100644
index ba8f3616dd..0000000000
--- a/railties/generators/scaffold/templates/view_show.rhtml
+++ /dev/null
@@ -1,8 +0,0 @@
-<%% for column in <%= class_name %>.content_columns %>
-<p>
- <b><%%= column.human_name %>:</b> <%%= @<%= singular_name %>.send(column.name) %>
-</p>
-<%% end %>
-
-<%%= link_to 'Edit', :action => 'edit<%= suffix %>', :id => @<%= singular_name %>.id %> |
-<%%= link_to 'Back', :action => 'list<%= suffix %>' %>