def copyf(name, src, dest, *args) args || args = [] args.insert 0, name body = proc { FileList[src].each do |f| puts " - copying %s to %s" % [File.basename(f), dest] FileUtils.mkpath(File.dirname(dest)) unless File.directory?(File.dirname(dest)) FileUtils.cp f, dest end } Rake::Task.define_task(*args, &body) end assets = File.join(File.dirname(__FILE__), '..','app','assets') destination = File.join(Rails.root.to_path,'app', 'assets') copyf(:copy_images, File.join(assets,"images",'aslon_scaffold',"*.*"), File.join(destination,"images",'aslon_scaffold/') ) copyf(:copy_stylesheets, File.join(assets,"stylesheets",'aslon_scaffold',"*.*"), File.join(destination,"stylesheets",'aslon_scaffold/') ) namespace :aslon_scaffold do desc "install assets" task :install_assets => [:copy_images,:copy_stylesheets ] desc "install" task :install => [ 'aslon_scaffold:install_images', 'aslon_scaffold:install_stylesheets', ] desc "Copies images,... to proper application directories" task :install_images do ASSETS = File.join(File.dirname(__FILE__), '..','app','assets') puts ASSETS Dir.glob("#{ASSETS}/*").each do |folder| folder_name = folder.gsub(/\/.+\//, '') destination = File.join(Rails.root.to_path, 'assets','aslon_scaffold',folder_name) FileUtils.mkpath(destination) unless File.directory?(destination) Dir[File.join(folder, '/*')].select { |a| File.file?(a) }.each do |asset| puts " - copying %s to %s" % [File.basename(asset), destination.gsub(/Rails.root/, '')] FileUtils.cp asset, destination end end puts " - done.3" end desc "Copies stylesheets to proper application directories" task :install_stylesheets do source = File.join(File.dirname(__FILE__), '..','assets','stylesheets','sass') destination = File.join(Rails.public_path, 'stylesheets','sass','aslon_scaffold') FileUtils.mkpath(destination) unless File.directory?(destination) %w(base.css.sass formtastic.css.sass formtastic_changes.css.sass table_coffee_with_milk.css.sass ).each do |filename| file_source =File.join(source, '/', filename) file_dest = File.join(destination, '/', filename) puts " - copying %s to %s" % [filename, destination.gsub(/Rails.root/, '')] FileUtils.cp file_source, file_dest end puts " - done.2" end desc "Copies template for scaffold" task :install_template_scaffold do source = File.join(File.dirname(__FILE__), '..','generators','templates','rails','scaffold_controller') destination = File.join(Rails.root, 'lib','templates','rails','scaffold_controller') FileUtils.mkpath(destination) unless File.directory?(destination) %w(controller.rb).each do |filename| file_source =File.join(source, '/', filename) file_dest = File.join(destination, '/', filename) puts " - copying %s to %s" % [filename, destination.gsub(/Rails.root/, '')] FileUtils.cp file_source, file_dest end puts " - done.1" end end