From f3014d6386b9c57cc5385364dfff6a7a9bddfd89 Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Mon, 10 May 2010 22:05:15 -0300 Subject: [PATCH 1/3] Rake task to copy the default templates for personalization [#4574 state:closed] --- railties/lib/rails/tasks/generator_templates.rake | 26 +++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) create mode 100644 railties/lib/rails/tasks/generator_templates.rake diff --git a/railties/lib/rails/tasks/generator_templates.rake b/railties/lib/rails/tasks/generator_templates.rake new file mode 100644 index 0000000..2fcd44d --- /dev/null +++ b/railties/lib/rails/tasks/generator_templates.rake @@ -0,0 +1,26 @@ +namespace :templates do + desc "Copy all the templates from rails to the application directory for customization, the local copy of the templates will be in RAILS_ROOT/lib/templates" + task :copy do + require 'rubygems' + require 'rubygems/gem_runner' + require 'fileutils' + railties = (version = ENV['VERSION']) ? + Gem.cache.find_name('railties', "= #{version}").first : + Gem.cache.find_name('railties').sort_by { |g| g.version }.last + base_path = railties.full_gem_path + FileUtils.mkdir_p "#{Rails.root}/lib/templates/" + default_dirs = {:erb => %w{controller mailer scaffold}, :rails => %w{controller helper mailer metal scaffold_controller stylesheets}} + default_dirs.each do |type,names| + FileUtils.mkdir_p "#{Rails.root}/lib/templates/#{type.to_s}" + names.each do |name| + dst_name = "#{Rails.root}/lib/templates/#{type.to_s}/#{name}" + FileUtils.mkdir_p dst_name + src_name = "#{base_path}/lib/rails/generators/#{type.to_s}/#{name}/templates" + src = Dir.new src_name + src.entries.each do |fname| + FileUtils.cp "#{src_name}/#{fname}", "#{dst_name}" unless fname =~ /^\..*/ + end + end + end + end +end -- 1.7.0.2.msysgit.0 From 42e48f2a7c53db6a6736d081831397aa6245ab10 Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Tue, 11 May 2010 12:21:25 -0300 Subject: [PATCH 2/3] implementing suggested changes from josevalim --- railties/lib/rails/tasks.rb | 1 + railties/lib/rails/tasks/generator_templates.rake | 29 +++++++++----------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb index 9807000..89d6e69 100644 --- a/railties/lib/rails/tasks.rb +++ b/railties/lib/rails/tasks.rb @@ -5,6 +5,7 @@ $VERBOSE = nil annotations documentation framework + generator_templates log middleware misc diff --git a/railties/lib/rails/tasks/generator_templates.rake b/railties/lib/rails/tasks/generator_templates.rake index 2fcd44d..eaa5c37 100644 --- a/railties/lib/rails/tasks/generator_templates.rake +++ b/railties/lib/rails/tasks/generator_templates.rake @@ -1,26 +1,23 @@ namespace :templates do - desc "Copy all the templates from rails to the application directory for customization, the local copy of the templates will be in RAILS_ROOT/lib/templates" + desc "Copy all the templates from rails to the application directory for customization. Already existing local copies will be overwritten" task :copy do - require 'rubygems' - require 'rubygems/gem_runner' - require 'fileutils' - railties = (version = ENV['VERSION']) ? - Gem.cache.find_name('railties', "= #{version}").first : - Gem.cache.find_name('railties').sort_by { |g| g.version }.last - base_path = railties.full_gem_path - FileUtils.mkdir_p "#{Rails.root}/lib/templates/" - default_dirs = {:erb => %w{controller mailer scaffold}, :rails => %w{controller helper mailer metal scaffold_controller stylesheets}} - default_dirs.each do |type,names| - FileUtils.mkdir_p "#{Rails.root}/lib/templates/#{type.to_s}" + railties_lib = "#{File.dirname(__FILE__)}/.." + project_templates = "#{Rails.root}/lib/templates/" + FileUtils.mkdir_p project_templates + default_templates = {:erb => %w{controller mailer scaffold}, :rails => %w{controller helper mailer metal scaffold_controller stylesheets}} + default_templates.each do |type,names| + local_template_type_dir = "#{project_templates}/#{type.to_s}" + FileUtils.mkdir_p local_template_type_dir names.each do |name| - dst_name = "#{Rails.root}/lib/templates/#{type.to_s}/#{name}" + dst_name = "#{local_template_type_dir}/#{name}" FileUtils.mkdir_p dst_name - src_name = "#{base_path}/lib/rails/generators/#{type.to_s}/#{name}/templates" + src_name = "#{railties_lib}/generators/#{type.to_s}/#{name}/templates" src = Dir.new src_name src.entries.each do |fname| - FileUtils.cp "#{src_name}/#{fname}", "#{dst_name}" unless fname =~ /^\..*/ + FileUtils.cp_r "#{src_name}/#{fname}", "#{dst_name}" unless fname =~ /^\..*/ end end end - end + end end + -- 1.7.0.2.msysgit.0 From 6d23af3f6120d3bf126d1b24c060303b54d42235 Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Tue, 11 May 2010 12:30:23 -0300 Subject: [PATCH 3/3] simplify file copy [#4574 state:closed] --- railties/lib/rails/tasks/generator_templates.rake | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-) diff --git a/railties/lib/rails/tasks/generator_templates.rake b/railties/lib/rails/tasks/generator_templates.rake index eaa5c37..48879e3 100644 --- a/railties/lib/rails/tasks/generator_templates.rake +++ b/railties/lib/rails/tasks/generator_templates.rake @@ -11,11 +11,8 @@ namespace :templates do names.each do |name| dst_name = "#{local_template_type_dir}/#{name}" FileUtils.mkdir_p dst_name - src_name = "#{railties_lib}/generators/#{type.to_s}/#{name}/templates" - src = Dir.new src_name - src.entries.each do |fname| - FileUtils.cp_r "#{src_name}/#{fname}", "#{dst_name}" unless fname =~ /^\..*/ - end + src_name = "#{railties_lib}/generators/#{type.to_s}/#{name}/templates/." + FileUtils.cp_r "#{src_name}", "#{dst_name}" end end end -- 1.7.0.2.msysgit.0