aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-06-28 00:12:15 +0200
committerXavier Noria <fxn@hashref.com>2010-06-28 00:12:15 +0200
commit4329f8133fee8e4f3e558787f67de59f0c4a4dd1 (patch)
tree346ef7340d8348e50d119ca749a16c1654c20a08 /railties/lib/rails/generators
parentc37f7d66e49ffe5ac2115cc30e5529fd1c2924a8 (diff)
parentebee77a28a7267d5f23a28ba23c1eb88a2d7d527 (diff)
downloadrails-4329f8133fee8e4f3e558787f67de59f0c4a4dd1.tar.gz
rails-4329f8133fee8e4f3e558787f67de59f0c4a4dd1.tar.bz2
rails-4329f8133fee8e4f3e558787f67de59f0c4a4dd1.zip
Merge remote branch 'rails/master'
Diffstat (limited to 'railties/lib/rails/generators')
-rw-r--r--railties/lib/rails/generators/base.rb2
-rw-r--r--railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb7
-rw-r--r--railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb8
-rw-r--r--railties/lib/rails/generators/erb/scaffold/templates/edit.html.erb4
-rw-r--r--railties/lib/rails/generators/erb/scaffold/templates/index.html.erb14
-rw-r--r--railties/lib/rails/generators/erb/scaffold/templates/new.html.erb2
-rw-r--r--railties/lib/rails/generators/erb/scaffold/templates/show.html.erb4
-rw-r--r--railties/lib/rails/generators/named_base.rb18
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile7
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb2
-rw-r--r--railties/lib/rails/generators/rails/model/USAGE2
-rw-r--r--railties/lib/rails/generators/rails/resource/resource_generator.rb18
-rw-r--r--railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb2
-rw-r--r--railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb56
-rw-r--r--railties/lib/rails/generators/resource_helpers.rb2
-rw-r--r--railties/lib/rails/generators/test_unit/model/model_generator.rb2
-rw-r--r--railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb1
-rw-r--r--railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb26
18 files changed, 86 insertions, 91 deletions
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index bd2260fc29..67a9a6030d 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -3,7 +3,7 @@ begin
rescue LoadError
puts "Thor is not available.\nIf you ran this command from a git checkout " \
"of Rails, please make sure thor is installed,\nand run this command " \
- "as `ruby /path/to/rails myapp --dev`"
+ "as `ruby /path/to/rails new myapp --dev`"
exit
end
diff --git a/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb
index 2db7f7bbf3..b2c8d7051b 100644
--- a/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb
@@ -8,17 +8,12 @@ module Erb
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
- class_option :singleton, :type => :boolean, :desc => "Supply to skip index view"
-
def create_root_folder
empty_directory File.join("app/views", controller_file_path)
end
def copy_view_files
- views = available_views
- views.delete("index") if options[:singleton]
-
- views.each do |view|
+ available_views.each do |view|
filename = filename_with_extensions(view)
template filename, File.join("app/views", controller_file_path, filename)
end
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
index 9b83207b3f..d12b2ff0e5 100644
--- a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
+++ b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
@@ -1,10 +1,10 @@
-<%%= form_for(@<%= singular_name %>) do |f| %>
- <%% if @<%= singular_name %>.errors.any? %>
+<%%= form_for(@<%= singular_table_name %>) do |f| %>
+ <%% if @<%= singular_table_name %>.errors.any? %>
<div id="error_explanation">
- <h2><%%= pluralize(@<%= singular_name %>.errors.count, "error") %> prohibited this <%= singular_name %> from being saved:</h2>
+ <h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
<ul>
- <%% @<%= singular_name %>.errors.full_messages.each do |msg| %>
+ <%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
<li><%%= msg %></li>
<%% end %>
</ul>
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/edit.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/edit.html.erb
index 415f820206..e58b9fbd08 100644
--- a/railties/lib/rails/generators/erb/scaffold/templates/edit.html.erb
+++ b/railties/lib/rails/generators/erb/scaffold/templates/edit.html.erb
@@ -1,6 +1,6 @@
-<h1>Editing <%= singular_name %></h1>
+<h1>Editing <%= singular_table_name %></h1>
<%%= render 'form' %>
-<%%= link_to 'Show', @<%= singular_name %> %> |
+<%%= link_to 'Show', @<%= singular_table_name %> %> |
<%%= link_to 'Back', <%= index_helper %>_path %>
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb
index d30d306d42..4c46db4d67 100644
--- a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb
+++ b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb
@@ -1,4 +1,4 @@
-<h1>Listing <%= plural_name %></h1>
+<h1>Listing <%= plural_table_name %></h1>
<table>
<tr>
@@ -10,18 +10,18 @@
<th></th>
</tr>
-<%% @<%= plural_name %>.each do |<%= singular_name %>| %>
+<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
<tr>
<% for attribute in attributes -%>
- <td><%%= <%= singular_name %>.<%= attribute.name %> %></td>
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
<% end -%>
- <td><%%= link_to 'Show', <%= singular_name %> %></td>
- <td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
- <td><%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
+ <td><%%= link_to 'Show', <%= singular_table_name %> %></td>
+ <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
+ <td><%%= link_to 'Destroy', <%= singular_table_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<%% end %>
</table>
<br />
-<%%= link_to 'New <%= human_name %>', new_<%= singular_name %>_path %>
+<%%= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path %>
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/new.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/new.html.erb
index ddabc9d349..02ae4d015e 100644
--- a/railties/lib/rails/generators/erb/scaffold/templates/new.html.erb
+++ b/railties/lib/rails/generators/erb/scaffold/templates/new.html.erb
@@ -1,4 +1,4 @@
-<h1>New <%= singular_name %></h1>
+<h1>New <%= singular_table_name %></h1>
<%%= render 'form' %>
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb
index 31b8253b35..c0e5ccff1e 100644
--- a/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb
+++ b/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb
@@ -3,10 +3,10 @@
<% for attribute in attributes -%>
<p>
<b><%= attribute.human_name %>:</b>
- <%%= @<%= singular_name %>.<%= attribute.name %> %>
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
</p>
<% end -%>
-<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
+<%%= link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>) %> |
<%%= link_to 'Back', <%= index_helper %>_path %>
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb
index 72ec2856d0..44f831e6f3 100644
--- a/railties/lib/rails/generators/named_base.rb
+++ b/railties/lib/rails/generators/named_base.rb
@@ -51,7 +51,23 @@ module Rails
end
def index_helper
- uncountable? ? "#{plural_name}_index" : plural_name
+ uncountable? ? "#{plural_table_name}_index" : plural_table_name
+ end
+
+ def singular_table_name
+ @singular_table_name ||= table_name.singularize
+ end
+
+ def plural_table_name
+ @plural_table_name ||= table_name.pluralize
+ end
+
+ def plural_file_name
+ @plural_file_name ||= file_name.pluralize
+ end
+
+ def route_url
+ @route_url ||= class_path.collect{|dname| "/" + dname }.join('') + "/" + plural_file_name
end
# Tries to retrieve the application name or simple return application.
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
index 0b922a89c0..a108968b97 100644
--- a/railties/lib/rails/generators/rails/app/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -32,8 +32,9 @@ gem '<%= gem_for_database %>'<% if require_for_database %>, :require => '<%= req
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
-# Bundle gems for certain environments:
-# gem 'rspec', :group => :test
-# group :test do
+# Bundle gems for the local environment. Make sure to
+# put test-only gems in this group so their generators
+# and rake tasks are available in development mode:
+# group :development, :test do
# gem 'webrat'
# end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index 0066e2b0c2..031466cb86 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -22,7 +22,7 @@ module <%= app_const_base %>
# -- all .rb files in that directory are automatically loaded.
# Add additional load paths for your own custom dirs
- # config.load_paths += %W( #{config.root}/extras )
+ # config.autoload_paths += %W( #{config.root}/extras )
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named
diff --git a/railties/lib/rails/generators/rails/model/USAGE b/railties/lib/rails/generators/rails/model/USAGE
index db98a2dd1b..67f76aad01 100644
--- a/railties/lib/rails/generators/rails/model/USAGE
+++ b/railties/lib/rails/generators/rails/model/USAGE
@@ -40,6 +40,6 @@ Examples:
Module: app/models/admin.rb
Model: app/models/admin/account.rb
Test: test/unit/admin/account_test.rb
- Fixtures: test/fixtures/admin_accounts.yml
+ Fixtures: test/fixtures/admin/accounts.yml
Migration: db/migrate/XXX_add_admin_accounts.rb
diff --git a/railties/lib/rails/generators/rails/resource/resource_generator.rb b/railties/lib/rails/generators/rails/resource/resource_generator.rb
index 8a46708009..fc070026d6 100644
--- a/railties/lib/rails/generators/rails/resource/resource_generator.rb
+++ b/railties/lib/rails/generators/rails/resource/resource_generator.rb
@@ -14,23 +14,13 @@ module Rails
class_option :actions, :type => :array, :banner => "ACTION ACTION", :default => [],
:desc => "Actions for the resource controller"
- class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
-
def add_resource_route
return if options[:actions].present?
- route "resource#{:s unless options[:singleton]} :#{pluralize?(file_name)}"
+ route_config = class_path.collect{|namespace| "namespace :#{namespace} do " }.join(" ")
+ route_config << "resources :#{file_name.pluralize}"
+ route_config << " end" * class_path.size
+ route route_config
end
-
- protected
-
- def pluralize?(name)
- if options[:singleton]
- name
- else
- name.pluralize
- end
- end
-
end
end
end
diff --git a/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb b/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb
index 49af2974cd..2271c6f9c1 100644
--- a/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb
+++ b/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb
@@ -10,8 +10,6 @@ module Rails
class_option :orm, :banner => "NAME", :type => :string, :required => true,
:desc => "ORM to generate the controller for"
- class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
-
def create_controller_files
template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
end
diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
index b5f19b6d15..b21340f755 100644
--- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
+++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
@@ -1,53 +1,51 @@
class <%= controller_class_name %>Controller < ApplicationController
-<% unless options[:singleton] -%>
- # GET /<%= table_name %>
- # GET /<%= table_name %>.xml
+ # GET <%= route_url %>
+ # GET <%= route_url %>.xml
def index
- @<%= table_name %> = <%= orm_class.all(class_name) %>
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
respond_to do |format|
format.html # index.html.erb
- format.xml { render :xml => @<%= table_name %> }
+ format.xml { render :xml => @<%= plural_table_name %> }
end
end
-<% end -%>
- # GET /<%= table_name %>/1
- # GET /<%= table_name %>/1.xml
+ # GET <%= route_url %>/1
+ # GET <%= route_url %>/1.xml
def show
- @<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
respond_to do |format|
format.html # show.html.erb
- format.xml { render :xml => @<%= file_name %> }
+ format.xml { render :xml => @<%= singular_table_name %> }
end
end
- # GET /<%= table_name %>/new
- # GET /<%= table_name %>/new.xml
+ # GET <%= route_url %>/new
+ # GET <%= route_url %>/new.xml
def new
- @<%= file_name %> = <%= orm_class.build(class_name) %>
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
respond_to do |format|
format.html # new.html.erb
- format.xml { render :xml => @<%= file_name %> }
+ format.xml { render :xml => @<%= singular_table_name %> }
end
end
- # GET /<%= table_name %>/1/edit
+ # GET <%= route_url %>/1/edit
def edit
- @<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
end
- # POST /<%= table_name %>
- # POST /<%= table_name %>.xml
+ # POST <%= route_url %>
+ # POST <%= route_url %>.xml
def create
- @<%= file_name %> = <%= orm_class.build(class_name, "params[:#{file_name}]") %>
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
respond_to do |format|
if @<%= orm_instance.save %>
- format.html { redirect_to(@<%= file_name %>, :notice => '<%= human_name %> was successfully created.') }
- format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
+ format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully created.') }
+ format.xml { render :xml => @<%= singular_table_name %>, :status => :created, :location => @<%= singular_table_name %> }
else
format.html { render :action => "new" }
format.xml { render :xml => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
@@ -55,14 +53,14 @@ class <%= controller_class_name %>Controller < ApplicationController
end
end
- # PUT /<%= table_name %>/1
- # PUT /<%= table_name %>/1.xml
+ # PUT <%= route_url %>/1
+ # PUT <%= route_url %>/1.xml
def update
- @<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
respond_to do |format|
- if @<%= orm_instance.update_attributes("params[:#{file_name}]") %>
- format.html { redirect_to(@<%= file_name %>, :notice => '<%= human_name %> was successfully updated.') }
+ if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
+ format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
@@ -71,10 +69,10 @@ class <%= controller_class_name %>Controller < ApplicationController
end
end
- # DELETE /<%= table_name %>/1
- # DELETE /<%= table_name %>/1.xml
+ # DELETE <%= route_url %>/1
+ # DELETE <%= route_url %>/1.xml
def destroy
- @<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
@<%= orm_instance.destroy %>
respond_to do |format|
diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb
index 3a98a8f9c1..829f4b200a 100644
--- a/railties/lib/rails/generators/resource_helpers.rb
+++ b/railties/lib/rails/generators/resource_helpers.rb
@@ -72,7 +72,7 @@ module Rails
end
# Initialize ORM::Generators::ActiveModel to access instance methods.
- def orm_instance(name=file_name)
+ def orm_instance(name=singular_table_name)
@orm_instance ||= @orm_class.new(name)
end
end
diff --git a/railties/lib/rails/generators/test_unit/model/model_generator.rb b/railties/lib/rails/generators/test_unit/model/model_generator.rb
index 609b815683..c1dd535dd3 100644
--- a/railties/lib/rails/generators/test_unit/model/model_generator.rb
+++ b/railties/lib/rails/generators/test_unit/model/model_generator.rb
@@ -16,7 +16,7 @@ module TestUnit
def create_fixture_file
if options[:fixture] && options[:fixture_replacement].nil?
- template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
+ template 'fixtures.yml', File.join('test/fixtures', class_path, "#{plural_file_name}.yml")
end
end
end
diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
index c0315c7fe6..f7e907a017 100644
--- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
@@ -6,7 +6,6 @@ module TestUnit
class ScaffoldGenerator < Base
include Rails::Generators::ResourceHelpers
- class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
check_class_collision :suffix => "ControllerTest"
def create_test_files
diff --git a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb
index d5d3d6d5cd..f23e495450 100644
--- a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb
+++ b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb
@@ -2,48 +2,46 @@ require 'test_helper'
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
setup do
- @<%= file_name %> = <%= table_name %>(:one)
+ @<%= singular_table_name %> = <%= table_name %>(:one)
end
-<% unless options[:singleton] -%>
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:<%= table_name %>)
end
-<% end -%>
test "should get new" do
get :new
assert_response :success
end
- test "should create <%= file_name %>" do
+ test "should create <%= singular_table_name %>" do
assert_difference('<%= class_name %>.count') do
- post :create, :<%= file_name %> => @<%= file_name %>.attributes
+ post :create, :<%= singular_table_name %> => @<%= singular_table_name %>.attributes
end
- assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
+ assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
end
- test "should show <%= file_name %>" do
- get :show, :id => @<%= file_name %>.to_param
+ test "should show <%= singular_table_name %>" do
+ get :show, :id => @<%= singular_table_name %>.to_param
assert_response :success
end
test "should get edit" do
- get :edit, :id => @<%= file_name %>.to_param
+ get :edit, :id => @<%= singular_table_name %>.to_param
assert_response :success
end
- test "should update <%= file_name %>" do
- put :update, :id => @<%= file_name %>.to_param, :<%= file_name %> => @<%= file_name %>.attributes
- assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
+ test "should update <%= singular_table_name %>" do
+ put :update, :id => @<%= singular_table_name %>.to_param, :<%= singular_table_name %> => @<%= singular_table_name %>.attributes
+ assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
end
- test "should destroy <%= file_name %>" do
+ test "should destroy <%= singular_table_name %>" do
assert_difference('<%= class_name %>.count', -1) do
- delete :destroy, :id => @<%= file_name %>.to_param
+ delete :destroy, :id => @<%= singular_table_name %>.to_param
end
assert_redirected_to <%= index_helper %>_path