Skip to content
This repository
Browse code

Add a rake task to apply a template to an existing application.

Example : rake rails:template LOCATION=~/template.rb
  • Loading branch information...
commit f7f113610e7cdca8ef03e206f2cbeb8400cdfefa 1 parent 2dc5d12
Pratik authored December 07, 2008
2  railties/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *2.3.0 [Edge]*
2 2
 
  3
+* Add a rake task to apply a template to an existing application : rake rails:template LOCATION=~/template.rb [Pratik]
  4
+
3 5
 * Add "-m/--template" option to Rails generator to apply a template to the generated application. [Jeremy McAnally]
4 6
 
5 7
     This has been extracted from rg - http://github.com/jeremymcanally/rg
2  railties/lib/rails_generator/generators/applications/app/app_generator.rb
@@ -40,7 +40,7 @@ def manifest
40 40
 
41 41
   def after_generate
42 42
     if options[:template]
43  
-      Rails::TemplateRunner.new(@destination_root, options[:template])
  43
+      Rails::TemplateRunner.new(options[:template], @destination_root)
44 44
     end
45 45
   end
46 46
 
4  railties/lib/rails_generator/generators/applications/app/template_runner.rb
@@ -9,8 +9,8 @@ module Rails
9 9
   class TemplateRunner
10 10
     attr_reader :root
11 11
 
12  
-    def initialize(root, template) # :nodoc:
13  
-      @root = Dir.pwd + "/" + root
  12
+    def initialize(template, root = '') # :nodoc:
  13
+      @root = File.join(Dir.pwd, root)
14 14
 
15 15
       puts "applying template: #{template}"
16 16
 
6  railties/lib/tasks/framework.rake
@@ -80,6 +80,12 @@ namespace :rails do
80 80
   desc "Update both configs, scripts and public/javascripts from Rails"
81 81
   task :update => [ "update:scripts", "update:javascripts", "update:configs", "update:application_controller" ]
82 82
 
  83
+  desc "Applies the template supplied by LOCATION=/path/to/template"
  84
+  task :template do
  85
+    require 'rails_generator/generators/applications/app/template_runner'
  86
+    Rails::TemplateRunner.new(ENV["LOCATION"])
  87
+  end
  88
+
83 89
   namespace :update do
84 90
     desc "Add new scripts to the application script/ directory"
85 91
     task :scripts do

0 notes on commit f7f1136

Please sign in to comment.
Something went wrong with that request. Please try again.