public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Add "-m/--template" option to Rails generator to apply template to generated 
application.

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Tue Dec 02 08:22:27 -0800 2008
lifo (committer)
Tue Dec 02 10:39:11 -0800 2008
commit  e8cc4b116c460c524961a07da92da3f323854c15
tree    aac0dee8ad4b1ebcf2f1e71f4cd963c1123003ce
parent  2014d9141aaa8e40a030875de35570b1061b7c2f
...
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
0
@@ -1,5 +1,48 @@
0
 *2.3.0 [Edge]*
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
0
+    
0
+    Example:
0
+    
0
+        # template.rb
0
+        
0
+        # Install plugins from git or svn
0
+        plugin "will-paginate", :git => "git://github.com/mislav/will_paginate.git"
0
+        plugin "old-restful-auth", :svn => "http://svn.techno-weenie.net/projects/plugins/restful_authentication/"
0
+    
0
+        # Add gems to environment.rb
0
+        gem "jeremymcanally-context"
0
+        gem "bluecloth"
0
+    
0
+        # Vendor file. Data in a string or...
0
+        vendor("borrowed.rb", <<CODE
0
+          def helpful_method
0
+            do_something_helpful_here
0
+          end
0
+        CODE
0
+    
0
+        # ...file data from block return value.
0
+        # #initializer creates a new initializer file
0
+        initializer("crypto.rb") do
0
+          salt = "--#{Time.now}--#{rand}--#{srand(Time.now.to_i)}"
0
+    
0
+          "SPECIAL_SALT = '#{salt}'"
0
+        end
0
+    
0
+    Usage:
0
+    
0
+      To use a template, provide a file path or URL:
0
+    
0
+      1. Using a local file :
0
+
0
+        rails <application name> -m /path/to/my/template.rb
0
+        
0
+      2. Or directly from a URL :
0
+
0
+        rails <application name> --template=http://gist.github.com/31208.txt
0
+
0
 * Extracted the process scripts (inspector, reaper, spawner) into the plugin irs_process_scripts [DHH]
0
 
0
 * Changed Rails.root to return a Pathname object (allows for Rails.root.join('app', 'controllers') => "#{RAILS_ROOT}/app/controllers") #1482 [Damian Janowski/?]
...
8
9
10
 
11
12
13
...
8
9
10
11
12
13
14
0
@@ -8,6 +8,7 @@ if %w(--version -v).include? ARGV.first
0
 end
0
 
0
 freeze   = ARGV.any? { |option| %w(--freeze -f).include?(option) }
3
+
0
 app_path = ARGV.first
0
 
0
 require File.dirname(__FILE__) + '/../lib/rails_generator'
...
154
155
156
 
 
 
157
158
159
...
154
155
156
157
158
159
160
161
162
0
@@ -154,6 +154,9 @@ module Rails
0
         File.join(destination_root, relative_destination)
0
       end
0
 
0
+      def after_generate
0
+      end
0
+
0
       protected
0
         # Convenience method for generator subclasses to record a manifest.
0
         def record
...
40
41
42
 
43
44
45
...
40
41
42
43
44
45
46
0
@@ -40,6 +40,7 @@ module Rails
0
         # Replay action manifest.  RewindBase subclass rewinds manifest.
0
         def invoke!
0
           manifest.replay(self)
0
+          after_generate
0
         end
0
 
0
         def dependency(generator_name, args, runtime_options = {})
...
1
 
2
3
4
...
37
38
39
 
 
 
 
 
 
40
41
42
...
60
61
62
 
 
 
 
 
63
64
65
...
1
2
3
4
5
...
38
39
40
41
42
43
44
45
46
47
48
49
...
67
68
69
70
71
72
73
74
75
76
77
0
@@ -1,4 +1,5 @@
0
 require 'rbconfig'
0
+require File.dirname(__FILE__) + '/template_runner'
0
 require 'digest/md5' 
0
 require 'active_support/secure_random'
0
 
0
@@ -37,6 +38,12 @@ class AppGenerator < Rails::Generator::Base
0
     end
0
   end
0
 
0
+  def after_generate
0
+    if options[:template]
0
+      Rails::TemplateRunner.new(@destination_root, options[:template])
0
+    end
0
+  end
0
+
0
   protected
0
     def banner
0
       "Usage: #{$0} /path/to/your/app [options]"
0
@@ -60,6 +67,11 @@ class AppGenerator < Rails::Generator::Base
0
       opt.on("-f", "--freeze",
0
             "Freeze Rails in vendor/rails from the gems generating the skeleton",
0
             "Default: false") { |v| options[:freeze] = v }
0
+
0
+      opt.on("-m", "--template=path", String,
0
+            "Use an application template that lives at path (can be a filesystem path or URL).",
0
+            "Default: (none)") { |v| options[:template] = v }
0
+
0
     end
0
 
0
 

Comments

greatseth Tue Dec 02 10:51:29 -0800 2008 at railties/bin/rails L11

BLOAT WTF BBQ

matthewrudy Tue Dec 02 14:02:32 -0800 2008

oh wow. I didn’t realise you could comment on individual lines.

Massiveness.

mislav Tue Dec 02 14:36:55 -0800 2008 at railties/bin/rails L11

OMG you’re increasing Rails’ LOC, nooooo

amerine Tue Dec 02 14:40:55 -0800 2008 at railties/bin/rails L11

ReallY????? OMG ITS HUGER!

chrisk Tue Dec 02 15:13:15 -0800 2008

Wow, this is super cool, nice work j-mac

Aupajo Tue Dec 02 16:00:27 -0800 2008
vendor("borrowed.rb", <<CODE
  ..snip..
+ CODE

Missing right-paren?

jeremymcanally Tue Dec 02 16:02:45 -0800 2008

Oopsie.

bumi Tue Dec 02 16:59:28 -0800 2008

yeah! great to see RG go into core! It feels like the old days when I’ve run the rails command for the first time ;)

samgranieri Wed Dec 03 06:22:43 -0800 2008

This is pretty cool. I wonder why RG was chosen over Suprails?

NZKoz Wed Dec 03 09:47:08 -0800 2008

@samgranieri: Jeremy reached out and suggested getting it included. We’ll be happy to take any patches to implement cool functionality in suprails but not in rails.

listrophy Fri Jul 03 11:22:52 -0700 2009

@samgranieri Thanks for the verbal support for Suprails, but Jeremy did the more intelligent thing and got it included into rails. I didn't try to do that with Suprails because I thought it would never get pulled into core. oops. =)