2006-02-26 23:38:39 -05:00
|
|
|
namespace :rails do
|
2013-07-13 08:30:58 -04:00
|
|
|
desc "Update configs and some other initially generated files (or use just update:configs or update:bin)"
|
|
|
|
task update: [ "update:configs", "update:bin" ]
|
2005-11-07 13:09:31 -05:00
|
|
|
|
2011-07-23 05:07:25 -04:00
|
|
|
desc "Applies the template supplied by LOCATION=(/path/to/template) or URL"
|
2014-03-08 09:51:49 -05:00
|
|
|
task template: :environment do
|
2009-04-20 12:01:32 -04:00
|
|
|
template = ENV["LOCATION"]
|
2011-07-23 05:07:25 -04:00
|
|
|
raise "No LOCATION value given. Please set LOCATION either as path to a file or a URL" if template.blank?
|
2009-04-20 12:01:32 -04:00
|
|
|
template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
|
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'
|
2012-10-14 06:03:39 -04:00
|
|
|
generator = Rails::Generators::AppGenerator.new [Rails.root], {}, destination_root: Rails.root
|
2014-02-14 14:38:26 -05: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},
|
2012-06-09 03:45:18 -04:00
|
|
|
"rails" => %w{controller helper scaffold_controller assets} }
|
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
|
2015-05-27 19:48:24 -04:00
|
|
|
end
|
2010-05-14 17:54:13 -04:00
|
|
|
end
|
|
|
|
|
2006-02-26 23:38:39 -05:00
|
|
|
namespace :update do
|
2015-05-27 19:48:24 -04:00
|
|
|
class RailsUpdate
|
|
|
|
def self.invoke_from_app_generator(method)
|
2015-05-27 21:18:00 -04:00
|
|
|
app_generator.send(method)
|
2010-02-21 07:44:08 -05:00
|
|
|
end
|
2006-02-26 23:38:39 -05:00
|
|
|
|
2015-05-27 19:48:24 -04:00
|
|
|
def self.app_generator
|
|
|
|
@app_generator ||= begin
|
2015-05-27 21:18:00 -04:00
|
|
|
require 'rails/generators'
|
|
|
|
require 'rails/generators/rails/app/app_generator'
|
2016-02-04 09:10:23 -05:00
|
|
|
gen = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true, api: !!Rails.application.config.api_only },
|
2015-05-27 21:18:00 -04:00
|
|
|
destination_root: Rails.root
|
|
|
|
File.exist?(Rails.root.join("config", "application.rb")) ?
|
|
|
|
gen.send(:app_const) : gen.send(:valid_const?)
|
|
|
|
gen
|
|
|
|
end
|
2010-02-21 07:44:08 -05:00
|
|
|
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
|
2015-05-27 19:48:24 -04:00
|
|
|
RailsUpdate.invoke_from_app_generator :create_boot_file
|
|
|
|
RailsUpdate.invoke_from_app_generator :update_config_files
|
2009-12-01 16:27:59 -05:00
|
|
|
end
|
|
|
|
|
2013-01-06 18:13:47 -05:00
|
|
|
# desc "Adds new executables to the application bin/ directory"
|
|
|
|
task :bin do
|
2015-05-27 19:48:24 -04:00
|
|
|
RailsUpdate.invoke_from_app_generator :create_bin_files
|
2009-07-16 05:17:19 -04:00
|
|
|
end
|
2005-11-07 13:09:31 -05:00
|
|
|
end
|
2006-03-13 13:45:40 -05:00
|
|
|
end
|