aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators
diff options
context:
space:
mode:
authorAlvaro Pereyra <alvaro@xendacentral.com>2012-05-28 02:29:46 -0500
committerAlvaro Pereyra <alvaro@xendacentral.com>2012-05-28 02:29:46 -0500
commit72973a30704894c808836d80a001208c1af39e7c (patch)
treeab84954fed3e67628bb0884b0e4b0376638bc5dc /railties/lib/rails/generators
parent011863673a353c334ddb2c93227dceadc5d7c3b6 (diff)
parent0ad2146ccf45b3a26924e729a92cd2ff98356413 (diff)
downloadrails-72973a30704894c808836d80a001208c1af39e7c.tar.gz
rails-72973a30704894c808836d80a001208c1af39e7c.tar.bz2
rails-72973a30704894c808836d80a001208c1af39e7c.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'railties/lib/rails/generators')
-rw-r--r--railties/lib/rails/generators/actions.rb5
-rw-r--r--railties/lib/rails/generators/active_model.rb3
-rw-r--r--railties/lib/rails/generators/base.rb1
-rw-r--r--railties/lib/rails/generators/named_base.rb5
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/routes.rb7
-rw-r--r--railties/lib/rails/generators/rails/controller/templates/controller.rb4
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb26
-rw-r--r--railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb4
-rw-r--r--railties/lib/rails/generators/resource_helpers.rb2
-rw-r--r--railties/lib/rails/generators/test_case.rb13
10 files changed, 50 insertions, 20 deletions
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index 6cd2ea2bbd..c41acc7841 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -5,8 +5,7 @@ module Rails
module Generators
module Actions
- # Adds an entry into Gemfile for the supplied gem. If env
- # is specified, add the gem to the given environment.
+ # Adds an entry into Gemfile for the supplied gem.
#
# gem "rspec", :group => :test
# gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
@@ -27,7 +26,7 @@ module Rails
log :gemfile, message
options.each do |option, value|
- parts << ":#{option} => #{value.inspect}"
+ parts << "#{option}: #{value.inspect}"
end
in_root do
diff --git a/railties/lib/rails/generators/active_model.rb b/railties/lib/rails/generators/active_model.rb
index 3d3b50540a..0e51b9c568 100644
--- a/railties/lib/rails/generators/active_model.rb
+++ b/railties/lib/rails/generators/active_model.rb
@@ -11,7 +11,7 @@ module Rails
# ActiveRecord::Generators::ActiveModel.find(Foo, "params[:id]")
# # => "Foo.find(params[:id])"
#
- # Datamapper::Generators::ActiveModel.find(Foo, "params[:id]")
+ # DataMapper::Generators::ActiveModel.find(Foo, "params[:id]")
# # => "Foo.get(params[:id])"
#
# On initialization, the ActiveModel accepts the instance name that will
@@ -22,6 +22,7 @@ module Rails
#
# The only exception in ActiveModel for ActiveRecord is the use of self.build
# instead of self.new.
+ #
class ActiveModel
attr_reader :name
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index f2ded6be84..28d7680669 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -161,6 +161,7 @@ module Rails
# hook_for :resource_controller do |instance, controller|
# instance.invoke controller, [ instance.name.pluralize ]
# end
+ #
def self.hook_for(*names, &block)
options = names.extract_options!
in_base = options.delete(:in) || base_name
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb
index e02f19508f..63703176de 100644
--- a/railties/lib/rails/generators/named_base.rb
+++ b/railties/lib/rails/generators/named_base.rb
@@ -79,6 +79,10 @@ module Rails
@class_path
end
+ def namespaced_file_path
+ @namespaced_file_path ||= namespaced_class_path.join("/")
+ end
+
def namespaced_class_path
@namespaced_class_path ||= begin
namespace_path = namespace.name.split("::").map {|m| m.underscore }
@@ -168,6 +172,7 @@ module Rails
#
# If the generator is invoked with class name Admin, it will check for
# the presence of "AdminObserver".
+ #
def self.check_class_collision(options={})
define_method :check_class_collision do
name = if self.respond_to?(:controller_class_name) # for ScaffoldBase
diff --git a/railties/lib/rails/generators/rails/app/templates/config/routes.rb b/railties/lib/rails/generators/rails/app/templates/config/routes.rb
index 286e93c3cf..303e47877f 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/routes.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/routes.rb
@@ -1,6 +1,10 @@
<%= app_const %>.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
+
+ # You can have the root of your site routed with "root"
+ # just remember to delete public/index.html.
+ # root :to => 'welcome#index'
# Sample of regular route:
# get 'products/:id' => 'catalog#view'
@@ -46,9 +50,6 @@
# resources :products
# end
- # You can have the root of your site routed with "root"
- # just remember to delete public/index.html.
- # root :to => 'welcome#index'
# See how all your routes lay out with "rake routes"
end \ No newline at end of file
diff --git a/railties/lib/rails/generators/rails/controller/templates/controller.rb b/railties/lib/rails/generators/rails/controller/templates/controller.rb
index 52243f4a2f..ece6bbba3b 100644
--- a/railties/lib/rails/generators/rails/controller/templates/controller.rb
+++ b/railties/lib/rails/generators/rails/controller/templates/controller.rb
@@ -1,3 +1,7 @@
+<% if namespaced? -%>
+require_dependency "<%= namespaced_file_path %>/application_controller"
+<% end -%>
+
<% module_namespacing do -%>
class <%= class_name %>Controller < ApplicationController
<% actions.each do |action| -%>
diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
index 722e37e20b..ab0e440bc4 100644
--- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -139,7 +139,7 @@ task :default => :test
gemfile_in_app_path = File.join(rails_app_path, "Gemfile")
if File.exist? gemfile_in_app_path
- entry = "gem '#{name}', :path => '#{relative_path}'"
+ entry = "gem '#{name}', path: '#{relative_path}'"
append_file gemfile_in_app_path, entry
end
end
@@ -232,6 +232,18 @@ task :default => :test
public_task :apply_rails_template, :run_bundle
+ def name
+ @name ||= begin
+ # same as ActiveSupport::Inflector#underscore except not replacing '-'
+ underscored = original_name.dup
+ underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
+ underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
+ underscored.downcase!
+
+ underscored
+ end
+ end
+
protected
def app_templates_dir
@@ -268,18 +280,6 @@ task :default => :test
@original_name ||= File.basename(destination_root)
end
- def name
- @name ||= begin
- # same as ActiveSupport::Inflector#underscore except not replacing '-'
- underscored = original_name.dup
- underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
- underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
- underscored.downcase!
-
- underscored
- end
- end
-
def camelized
@camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize
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 b95aea5f19..0294bde582 100644
--- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
+++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
@@ -1,3 +1,7 @@
+<% if namespaced? -%>
+require_dependency "<%= namespaced_file_path %>/application_controller"
+<% end -%>
+
<% module_namespacing do -%>
class <%= controller_class_name %>Controller < ApplicationController
# GET <%= route_url %>
diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb
index 3c12da359b..48833869e5 100644
--- a/railties/lib/rails/generators/resource_helpers.rb
+++ b/railties/lib/rails/generators/resource_helpers.rb
@@ -4,6 +4,7 @@ module Rails
module Generators
# Deal with controller names on scaffold and add some helpers to deal with
# ActiveModel.
+ #
module ResourceHelpers
mattr_accessor :skip_warn
@@ -12,6 +13,7 @@ module Rails
end
# Set controller variables on initialization.
+ #
def initialize(*args) #:nodoc:
super
diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb
index e8f5925ca5..ff9cf0087e 100644
--- a/railties/lib/rails/generators/test_case.rb
+++ b/railties/lib/rails/generators/test_case.rb
@@ -26,6 +26,7 @@ module Rails
# destination File.expand_path("../tmp", File.dirname(__FILE__))
# setup :prepare_destination
# end
+ #
class TestCase < ActiveSupport::TestCase
include FileUtils
@@ -42,6 +43,7 @@ module Rails
# Sets which generator should be tested:
#
# tests AppGenerator
+ #
def self.tests(klass)
self.generator_class = klass
end
@@ -50,6 +52,7 @@ module Rails
# invoking it.
#
# arguments %w(app_name --skip-active-record)
+ #
def self.arguments(array)
self.default_arguments = array
end
@@ -57,6 +60,7 @@ module Rails
# Sets the destination of generator files:
#
# destination File.expand_path("../tmp", File.dirname(__FILE__))
+ #
def self.destination(path)
self.destination_root = path
end
@@ -79,6 +83,7 @@ module Rails
# assert_match(/Product\.all/, index)
# end
# end
+ #
def assert_file(relative, *contents)
absolute = File.expand_path(relative, destination_root)
assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not"
@@ -101,6 +106,7 @@ module Rails
# path relative to the configured destination:
#
# assert_no_file "config/random.rb"
+ #
def assert_no_file(relative)
absolute = File.expand_path(relative, destination_root)
assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does"
@@ -118,6 +124,7 @@ module Rails
# assert_file "db/migrate/003_create_products.rb"
#
# Consequently, assert_migration accepts the same arguments has assert_file.
+ #
def assert_migration(relative, *contents, &block)
file_name = migration_file_name(relative)
assert file_name, "Expected migration #{relative} to exist, but was not found"
@@ -128,6 +135,7 @@ module Rails
# path relative to the configured destination:
#
# assert_no_migration "db/migrate/create_products.rb"
+ #
def assert_no_migration(relative)
file_name = migration_file_name(relative)
assert_nil file_name, "Expected migration #{relative} to not exist, but found #{file_name}"
@@ -142,6 +150,7 @@ module Rails
# assert_match(/create_table/, up)
# end
# end
+ #
def assert_class_method(method, content, &block)
assert_instance_method "self.#{method}", content, &block
end
@@ -154,6 +163,7 @@ module Rails
# assert_match(/Product\.all/, index)
# end
# end
+ #
def assert_instance_method(method, content)
assert content =~ /def #{method}(\(.+\))?(.*?)\n end/m, "Expected to have method #{method}"
yield $2.strip if block_given?
@@ -164,6 +174,7 @@ module Rails
# properly:
#
# assert_field_type :date, :date_select
+ #
def assert_field_type(attribute_type, field_type)
assert_equal(field_type, create_generated_attribute(attribute_type).field_type)
end
@@ -171,6 +182,7 @@ module Rails
# Asserts the given attribute type gets a proper default value:
#
# assert_field_default_value :string, "MyString"
+ #
def assert_field_default_value(attribute_type, value)
assert_equal(value, create_generated_attribute(attribute_type).default)
end
@@ -204,6 +216,7 @@ module Rails
# attribute type and, optionally, the attribute name:
#
# create_generated_attribute(:string, 'name')
+ #
def create_generated_attribute(attribute_type, name = 'test', index = nil)
Rails::Generators::GeneratedAttribute.parse([name, attribute_type, index].compact.join(':'))
end