tclone 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,9 @@
1
1
  class TcloneGenerator < Rails::Generators::NamedBase
2
2
  source_root File.expand_path('../templates', __FILE__)
3
3
 
4
+ argument :template_file_name, :type => :string, :default => ""
5
+ class_option :recursive, :type => :boolean, :default => true, :desc => "Do recursive template clone"
6
+
4
7
  def create_template_files
5
8
  clone_generator_templates( name )
6
9
  end
@@ -9,16 +12,29 @@ class TcloneGenerator < Rails::Generators::NamedBase
9
12
  def clone_generator_templates( gname, goptions = [] )
10
13
  klass_obj = Rails::Generators.find_by_namespace( gname, *goptions )
11
14
  if( klass_obj )
12
- clone_templates( klass_obj.namespace, klass_obj.source_root )
13
- for k,v in klass_obj.hooks
14
- gk = klass_obj.class_options[k].default
15
- gk = ( gk == true ) ? k : gk
16
- clone_generator_templates( gk, v )
15
+ if( template_file_name != "" )
16
+ clone_file( klass_obj.namespace, klass_obj.source_root, template_file_name )
17
+ else
18
+ clone_templates( klass_obj.namespace, klass_obj.source_root )
19
+ if( options[:recursive] )
20
+ for k,v in klass_obj.hooks
21
+ gk = klass_obj.class_options[k].default
22
+ gk = ( gk == true ) ? k : gk
23
+ clone_generator_templates( gk, v )
24
+ end
25
+ end
17
26
  end
18
27
  end
19
28
  end
20
29
 
30
+ def clone_file( ns, path, filename )
31
+ if( path and File.directory?( path ) and File.file?( path + "/" + filename ) )
32
+ copy_file "#{path}/#{filename}", "lib/templates/#{ns.gsub(/:/,'/')}/#{filename}"
33
+ end
34
+ end
35
+
21
36
  def clone_templates( ns, path )
37
+ puts ns
22
38
  if( path and File.directory? path )
23
39
  directory path, "lib/templates/#{ns.gsub(/:/,'/')}"
24
40
  end
@@ -1,3 +1,3 @@
1
1
  module Tclone
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mohammed Siddick. E
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-05 00:00:00 +05:30
17
+ date: 2011-01-23 00:00:00 +05:30
18
18
  default_executable:
19
19
  dependencies: []
20
20