public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Add a rake task to apply a template to an existing application.

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

Comments