mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-28 03:36:11 +01:00
Vendoring Rails 2.3.5
This commit is contained in:
parent
3e83d19299
commit
f8779795ce
943 changed files with 56503 additions and 61351 deletions
|
|
@ -154,6 +154,9 @@ module Rails
|
|||
File.join(destination_root, relative_destination)
|
||||
end
|
||||
|
||||
def after_generate
|
||||
end
|
||||
|
||||
protected
|
||||
# Convenience method for generator subclasses to record a manifest.
|
||||
def record
|
||||
|
|
@ -230,13 +233,13 @@ module Rails
|
|||
base_name, @class_path, @file_path, @class_nesting, @class_nesting_depth = extract_modules(@name)
|
||||
@class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name)
|
||||
@table_name = (!defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names) ? plural_name : singular_name
|
||||
@table_name.gsub! '/', '_'
|
||||
if @class_nesting.empty?
|
||||
@class_name = @class_name_without_nesting
|
||||
else
|
||||
@table_name = @class_nesting.underscore << "_" << @table_name
|
||||
@class_name = "#{@class_nesting}::#{@class_name_without_nesting}"
|
||||
end
|
||||
@table_name.gsub! '/', '_'
|
||||
end
|
||||
|
||||
# Extract modules from filesystem-style or ruby-style path:
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ module Rails
|
|||
# Replay action manifest. RewindBase subclass rewinds manifest.
|
||||
def invoke!
|
||||
manifest.replay(self)
|
||||
after_generate
|
||||
end
|
||||
|
||||
def dependency(generator_name, args, runtime_options = {})
|
||||
|
|
@ -181,15 +182,19 @@ HELP
|
|||
nesting = class_name.split('::')
|
||||
name = nesting.pop
|
||||
|
||||
# Hack to limit const_defined? to non-inherited on 1.9.
|
||||
extra = []
|
||||
extra << false unless Object.method(:const_defined?).arity == 1
|
||||
|
||||
# Extract the last Module in the nesting.
|
||||
last = nesting.inject(Object) { |last, nest|
|
||||
break unless last.const_defined?(nest)
|
||||
break unless last.const_defined?(nest, *extra)
|
||||
last.const_get(nest)
|
||||
}
|
||||
|
||||
# If the last Module exists, check whether the given
|
||||
# class exists and raise a collision if so.
|
||||
if last and last.const_defined?(name.camelize)
|
||||
if last and last.const_defined?(name.camelize, *extra)
|
||||
raise_class_collision(class_name)
|
||||
end
|
||||
end
|
||||
|
|
@ -293,7 +298,7 @@ HELP
|
|||
file(relative_source, relative_destination, template_options) do |file|
|
||||
# Evaluate any assignments in a temporary, throwaway binding.
|
||||
vars = template_options[:assigns] || {}
|
||||
b = binding
|
||||
b = template_options[:binding] || binding
|
||||
vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b }
|
||||
|
||||
# Render the source file with the temporary binding.
|
||||
|
|
|
|||
|
|
@ -1,113 +1,46 @@
|
|||
require 'rbconfig'
|
||||
require File.dirname(__FILE__) + '/template_runner'
|
||||
require 'digest/md5'
|
||||
require 'active_support/secure_random'
|
||||
|
||||
class AppGenerator < Rails::Generator::Base
|
||||
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
||||
Config::CONFIG['ruby_install_name'])
|
||||
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
||||
|
||||
DATABASES = %w(mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db)
|
||||
DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db )
|
||||
DEFAULT_DATABASE = 'sqlite3'
|
||||
|
||||
default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE),
|
||||
:shebang => DEFAULT_SHEBANG, :freeze => false
|
||||
mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.."
|
||||
default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE),
|
||||
:shebang => DEFAULT_SHEBANG, :with_dispatchers => false, :freeze => false
|
||||
|
||||
|
||||
def initialize(runtime_args, runtime_options = {})
|
||||
super
|
||||
|
||||
usage if args.empty?
|
||||
usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db]))
|
||||
|
||||
@destination_root = args.shift
|
||||
@app_name = File.basename(File.expand_path(@destination_root))
|
||||
end
|
||||
|
||||
def manifest
|
||||
# Use /usr/bin/env if no special shebang was specified
|
||||
script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
|
||||
dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
|
||||
|
||||
# duplicate CGI::Session#generate_unique_id
|
||||
md5 = Digest::MD5.new
|
||||
now = Time.now
|
||||
md5 << now.to_s
|
||||
md5 << String(now.usec)
|
||||
md5 << String(rand(0))
|
||||
md5 << String($$)
|
||||
md5 << @app_name
|
||||
|
||||
# Do our best to generate a secure secret key for CookieStore
|
||||
secret = ActiveSupport::SecureRandom.hex(64)
|
||||
|
||||
record do |m|
|
||||
# Root directory and all subdirectories.
|
||||
m.directory ''
|
||||
BASEDIRS.each { |path| m.directory path }
|
||||
create_directories(m)
|
||||
create_root_files(m)
|
||||
create_app_files(m)
|
||||
create_config_files(m)
|
||||
create_script_files(m)
|
||||
create_test_files(m)
|
||||
create_public_files(m)
|
||||
create_documentation_file(m)
|
||||
create_log_files(m)
|
||||
end
|
||||
end
|
||||
|
||||
# Root
|
||||
m.file "fresh_rakefile", "Rakefile"
|
||||
m.file "README", "README"
|
||||
|
||||
# Application
|
||||
m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name, :app_secret => md5.hexdigest }
|
||||
m.template "helpers/application_helper.rb", "app/helpers/application_helper.rb"
|
||||
m.template "helpers/test_helper.rb", "test/test_helper.rb"
|
||||
m.template "helpers/performance_test.rb", "test/performance/browsing_test.rb"
|
||||
|
||||
# database.yml and routes.rb
|
||||
m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => {
|
||||
:app_name => @app_name,
|
||||
:socket => options[:db] == "mysql" ? mysql_socket_location : nil
|
||||
}
|
||||
m.template "configs/routes.rb", "config/routes.rb"
|
||||
|
||||
# Initializers
|
||||
m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb"
|
||||
m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb"
|
||||
m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb"
|
||||
|
||||
# Locale
|
||||
m.template "configs/locales/en.yml", "config/locales/en.yml"
|
||||
|
||||
# Environments
|
||||
m.file "environments/boot.rb", "config/boot.rb"
|
||||
m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze], :app_name => @app_name, :app_secret => secret }
|
||||
m.file "environments/production.rb", "config/environments/production.rb"
|
||||
m.file "environments/development.rb", "config/environments/development.rb"
|
||||
m.file "environments/test.rb", "config/environments/test.rb"
|
||||
|
||||
# Scripts
|
||||
%w( about console dbconsole destroy generate performance/benchmarker performance/profiler performance/request process/reaper process/spawner process/inspector runner server plugin ).each do |file|
|
||||
m.file "bin/#{file}", "script/#{file}", script_options
|
||||
end
|
||||
|
||||
# Dispatches
|
||||
m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options
|
||||
m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options
|
||||
m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options
|
||||
|
||||
# HTML files
|
||||
%w(404 422 500 index).each do |file|
|
||||
m.template "html/#{file}.html", "public/#{file}.html"
|
||||
end
|
||||
|
||||
m.template "html/favicon.ico", "public/favicon.ico"
|
||||
m.template "html/robots.txt", "public/robots.txt"
|
||||
m.file "html/images/rails.png", "public/images/rails.png"
|
||||
|
||||
# Javascripts
|
||||
m.file "html/javascripts/prototype.js", "public/javascripts/prototype.js"
|
||||
m.file "html/javascripts/effects.js", "public/javascripts/effects.js"
|
||||
m.file "html/javascripts/dragdrop.js", "public/javascripts/dragdrop.js"
|
||||
m.file "html/javascripts/controls.js", "public/javascripts/controls.js"
|
||||
m.file "html/javascripts/application.js", "public/javascripts/application.js"
|
||||
|
||||
# Docs
|
||||
m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
|
||||
|
||||
# Logs
|
||||
%w(server production development test).each { |file|
|
||||
m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666
|
||||
}
|
||||
def after_generate
|
||||
if options[:template]
|
||||
Rails::TemplateRunner.new(options[:template], @destination_root)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -127,58 +60,204 @@ class AppGenerator < Rails::Generator::Base
|
|||
"Preconfigure for selected database (options: #{DATABASES.join('/')}).",
|
||||
"Default: #{DEFAULT_DATABASE}") { |v| options[:db] = v }
|
||||
|
||||
opt.on("-D", "--with-dispatchers",
|
||||
"Add CGI/FastCGI/mod_ruby dispatches code to generated application skeleton",
|
||||
"Default: false") { |v| options[:with_dispatchers] = v }
|
||||
|
||||
opt.on("-f", "--freeze",
|
||||
"Freeze Rails in vendor/rails from the gems generating the skeleton",
|
||||
"Default: false") { |v| options[:freeze] = v }
|
||||
|
||||
opt.on("-m", "--template=path", String,
|
||||
"Use an application template that lives at path (can be a filesystem path or URL).",
|
||||
"Default: (none)") { |v| options[:template] = v }
|
||||
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def create_directories(m)
|
||||
m.directory ''
|
||||
|
||||
# Intermediate directories are automatically created so don't sweat their absence here.
|
||||
%w(
|
||||
app/controllers
|
||||
app/helpers
|
||||
app/models
|
||||
app/views/layouts
|
||||
config/environments
|
||||
config/initializers
|
||||
config/locales
|
||||
db
|
||||
doc
|
||||
lib
|
||||
lib/tasks
|
||||
log
|
||||
public/images
|
||||
public/javascripts
|
||||
public/stylesheets
|
||||
script/performance
|
||||
test/fixtures
|
||||
test/functional
|
||||
test/integration
|
||||
test/performance
|
||||
test/unit
|
||||
vendor
|
||||
vendor/plugins
|
||||
tmp/sessions
|
||||
tmp/sockets
|
||||
tmp/cache
|
||||
tmp/pids
|
||||
).each { |path| m.directory(path) }
|
||||
end
|
||||
|
||||
def create_root_files(m)
|
||||
m.file "fresh_rakefile", "Rakefile"
|
||||
m.file "README", "README"
|
||||
end
|
||||
|
||||
def create_app_files(m)
|
||||
m.file "helpers/application_controller.rb", "app/controllers/application_controller.rb"
|
||||
m.file "helpers/application_helper.rb", "app/helpers/application_helper.rb"
|
||||
end
|
||||
|
||||
def create_config_files(m)
|
||||
create_database_configuration_file(m)
|
||||
create_routes_file(m)
|
||||
create_locale_file(m)
|
||||
create_seeds_file(m)
|
||||
create_initializer_files(m)
|
||||
create_environment_files(m)
|
||||
end
|
||||
|
||||
def create_documentation_file(m)
|
||||
m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
|
||||
end
|
||||
|
||||
def create_log_files(m)
|
||||
%w( server production development test ).each do |file|
|
||||
m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666
|
||||
end
|
||||
end
|
||||
|
||||
def create_public_files(m)
|
||||
create_dispatch_files(m)
|
||||
create_error_files(m)
|
||||
create_welcome_file(m)
|
||||
create_browser_convention_files(m)
|
||||
create_rails_image(m)
|
||||
create_javascript_files(m)
|
||||
end
|
||||
|
||||
def create_script_files(m)
|
||||
%w(
|
||||
about console dbconsole destroy generate runner server plugin
|
||||
performance/benchmarker performance/profiler
|
||||
).each do |file|
|
||||
m.file "bin/#{file}", "script/#{file}", {
|
||||
:chmod => 0755,
|
||||
:shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def create_test_files(m)
|
||||
m.file "helpers/test_helper.rb", "test/test_helper.rb"
|
||||
m.file "helpers/performance_test.rb", "test/performance/browsing_test.rb"
|
||||
end
|
||||
|
||||
|
||||
def create_database_configuration_file(m)
|
||||
m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => {
|
||||
:app_name => @app_name,
|
||||
:socket => options[:db] == "mysql" ? mysql_socket_location : nil }
|
||||
end
|
||||
|
||||
def create_routes_file(m)
|
||||
m.file "configs/routes.rb", "config/routes.rb"
|
||||
end
|
||||
|
||||
def create_seeds_file(m)
|
||||
m.file "configs/seeds.rb", "db/seeds.rb"
|
||||
end
|
||||
|
||||
def create_initializer_files(m)
|
||||
%w(
|
||||
backtrace_silencers
|
||||
inflections
|
||||
mime_types
|
||||
new_rails_defaults
|
||||
).each do |initializer|
|
||||
m.file "configs/initializers/#{initializer}.rb", "config/initializers/#{initializer}.rb"
|
||||
end
|
||||
|
||||
m.template "configs/initializers/session_store.rb", "config/initializers/session_store.rb",
|
||||
:assigns => { :app_name => @app_name, :app_secret => ActiveSupport::SecureRandom.hex(64) }
|
||||
end
|
||||
|
||||
def create_locale_file(m)
|
||||
m.file "configs/locales/en.yml", "config/locales/en.yml"
|
||||
end
|
||||
|
||||
def create_environment_files(m)
|
||||
m.template "environments/environment.rb", "config/environment.rb",
|
||||
:assigns => { :freeze => options[:freeze] }
|
||||
|
||||
m.file "environments/boot.rb", "config/boot.rb"
|
||||
m.file "environments/production.rb", "config/environments/production.rb"
|
||||
m.file "environments/development.rb", "config/environments/development.rb"
|
||||
m.file "environments/test.rb", "config/environments/test.rb"
|
||||
end
|
||||
|
||||
|
||||
def create_dispatch_files(m)
|
||||
if options[:with_dispatchers]
|
||||
dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
|
||||
|
||||
m.file "dispatches/config.ru", "config.ru"
|
||||
m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options
|
||||
m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options
|
||||
m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options
|
||||
end
|
||||
end
|
||||
|
||||
def create_error_files(m)
|
||||
%w( 404 422 500 ).each do |file|
|
||||
m.file "html/#{file}.html", "public/#{file}.html"
|
||||
end
|
||||
end
|
||||
|
||||
def create_welcome_file(m)
|
||||
m.file 'html/index.html', 'public/index.html'
|
||||
end
|
||||
|
||||
def create_browser_convention_files(m)
|
||||
m.file "html/favicon.ico", "public/favicon.ico"
|
||||
m.file "html/robots.txt", "public/robots.txt"
|
||||
end
|
||||
|
||||
def create_rails_image(m)
|
||||
m.file "html/images/rails.png", "public/images/rails.png"
|
||||
end
|
||||
|
||||
def create_javascript_files(m)
|
||||
%w( prototype effects dragdrop controls application ).each do |javascript|
|
||||
m.file "html/javascripts/#{javascript}.js", "public/javascripts/#{javascript}.js"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def mysql_socket_location
|
||||
MYSQL_SOCKET_LOCATIONS.find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
|
||||
[
|
||||
"/tmp/mysql.sock", # default
|
||||
"/var/run/mysqld/mysqld.sock", # debian/gentoo
|
||||
"/var/tmp/mysql.sock", # freebsd
|
||||
"/var/lib/mysql/mysql.sock", # fedora
|
||||
"/opt/local/lib/mysql/mysql.sock", # fedora
|
||||
"/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
|
||||
"/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
|
||||
"/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
|
||||
"/opt/lampp/var/mysql/mysql.sock" # xampp for linux
|
||||
].find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
|
||||
end
|
||||
|
||||
|
||||
# Installation skeleton. Intermediate directories are automatically
|
||||
# created so don't sweat their absence here.
|
||||
BASEDIRS = %w(
|
||||
app/controllers
|
||||
app/helpers
|
||||
app/models
|
||||
app/views/layouts
|
||||
config/environments
|
||||
config/initializers
|
||||
config/locales
|
||||
db
|
||||
doc
|
||||
lib
|
||||
lib/tasks
|
||||
log
|
||||
public/images
|
||||
public/javascripts
|
||||
public/stylesheets
|
||||
script/performance
|
||||
script/process
|
||||
test/fixtures
|
||||
test/functional
|
||||
test/integration
|
||||
test/performance
|
||||
test/unit
|
||||
vendor
|
||||
vendor/plugins
|
||||
tmp/sessions
|
||||
tmp/sockets
|
||||
tmp/cache
|
||||
tmp/pids
|
||||
)
|
||||
|
||||
MYSQL_SOCKET_LOCATIONS = [
|
||||
"/tmp/mysql.sock", # default
|
||||
"/var/run/mysqld/mysqld.sock", # debian/gentoo
|
||||
"/var/tmp/mysql.sock", # freebsd
|
||||
"/var/lib/mysql/mysql.sock", # fedora
|
||||
"/opt/local/lib/mysql/mysql.sock", # fedora
|
||||
"/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
|
||||
"/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
|
||||
"/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
|
||||
"/opt/lampp/var/mysql/mysql.sock" # xampp for linux
|
||||
]
|
||||
end
|
||||
end
|
||||
18
vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/git.rb
vendored
Normal file
18
vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/git.rb
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
STDOUT.sync = true
|
||||
|
||||
module Rails
|
||||
class Git < Scm
|
||||
def self.clone(repos, branch=nil)
|
||||
system "git clone #{repos}"
|
||||
|
||||
if branch
|
||||
system "cd #{repos.split('/').last}/"
|
||||
system "git checkout #{branch}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.run(command)
|
||||
system "git #{command}"
|
||||
end
|
||||
end
|
||||
end
|
||||
8
vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/scm.rb
vendored
Normal file
8
vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/scm.rb
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
module Rails
|
||||
class Scm
|
||||
private
|
||||
def self.hash_to_parameters(hash)
|
||||
hash.collect { |key, value| "--#{key} #{(value.kind_of?(String) ? value : "")}"}.join(" ")
|
||||
end
|
||||
end
|
||||
end
|
||||
7
vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/svn.rb
vendored
Normal file
7
vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/svn.rb
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
module Rails
|
||||
class Svn < Scm
|
||||
def self.checkout(repos, branch = nil)
|
||||
`svn checkout #{repos}/#{branch || "trunk"}`
|
||||
end
|
||||
end
|
||||
end
|
||||
401
vendor/rails/railties/lib/rails_generator/generators/applications/app/template_runner.rb
vendored
Normal file
401
vendor/rails/railties/lib/rails_generator/generators/applications/app/template_runner.rb
vendored
Normal file
|
|
@ -0,0 +1,401 @@
|
|||
require File.dirname(__FILE__) + '/scm/scm'
|
||||
require File.dirname(__FILE__) + '/scm/git'
|
||||
require File.dirname(__FILE__) + '/scm/svn'
|
||||
|
||||
require 'open-uri'
|
||||
require 'fileutils'
|
||||
|
||||
module Rails
|
||||
class TemplateRunner
|
||||
attr_reader :root
|
||||
attr_writer :logger
|
||||
|
||||
def initialize(template, root = '') # :nodoc:
|
||||
@root = File.expand_path(File.directory?(root) ? root : File.join(Dir.pwd, root))
|
||||
|
||||
log 'applying', "template: #{template}"
|
||||
|
||||
load_template(template)
|
||||
|
||||
log 'applied', "#{template}"
|
||||
end
|
||||
|
||||
def load_template(template)
|
||||
begin
|
||||
code = open(template).read
|
||||
in_root { self.instance_eval(code) }
|
||||
rescue LoadError, Errno::ENOENT => e
|
||||
raise "The template [#{template}] could not be loaded. Error: #{e}"
|
||||
end
|
||||
end
|
||||
|
||||
# Create a new file in the Rails project folder. Specify the
|
||||
# relative path from RAILS_ROOT. Data is the return value of a block
|
||||
# or a data string.
|
||||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# file("lib/fun_party.rb") do
|
||||
# hostname = ask("What is the virtual hostname I should use?")
|
||||
# "vhost.name = #{hostname}"
|
||||
# end
|
||||
#
|
||||
# file("config/apach.conf", "your apache config")
|
||||
#
|
||||
def file(filename, data = nil, log_action = true, &block)
|
||||
log 'file', filename if log_action
|
||||
dir, file = [File.dirname(filename), File.basename(filename)]
|
||||
|
||||
inside(dir) do
|
||||
File.open(file, "w") do |f|
|
||||
if block_given?
|
||||
f.write(block.call)
|
||||
else
|
||||
f.write(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Install a plugin. You must provide either a Subversion url or Git url.
|
||||
# For a Git-hosted plugin, you can specify if it should be added as a submodule instead of cloned.
|
||||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git'
|
||||
# plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git', :submodule => true
|
||||
# plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk'
|
||||
#
|
||||
def plugin(name, options)
|
||||
log 'plugin', name
|
||||
|
||||
if options[:git] && options[:submodule]
|
||||
in_root do
|
||||
Git.run("submodule add #{options[:git]} vendor/plugins/#{name}")
|
||||
end
|
||||
elsif options[:git] || options[:svn]
|
||||
in_root do
|
||||
run_ruby_script("script/plugin install #{options[:svn] || options[:git]}", false)
|
||||
end
|
||||
else
|
||||
log "! no git or svn provided for #{name}. skipping..."
|
||||
end
|
||||
end
|
||||
|
||||
# Adds an entry into config/environment.rb for the supplied gem :
|
||||
def gem(name, options = {})
|
||||
log 'gem', name
|
||||
env = options.delete(:env)
|
||||
|
||||
gems_code = "config.gem '#{name}'"
|
||||
|
||||
if options.any?
|
||||
opts = options.inject([]) {|result, h| result << [":#{h[0]} => #{h[1].inspect.gsub('"',"'")}"] }.sort.join(", ")
|
||||
gems_code << ", #{opts}"
|
||||
end
|
||||
|
||||
environment gems_code, :env => env
|
||||
end
|
||||
|
||||
# Adds a line inside the Initializer block for config/environment.rb. Used by #gem
|
||||
# If options :env is specified, the line is appended to the corresponding
|
||||
# file in config/environments/#{env}.rb
|
||||
def environment(data = nil, options = {}, &block)
|
||||
sentinel = 'Rails::Initializer.run do |config|'
|
||||
|
||||
data = block.call if !data && block_given?
|
||||
|
||||
in_root do
|
||||
if options[:env].nil?
|
||||
gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
||||
"#{match}\n " << data
|
||||
end
|
||||
else
|
||||
Array.wrap(options[:env]).each do|env|
|
||||
append_file "config/environments/#{env}.rb", "\n#{data}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Run a command in git.
|
||||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# git :init
|
||||
# git :add => "this.file that.rb"
|
||||
# git :add => "onefile.rb", :rm => "badfile.cxx"
|
||||
#
|
||||
def git(command = {})
|
||||
in_root do
|
||||
if command.is_a?(Symbol)
|
||||
log 'running', "git #{command}"
|
||||
Git.run(command.to_s)
|
||||
else
|
||||
command.each do |command, options|
|
||||
log 'running', "git #{command} #{options}"
|
||||
Git.run("#{command} #{options}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Create a new file in the vendor/ directory. Code can be specified
|
||||
# in a block or a data string can be given.
|
||||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# vendor("sekrit.rb") do
|
||||
# sekrit_salt = "#{Time.now}--#{3.years.ago}--#{rand}--"
|
||||
# "salt = '#{sekrit_salt}'"
|
||||
# end
|
||||
#
|
||||
# vendor("foreign.rb", "# Foreign code is fun")
|
||||
#
|
||||
def vendor(filename, data = nil, &block)
|
||||
log 'vendoring', filename
|
||||
file("vendor/#{filename}", data, false, &block)
|
||||
end
|
||||
|
||||
# Create a new file in the lib/ directory. Code can be specified
|
||||
# in a block or a data string can be given.
|
||||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# lib("crypto.rb") do
|
||||
# "crypted_special_value = '#{rand}--#{Time.now}--#{rand(1337)}--'"
|
||||
# end
|
||||
#
|
||||
# lib("foreign.rb", "# Foreign code is fun")
|
||||
#
|
||||
def lib(filename, data = nil, &block)
|
||||
log 'lib', filename
|
||||
file("lib/#{filename}", data, false, &block)
|
||||
end
|
||||
|
||||
# Create a new Rakefile with the provided code (either in a block or a string).
|
||||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# rakefile("bootstrap.rake") do
|
||||
# project = ask("What is the UNIX name of your project?")
|
||||
#
|
||||
# <<-TASK
|
||||
# namespace :#{project} do
|
||||
# task :bootstrap do
|
||||
# puts "i like boots!"
|
||||
# end
|
||||
# end
|
||||
# TASK
|
||||
# end
|
||||
#
|
||||
# rakefile("seed.rake", "puts 'im plantin ur seedz'")
|
||||
#
|
||||
def rakefile(filename, data = nil, &block)
|
||||
log 'rakefile', filename
|
||||
file("lib/tasks/#{filename}", data, false, &block)
|
||||
end
|
||||
|
||||
# Create a new initializer with the provided code (either in a block or a string).
|
||||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# initializer("globals.rb") do
|
||||
# data = ""
|
||||
#
|
||||
# ['MY_WORK', 'ADMINS', 'BEST_COMPANY_EVAR'].each do
|
||||
# data << "#{const} = :entp"
|
||||
# end
|
||||
#
|
||||
# data
|
||||
# end
|
||||
#
|
||||
# initializer("api.rb", "API_KEY = '123456'")
|
||||
#
|
||||
def initializer(filename, data = nil, &block)
|
||||
log 'initializer', filename
|
||||
file("config/initializers/#{filename}", data, false, &block)
|
||||
end
|
||||
|
||||
# Generate something using a generator from Rails or a plugin.
|
||||
# The second parameter is the argument string that is passed to
|
||||
# the generator or an Array that is joined.
|
||||
#
|
||||
# ==== Example
|
||||
#
|
||||
# generate(:authenticated, "user session")
|
||||
#
|
||||
def generate(what, *args)
|
||||
log 'generating', what
|
||||
argument = args.map(&:to_s).flatten.join(" ")
|
||||
|
||||
in_root { run_ruby_script("script/generate #{what} #{argument}", false) }
|
||||
end
|
||||
|
||||
# Executes a command
|
||||
#
|
||||
# ==== Example
|
||||
#
|
||||
# inside('vendor') do
|
||||
# run('ln -s ~/edge rails')
|
||||
# end
|
||||
#
|
||||
def run(command, log_action = true)
|
||||
log 'executing', "#{command} from #{Dir.pwd}" if log_action
|
||||
`#{command}`
|
||||
end
|
||||
|
||||
# Executes a ruby script (taking into account WIN32 platform quirks)
|
||||
def run_ruby_script(command, log_action = true)
|
||||
ruby_command = RUBY_PLATFORM=~ /win32/ ? 'ruby ' : ''
|
||||
run("#{ruby_command}#{command}", log_action)
|
||||
end
|
||||
|
||||
# Runs the supplied rake task
|
||||
#
|
||||
# ==== Example
|
||||
#
|
||||
# rake("db:migrate")
|
||||
# rake("db:migrate", :env => "production")
|
||||
# rake("gems:install", :sudo => true)
|
||||
#
|
||||
def rake(command, options = {})
|
||||
log 'rake', command
|
||||
env = options[:env] || 'development'
|
||||
sudo = options[:sudo] ? 'sudo ' : ''
|
||||
in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", false) }
|
||||
end
|
||||
|
||||
# Just run the capify command in root
|
||||
#
|
||||
# ==== Example
|
||||
#
|
||||
# capify!
|
||||
#
|
||||
def capify!
|
||||
log 'capifying'
|
||||
in_root { run('capify .', false) }
|
||||
end
|
||||
|
||||
# Add Rails to /vendor/rails
|
||||
#
|
||||
# ==== Example
|
||||
#
|
||||
# freeze!
|
||||
#
|
||||
def freeze!(args = {})
|
||||
log 'vendor', 'rails edge'
|
||||
in_root { run('rake rails:freeze:edge', false) }
|
||||
end
|
||||
|
||||
# Make an entry in Rails routing file conifg/routes.rb
|
||||
#
|
||||
# === Example
|
||||
#
|
||||
# route "map.root :controller => :welcome"
|
||||
#
|
||||
def route(routing_code)
|
||||
log 'route', routing_code
|
||||
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
||||
|
||||
in_root do
|
||||
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
||||
"#{match}\n #{routing_code}\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Get a user's input
|
||||
#
|
||||
# ==== Example
|
||||
#
|
||||
# answer = ask("Should I freeze the latest Rails?")
|
||||
# freeze! if ask("Should I freeze the latest Rails?") == "yes"
|
||||
#
|
||||
def ask(string)
|
||||
log '', string
|
||||
STDIN.gets.strip
|
||||
end
|
||||
|
||||
# Do something in the root of the Rails application or
|
||||
# a provided subfolder; the full path is yielded to the block you provide.
|
||||
# The path is set back to the previous path when the method exits.
|
||||
def inside(dir = '', &block)
|
||||
folder = File.join(root, dir)
|
||||
FileUtils.mkdir_p(folder) unless File.exist?(folder)
|
||||
FileUtils.cd(folder) { block.arity == 1 ? yield(folder) : yield }
|
||||
end
|
||||
|
||||
def in_root
|
||||
FileUtils.cd(root) { yield }
|
||||
end
|
||||
|
||||
# Helper to test if the user says yes(y)?
|
||||
#
|
||||
# ==== Example
|
||||
#
|
||||
# freeze! if yes?("Should I freeze the latest Rails?")
|
||||
#
|
||||
def yes?(question)
|
||||
answer = ask(question).downcase
|
||||
answer == "y" || answer == "yes"
|
||||
end
|
||||
|
||||
# Helper to test if the user does NOT say yes(y)?
|
||||
#
|
||||
# ==== Example
|
||||
#
|
||||
# capify! if no?("Will you be using vlad to deploy your application?")
|
||||
#
|
||||
def no?(question)
|
||||
!yes?(question)
|
||||
end
|
||||
|
||||
# Run a regular expression replacement on a file
|
||||
#
|
||||
# ==== Example
|
||||
#
|
||||
# gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
|
||||
#
|
||||
def gsub_file(relative_destination, regexp, *args, &block)
|
||||
path = destination_path(relative_destination)
|
||||
content = File.read(path).gsub(regexp, *args, &block)
|
||||
File.open(path, 'wb') { |file| file.write(content) }
|
||||
end
|
||||
|
||||
# Append text to a file
|
||||
#
|
||||
# ==== Example
|
||||
#
|
||||
# append_file 'config/environments/test.rb', 'config.gem "rspec"'
|
||||
#
|
||||
def append_file(relative_destination, data)
|
||||
path = destination_path(relative_destination)
|
||||
File.open(path, 'ab') { |file| file.write(data) }
|
||||
end
|
||||
|
||||
def destination_path(relative_destination)
|
||||
File.join(root, relative_destination)
|
||||
end
|
||||
|
||||
def log(action, message = '')
|
||||
logger.log(action, message)
|
||||
end
|
||||
|
||||
def logger
|
||||
@logger ||= Rails::Generator::Base.logger
|
||||
end
|
||||
|
||||
def logger
|
||||
@logger ||= if defined?(Rails::Generator::Base)
|
||||
Rails::Generator::Base.logger
|
||||
else
|
||||
require 'rails_generator/simple_logger'
|
||||
Rails::Generator::SimpleLogger.new(STDOUT)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -6,24 +6,25 @@ Description:
|
|||
path like 'parent_module/controller_name'.
|
||||
|
||||
This generates a controller class in app/controllers, view templates in
|
||||
app/views/controller_name, a helper class in app/helpers, and a functional
|
||||
test suite in test/functional.
|
||||
app/views/controller_name, a helper class in app/helpers, a functional
|
||||
test suite in test/functional and a helper test suite in test/unit/helpers.
|
||||
|
||||
Example:
|
||||
`./script/generate controller CreditCard open debit credit close`
|
||||
|
||||
Credit card controller with URLs like /credit_card/debit.
|
||||
Controller: app/controllers/credit_card_controller.rb
|
||||
Views: app/views/credit_card/debit.html.erb [...]
|
||||
Helper: app/helpers/credit_card_helper.rb
|
||||
Test: test/functional/credit_card_controller_test.rb
|
||||
Controller: app/controllers/credit_card_controller.rb
|
||||
Functional Test: test/functional/credit_card_controller_test.rb
|
||||
Views: app/views/credit_card/debit.html.erb [...]
|
||||
Helper: app/helpers/credit_card_helper.rb
|
||||
Helper Test: test/unit/helpers/credit_card_helper_test.rb
|
||||
|
||||
Modules Example:
|
||||
`./script/generate controller 'admin/credit_card' suspend late_fee`
|
||||
|
||||
Credit card admin controller with URLs /admin/credit_card/suspend.
|
||||
Controller: app/controllers/admin/credit_card_controller.rb
|
||||
Views: app/views/admin/credit_card/debit.html.erb [...]
|
||||
Helper: app/helpers/admin/credit_card_helper.rb
|
||||
Test: test/functional/admin/credit_card_controller_test.rb
|
||||
|
||||
Controller: app/controllers/admin/credit_card_controller.rb
|
||||
Functional Test: test/functional/admin/credit_card_controller_test.rb
|
||||
Views: app/views/admin/credit_card/debit.html.erb [...]
|
||||
Helper: app/helpers/admin/credit_card_helper.rb
|
||||
Helper Test: test/unit/helpers/admin/credit_card_helper_test.rb
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ class ControllerGenerator < Rails::Generator::NamedBase
|
|||
def manifest
|
||||
record do |m|
|
||||
# Check for class naming collisions.
|
||||
m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"
|
||||
m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper", "#{class_name}HelperTest"
|
||||
|
||||
# Controller, helper, views, and test directories.
|
||||
m.directory File.join('app/controllers', class_path)
|
||||
m.directory File.join('app/helpers', class_path)
|
||||
m.directory File.join('app/views', class_path, file_name)
|
||||
m.directory File.join('test/functional', class_path)
|
||||
m.directory File.join('test/unit/helpers', class_path)
|
||||
|
||||
# Controller class, functional test, and helper class.
|
||||
m.template 'controller.rb',
|
||||
|
|
@ -26,6 +27,11 @@ class ControllerGenerator < Rails::Generator::NamedBase
|
|||
class_path,
|
||||
"#{file_name}_helper.rb")
|
||||
|
||||
m.template 'helper_test.rb',
|
||||
File.join('test/unit/helpers',
|
||||
class_path,
|
||||
"#{file_name}_helper_test.rb")
|
||||
|
||||
# View template for each action.
|
||||
actions.each do |action|
|
||||
path = File.join('app/views', class_path, file_name, "#{action}.html.erb")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class <%= class_name %>HelperTest < ActionView::TestCase
|
||||
end
|
||||
24
vendor/rails/railties/lib/rails_generator/generators/components/helper/USAGE
vendored
Normal file
24
vendor/rails/railties/lib/rails_generator/generators/components/helper/USAGE
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Description:
|
||||
Stubs out a new helper. Pass the helper name, either
|
||||
CamelCased or under_scored.
|
||||
|
||||
To create a helper within a module, specify the helper name as a
|
||||
path like 'parent_module/helper_name'.
|
||||
|
||||
This generates a helper class in app/helpers and a helper test
|
||||
suite in test/unit/helpers.
|
||||
|
||||
Example:
|
||||
`./script/generate helper CreditCard`
|
||||
|
||||
Credit card helper.
|
||||
Helper: app/helpers/credit_card_helper.rb
|
||||
Test: test/unit/helpers/credit_card_helper_test.rb
|
||||
|
||||
Modules Example:
|
||||
`./script/generate helper 'admin/credit_card'`
|
||||
|
||||
Credit card admin helper.
|
||||
Helper: app/helpers/admin/credit_card_helper.rb
|
||||
Test: test/unit/helpers/admin/credit_card_helper_test.rb
|
||||
|
||||
25
vendor/rails/railties/lib/rails_generator/generators/components/helper/helper_generator.rb
vendored
Normal file
25
vendor/rails/railties/lib/rails_generator/generators/components/helper/helper_generator.rb
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
class HelperGenerator < Rails::Generator::NamedBase
|
||||
def manifest
|
||||
record do |m|
|
||||
# Check for class naming collisions.
|
||||
m.class_collisions class_path, "#{class_name}Helper", "#{class_name}HelperTest"
|
||||
|
||||
# Helper and helper test directories.
|
||||
m.directory File.join('app/helpers', class_path)
|
||||
m.directory File.join('test/unit/helpers', class_path)
|
||||
|
||||
# Helper and helper test class.
|
||||
|
||||
m.template 'helper.rb',
|
||||
File.join('app/helpers',
|
||||
class_path,
|
||||
"#{file_name}_helper.rb")
|
||||
|
||||
m.template 'helper_test.rb',
|
||||
File.join('test/unit/helpers',
|
||||
class_path,
|
||||
"#{file_name}_helper_test.rb")
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
2
vendor/rails/railties/lib/rails_generator/generators/components/helper/templates/helper.rb
vendored
Normal file
2
vendor/rails/railties/lib/rails_generator/generators/components/helper/templates/helper.rb
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module <%= class_name %>Helper
|
||||
end
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class <%= class_name %>HelperTest < ActionView::TestCase
|
||||
end
|
||||
8
vendor/rails/railties/lib/rails_generator/generators/components/metal/USAGE
vendored
Normal file
8
vendor/rails/railties/lib/rails_generator/generators/components/metal/USAGE
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Description:
|
||||
Cast some metal!
|
||||
|
||||
Examples:
|
||||
`./script/generate metal poller`
|
||||
|
||||
This will create:
|
||||
Metal: app/metal/poller.rb
|
||||
8
vendor/rails/railties/lib/rails_generator/generators/components/metal/metal_generator.rb
vendored
Normal file
8
vendor/rails/railties/lib/rails_generator/generators/components/metal/metal_generator.rb
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class MetalGenerator < Rails::Generator::NamedBase
|
||||
def manifest
|
||||
record do |m|
|
||||
m.directory 'app/metal'
|
||||
m.template 'metal.rb', File.join('app/metal', "#{file_name}.rb")
|
||||
end
|
||||
end
|
||||
end
|
||||
12
vendor/rails/railties/lib/rails_generator/generators/components/metal/templates/metal.rb
vendored
Normal file
12
vendor/rails/railties/lib/rails_generator/generators/components/metal/templates/metal.rb
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Allow the metal piece to run in isolation
|
||||
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
|
||||
|
||||
class <%= class_name %>
|
||||
def self.call(env)
|
||||
if env["PATH_INFO"] =~ /^\/<%= file_name %>/
|
||||
[200, {"Content-Type" => "text/html"}, ["Hello, World!"]]
|
||||
else
|
||||
[404, {"Content-Type" => "text/html"}, ["Not Found"]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -19,10 +19,17 @@ class ModelGenerator < Rails::Generator::NamedBase
|
|||
m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
|
||||
end
|
||||
|
||||
migration_file_path = file_path.gsub(/\//, '_')
|
||||
migration_name = class_name
|
||||
if ActiveRecord::Base.pluralize_table_names
|
||||
migration_name = migration_name.pluralize
|
||||
migration_file_path = migration_file_path.pluralize
|
||||
end
|
||||
|
||||
unless options[:skip_migration]
|
||||
m.migration_template 'migration.rb', 'db/migrate', :assigns => {
|
||||
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
||||
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
||||
:migration_name => "Create#{migration_name.gsub(/::/, '')}"
|
||||
}, :migration_file_name => "create_#{migration_file_path}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ Description:
|
|||
You don't have to think up every attribute up front, but it helps to
|
||||
sketch out a few so you can start working with the resource immediately.
|
||||
|
||||
This creates a model, controller, tests and fixtures for both, and the
|
||||
corresponding map.resources declaration in config/routes.rb
|
||||
This creates a model, controller, helper, tests and fixtures for all of them,
|
||||
and the corresponding map.resources declaration in config/routes.rb
|
||||
|
||||
Unlike the scaffold generator, the resource generator does not create
|
||||
views or add any methods to the generated controller.
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ class ResourceGenerator < Rails::Generator::NamedBase
|
|||
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
||||
m.directory(File.join('test/functional', controller_class_path))
|
||||
m.directory(File.join('test/unit', class_path))
|
||||
m.directory(File.join('test/unit/helpers', class_path))
|
||||
|
||||
m.dependency 'model', [name] + @args, :collision => :skip
|
||||
|
||||
|
|
@ -49,6 +50,7 @@ class ResourceGenerator < Rails::Generator::NamedBase
|
|||
|
||||
m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
||||
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
||||
m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb"))
|
||||
|
||||
m.route_resources controller_file_name
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class <%= controller_class_name %>HelperTest < ActionView::TestCase
|
||||
end
|
||||
|
|
@ -19,6 +19,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase
|
|||
if @name == @name.pluralize && !options[:force_plural]
|
||||
logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural."
|
||||
@name = @name.singularize
|
||||
assign_names!(@name)
|
||||
end
|
||||
|
||||
@controller_name = @name.pluralize
|
||||
|
|
@ -47,6 +48,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase
|
|||
m.directory(File.join('app/views/layouts', controller_class_path))
|
||||
m.directory(File.join('test/functional', controller_class_path))
|
||||
m.directory(File.join('test/unit', class_path))
|
||||
m.directory(File.join('test/unit/helpers', class_path))
|
||||
m.directory(File.join('public/stylesheets', class_path))
|
||||
|
||||
for action in scaffold_views
|
||||
|
|
@ -66,6 +68,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase
|
|||
|
||||
m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
||||
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
||||
m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb"))
|
||||
|
||||
m.route_resources controller_file_name
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|||
# GET /<%= table_name %>
|
||||
# GET /<%= table_name %>.xml
|
||||
def index
|
||||
@<%= table_name %> = <%= class_name %>.find(:all)
|
||||
@<%= table_name %> = <%= class_name %>.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
|
|
|
|||
|
|
@ -21,23 +21,23 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
test "should show <%= file_name %>" do
|
||||
get :show, :id => <%= table_name %>(:one).id
|
||||
get :show, :id => <%= table_name %>(:one).to_param
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get :edit, :id => <%= table_name %>(:one).id
|
||||
get :edit, :id => <%= table_name %>(:one).to_param
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update <%= file_name %>" do
|
||||
put :update, :id => <%= table_name %>(:one).id, :<%= file_name %> => { }
|
||||
put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
|
||||
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
|
||||
end
|
||||
|
||||
test "should destroy <%= file_name %>" do
|
||||
assert_difference('<%= class_name %>.count', -1) do
|
||||
delete :destroy, :id => <%= table_name %>(:one).id
|
||||
delete :destroy, :id => <%= table_name %>(:one).to_param
|
||||
end
|
||||
|
||||
assert_redirected_to <%= table_name %>_path
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class <%= controller_class_name %>HelperTest < ActionView::TestCase
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<p style="color: green"><%%= flash[:notice] %></p>
|
||||
|
||||
<%%= yield %>
|
||||
<%%= yield %>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
</p>
|
||||
<% end -%>
|
||||
<p>
|
||||
<%%= f.submit "Update" %>
|
||||
<%%= f.submit 'Update' %>
|
||||
</p>
|
||||
<%% end %>
|
||||
|
||||
<%%= link_to 'Show', @<%= singular_name %> %> |
|
||||
<%%= link_to 'Back', <%= plural_name %>_path %>
|
||||
<%%= link_to 'Back', <%= plural_name %>_path %>
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
<% end -%>
|
||||
</tr>
|
||||
|
||||
<%% for <%= singular_name %> in @<%= plural_name %> %>
|
||||
<%% @<%= plural_name %>.each do |<%= singular_name %>| %>
|
||||
<tr>
|
||||
<% for attribute in attributes -%>
|
||||
<td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
|
||||
|
|
@ -21,4 +21,4 @@
|
|||
|
||||
<br />
|
||||
|
||||
<%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
|
||||
<%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
|
||||
|
|
@ -10,8 +10,8 @@
|
|||
</p>
|
||||
<% end -%>
|
||||
<p>
|
||||
<%%= f.submit "Create" %>
|
||||
<%%= f.submit 'Create' %>
|
||||
</p>
|
||||
<%% end %>
|
||||
|
||||
<%%= link_to 'Back', <%= plural_name %>_path %>
|
||||
<%%= link_to 'Back', <%= plural_name %>_path %>
|
||||
|
|
@ -7,4 +7,4 @@
|
|||
<% end -%>
|
||||
|
||||
<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
|
||||
<%%= link_to 'Back', <%= plural_name %>_path %>
|
||||
<%%= link_to 'Back', <%= plural_name %>_path %>
|
||||
|
|
@ -131,16 +131,16 @@ module Rails
|
|||
opt.on('-q', '--quiet', 'Suppress normal output.') { |v| options[:quiet] = v }
|
||||
opt.on('-t', '--backtrace', 'Debugging: show backtrace on errors.') { |v| options[:backtrace] = v }
|
||||
opt.on('-c', '--svn', 'Modify files with subversion. (Note: svn must be in path)') do
|
||||
options[:svn] = `svn status`.inject({}) do |opt, e|
|
||||
opt[e.chomp[7..-1]] = true
|
||||
opt
|
||||
options[:svn] = {}
|
||||
`svn status`.each_line do |line|
|
||||
options[:svn][line.chomp[7..-1]] = true
|
||||
end
|
||||
end
|
||||
opt.on('-g', '--git', 'Modify files with git. (Note: git must be in path)') do
|
||||
options[:git] = `git status`.inject({:new => {}, :modified => {}}) do |opt, e|
|
||||
opt[:new][e.chomp[14..-1]] = true if e =~ /new file:/
|
||||
opt[:modified][e.chomp[14..-1]] = true if e =~ /modified:/
|
||||
opt
|
||||
options[:git] = {:new => {}, :modified => {}}
|
||||
`git status`.each_line do |line|
|
||||
options[:git][:new][line.chomp[14..-1]] = true if line =~ /new file:/
|
||||
options[:git][:modified][line.chomp[14..-1]] = true if line =~ /modified:/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
require 'active_support/deprecation'
|
||||
|
||||
module Rails
|
||||
# A class for creating random secret keys. This class will do its best to create a
|
||||
# random secret key that's as secure as possible, using whatever methods are
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue