2006-02-26 23:38:39 -05:00
|
|
|
namespace :rails do
|
2010-06-09 16:19:03 -04:00
|
|
|
desc "Update both configs and public/javascripts from Rails (or use just update:javascripts or update:configs)"
|
2009-07-16 05:17:19 -04:00
|
|
|
task :update => [ "update:configs", "update:javascripts", "update:scripts", "update:application_controller" ]
|
2005-11-07 13:09:31 -05:00
|
|
|
|
2008-12-06 21:40:23 -05:00
|
|
|
desc "Applies the template supplied by LOCATION=/path/to/template"
|
|
|
|
task :template do
|
2009-04-20 12:01:32 -04:00
|
|
|
template = ENV["LOCATION"]
|
|
|
|
template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
|
2009-07-16 05:17:19 -04:00
|
|
|
|
2010-01-16 14:35:39 -05:00
|
|
|
require 'rails/generators'
|
2010-03-23 09:20:43 -04:00
|
|
|
require 'rails/generators/rails/app/app_generator'
|
2010-01-16 14:35:39 -05:00
|
|
|
generator = Rails::Generators::AppGenerator.new [ Rails.root ], {}, :destination_root => Rails.root
|
2009-07-16 05:17:19 -04:00
|
|
|
generator.apply template, :verbose => false
|
2008-12-06 21:40:23 -05:00
|
|
|
end
|
|
|
|
|
2010-05-14 17:54:13 -04:00
|
|
|
namespace :templates do
|
2010-06-09 16:19:03 -04:00
|
|
|
# desc "Copy all the templates from rails to the application directory for customization. Already existing local copies will be overwritten"
|
2010-05-14 17:54:13 -04:00
|
|
|
task :copy do
|
|
|
|
generators_lib = File.expand_path("../../generators", __FILE__)
|
|
|
|
project_templates = "#{Rails.root}/lib/templates"
|
|
|
|
|
|
|
|
default_templates = { "erb" => %w{controller mailer scaffold},
|
2010-05-29 14:07:47 -04:00
|
|
|
"rails" => %w{controller helper scaffold_controller stylesheets} }
|
2010-05-14 17:54:13 -04:00
|
|
|
|
|
|
|
default_templates.each do |type, names|
|
|
|
|
local_template_type_dir = File.join(project_templates, type)
|
|
|
|
FileUtils.mkdir_p local_template_type_dir
|
|
|
|
|
|
|
|
names.each do |name|
|
|
|
|
dst_name = File.join(local_template_type_dir, name)
|
|
|
|
src_name = File.join(generators_lib, type, name, "templates")
|
|
|
|
FileUtils.cp_r src_name, dst_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-02-26 23:38:39 -05:00
|
|
|
namespace :update do
|
2009-07-16 05:17:19 -04:00
|
|
|
def invoke_from_app_generator(method)
|
2010-07-27 05:27:46 -04:00
|
|
|
app_generator.send(method)
|
2010-02-21 07:44:08 -05:00
|
|
|
end
|
2006-02-26 23:38:39 -05:00
|
|
|
|
2010-02-21 07:44:08 -05:00
|
|
|
def app_generator
|
|
|
|
@app_generator ||= begin
|
|
|
|
require 'rails/generators'
|
2010-03-23 09:20:43 -04:00
|
|
|
require 'rails/generators/rails/app/app_generator'
|
2010-02-21 07:44:08 -05:00
|
|
|
gen = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true },
|
|
|
|
:destination_root => Rails.root
|
2010-03-27 05:45:54 -04:00
|
|
|
File.exists?(Rails.root.join("config", "application.rb")) ?
|
|
|
|
gen.send(:app_const) : gen.send(:valid_app_const?)
|
2010-02-21 07:44:08 -05:00
|
|
|
gen
|
|
|
|
end
|
2005-11-07 13:09:31 -05:00
|
|
|
end
|
2006-04-07 14:21:52 -04:00
|
|
|
|
2010-06-09 16:19:03 -04:00
|
|
|
# desc "Update config/boot.rb from your current rails install"
|
2009-12-01 16:27:59 -05:00
|
|
|
task :configs do
|
|
|
|
invoke_from_app_generator :create_boot_file
|
2009-12-01 16:37:12 -05:00
|
|
|
invoke_from_app_generator :create_config_files
|
2009-12-01 16:27:59 -05:00
|
|
|
end
|
|
|
|
|
2010-06-09 16:19:03 -04:00
|
|
|
# desc "Update Prototype javascripts from your current rails install"
|
2009-07-16 05:17:19 -04:00
|
|
|
task :javascripts do
|
|
|
|
invoke_from_app_generator :create_prototype_files
|
|
|
|
end
|
|
|
|
|
2010-06-09 16:19:03 -04:00
|
|
|
# desc "Adds new scripts to the application script/ directory"
|
2009-07-16 05:17:19 -04:00
|
|
|
task :scripts do
|
|
|
|
invoke_from_app_generator :create_script_files
|
|
|
|
end
|
|
|
|
|
2010-06-09 16:19:03 -04:00
|
|
|
# desc "Rename application.rb to application_controller.rb"
|
2008-11-23 07:39:30 -05:00
|
|
|
task :application_controller do
|
2009-10-16 15:49:39 -04:00
|
|
|
old_style = Rails.root + '/app/controllers/application.rb'
|
|
|
|
new_style = Rails.root + '/app/controllers/application_controller.rb'
|
2008-11-23 07:39:30 -05:00
|
|
|
if File.exists?(old_style) && !File.exists?(new_style)
|
|
|
|
FileUtils.mv(old_style, new_style)
|
|
|
|
puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary"
|
|
|
|
end
|
|
|
|
end
|
2005-11-07 13:09:31 -05:00
|
|
|
end
|
2006-03-13 13:45:40 -05:00
|
|
|
end
|