ronin-gen 1.0.1 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/ChangeLog.md +13 -0
- data/Gemfile +2 -2
- data/README.md +18 -9
- data/bin/ronin-gen +1 -13
- data/data/ronin/gen/library/Gemfile.erb +1 -1
- data/data/ronin/gen/library/README.md.erb +1 -1
- data/data/ronin/gen/library/gemspec.yml.erb +1 -1
- data/data/ronin/gen/library/lib/ronin/name/version.rb.erb +1 -1
- data/data/ronin/gen/library/name.gemspec.erb +1 -1
- data/data/ronin/gen/repository/ronin.yml.erb +2 -2
- data/gemspec.yml +3 -3
- data/lib/ronin/gen/dir_generator.rb +18 -28
- data/lib/ronin/gen/file_generator.rb +39 -21
- data/lib/ronin/gen/gen.rb +1 -1
- data/lib/ronin/gen/generator.rb +569 -94
- data/lib/ronin/gen/generators/library.rb +79 -113
- data/lib/ronin/gen/generators/repository.rb +31 -70
- data/lib/ronin/gen/ruby_generator.rb +1 -1
- data/lib/ronin/gen/source_code_generator.rb +41 -8
- data/lib/ronin/gen/version.rb +1 -1
- data/lib/ronin/ui/cli/commands/gen.rb +34 -3
- data/ronin-gen.gemspec +1 -1
- data/spec/gen/classes/basic_generator.rb +3 -5
- data/spec/gen/classes/file_generator.rb +2 -2
- data/spec/gen/classes/templated_generator.rb +2 -2
- data/spec/gen/classes/touch_generator.rb +1 -1
- data/spec/gen/gen_spec.rb +1 -1
- data/spec/gen/generator_spec.rb +4 -6
- data/spec/gen/generators/library_spec.rb +1 -1
- data/spec/gen/generators/repository_spec.rb +1 -2
- data/spec/gen/helpers/data/generators/templated.txt.erb +1 -1
- metadata +71 -76
@@ -32,48 +32,47 @@ module Ronin
|
|
32
32
|
#
|
33
33
|
class Library < DirGenerator
|
34
34
|
|
35
|
-
# Default version of the library
|
36
|
-
DEFAULT_VERSION = '0.1.0'
|
37
|
-
|
38
35
|
# Default license of the library
|
39
36
|
DEFAULT_LICENSE = 'GPL-2'
|
40
37
|
|
41
|
-
# Default author of the library
|
42
|
-
DEFAULT_AUTHOR = 'Author'
|
43
|
-
|
44
|
-
# Default email of the library
|
45
|
-
DEFAULT_EMAIL = 'name@host.com'
|
46
|
-
|
47
|
-
# Default homepage for the library
|
48
|
-
DEFAULT_HOMEPAGE = 'http://ronin-ruby.github.com/'
|
49
|
-
|
50
38
|
# Directory to store command classes in
|
51
39
|
COMMANDS_DIR = File.join('lib',UI::CLI::Commands.namespace_root)
|
52
40
|
|
53
41
|
# Directory to store generator classes in
|
54
42
|
GENERATORS_DIR = File.join('lib',Generators.namespace_root)
|
55
43
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
44
|
+
data_dir File.join('ronin','gen','library')
|
45
|
+
|
46
|
+
parameter :name, :type => String
|
47
|
+
|
48
|
+
parameter :version, :type => String,
|
49
|
+
:default => '0.1.0'
|
50
|
+
|
51
|
+
parameter :author, :type => String,
|
52
|
+
:default => 'Author'
|
53
|
+
|
54
|
+
parameter :email, :type => String,
|
55
|
+
:default => 'name@host.com'
|
56
|
+
|
57
|
+
parameter :homepage, :type => String,
|
58
|
+
:default => 'http://ronin-ruby.github.com/'
|
63
59
|
|
64
|
-
|
65
|
-
|
66
|
-
:banner => 'NAME [...]'
|
60
|
+
parameter :commands, :type => Array[String],
|
61
|
+
:default => []
|
67
62
|
|
68
|
-
|
69
|
-
|
70
|
-
:banner => 'NAME [...]'
|
63
|
+
parameter :generators, :type => Array[String],
|
64
|
+
:default => []
|
71
65
|
|
72
|
-
|
66
|
+
parameter :no_git, :type => true
|
73
67
|
|
68
|
+
#
|
69
|
+
# Sets up the library generator.
|
70
|
+
#
|
74
71
|
def setup
|
75
|
-
|
76
|
-
|
72
|
+
super
|
73
|
+
|
74
|
+
@name ||= File.basename(@path)
|
75
|
+
@dir_name = @name.gsub(/^ronin[-_]/,'')
|
77
76
|
@module_name = @dir_name.capitalize
|
78
77
|
|
79
78
|
@title = @name.split(/[\s_-]+/).map { |word|
|
@@ -82,133 +81,100 @@ module Ronin
|
|
82
81
|
|
83
82
|
@license = DEFAULT_LICENSE
|
84
83
|
|
85
|
-
@author = options[:author]
|
86
|
-
@email = options[:email]
|
87
84
|
@safe_email = @email.gsub(/\s*@\s*/,' at ')
|
88
|
-
|
85
|
+
|
86
|
+
@bin_script = File.join('bin',"ronin-#{@dir_name}")
|
89
87
|
end
|
90
88
|
|
91
89
|
#
|
92
90
|
# Generates top-level files.
|
93
91
|
#
|
94
92
|
def generate
|
95
|
-
unless
|
96
|
-
|
93
|
+
unless no_git?
|
94
|
+
run "git init"
|
97
95
|
end
|
98
96
|
|
99
|
-
|
100
|
-
cp
|
97
|
+
template 'Gemfile.erb', 'Gemfile'
|
98
|
+
cp 'Rakefile'
|
101
99
|
|
102
|
-
|
103
|
-
|
104
|
-
erb File.join('ronin','gen','library','gemspec.yml.erb'),
|
105
|
-
'gemspec.yml'
|
100
|
+
template 'name.gemspec.erb', "#{@name}.gemspec"
|
101
|
+
template 'gemspec.yml.erb', 'gemspec.yml'
|
106
102
|
|
107
|
-
unless
|
108
|
-
cp
|
103
|
+
unless no_git?
|
104
|
+
cp '.gitignore'
|
109
105
|
end
|
110
106
|
|
111
|
-
cp
|
112
|
-
cp
|
113
|
-
|
114
|
-
'.yardopts'
|
107
|
+
cp '.rspec'
|
108
|
+
cp '.document'
|
109
|
+
template '.yardopts.erb', '.yardopts'
|
115
110
|
|
116
|
-
cp
|
111
|
+
cp 'COPYING.txt'
|
117
112
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
erb File.join('ronin','gen','library','README.md.erb'),
|
122
|
-
'README.md'
|
123
|
-
|
124
|
-
mkdir 'data'
|
125
|
-
end
|
113
|
+
template 'ChangeLog.md.erb', 'ChangeLog.md'
|
114
|
+
template 'README.md.erb', 'README.md'
|
126
115
|
|
127
|
-
#
|
128
|
-
# Generates the contents of the `bin` directory.
|
129
|
-
#
|
130
|
-
def bin
|
131
116
|
mkdir 'bin'
|
132
117
|
|
133
|
-
|
118
|
+
template File.join('bin','ronin-name.erb'), @bin_script
|
119
|
+
chmod 0755, @bin_script
|
134
120
|
|
135
|
-
|
136
|
-
bin_script
|
137
|
-
chmod bin_script, 0755
|
138
|
-
end
|
121
|
+
mkdir_p File.join('lib','ronin',@dir_name)
|
139
122
|
|
140
|
-
|
141
|
-
|
142
|
-
#
|
143
|
-
def lib
|
144
|
-
mkdir File.join('lib','ronin',@dir_name)
|
123
|
+
template File.join('lib','ronin','name.rb.erb'),
|
124
|
+
File.join('lib','ronin',"#{@dir_name}.rb")
|
145
125
|
|
146
|
-
|
147
|
-
|
126
|
+
template File.join('lib','ronin','name','version.rb.erb'),
|
127
|
+
File.join('lib','ronin',@dir_name,'version.rb')
|
148
128
|
|
149
|
-
|
150
|
-
File.join('lib','ronin',@dir_name,'version.rb')
|
151
|
-
end
|
129
|
+
mkdir 'data'
|
152
130
|
|
153
|
-
#
|
154
|
-
# Generates the test suite.
|
155
|
-
#
|
156
|
-
def test_suite
|
157
131
|
mkdir 'spec'
|
158
|
-
|
159
|
-
|
132
|
+
template File.join('spec','spec_helper.rb.erb'),
|
133
|
+
File.join('spec','spec_helper.rb')
|
160
134
|
|
161
135
|
mkdir File.join('spec',@dir_name)
|
162
|
-
|
163
|
-
|
136
|
+
template File.join('spec','name','name_spec.rb.erb'),
|
137
|
+
File.join('spec',@dir_name,"#{@dir_name}_spec.rb")
|
138
|
+
|
139
|
+
generate_commands unless @commands.empty?
|
140
|
+
generate_generators unless @generators.empty?
|
141
|
+
|
142
|
+
unless no_git?
|
143
|
+
run 'git add .'
|
144
|
+
run 'git commit -m "Initial commit."'
|
145
|
+
end
|
164
146
|
end
|
165
147
|
|
166
148
|
#
|
167
149
|
# Generates any optional commands for the library.
|
168
150
|
#
|
169
|
-
def
|
170
|
-
|
171
|
-
mkdir COMMANDS_DIR
|
151
|
+
def generate_commands
|
152
|
+
mkdir COMMANDS_DIR
|
172
153
|
|
173
|
-
|
174
|
-
|
175
|
-
|
154
|
+
@commands.each do |name|
|
155
|
+
@command_file = name.downcase.gsub(/[_-]+/,'_')
|
156
|
+
@command_class = @command_file.to_const_string
|
176
157
|
|
177
|
-
|
178
|
-
|
158
|
+
template File.join('bin','ronin-command.erb'),
|
159
|
+
File.join('bin','ronin-' + @command_file.gsub('_','-'))
|
179
160
|
|
180
|
-
|
181
|
-
|
182
|
-
end
|
161
|
+
template File.join(COMMANDS_DIR,'command.rb.erb'),
|
162
|
+
File.join(COMMANDS_DIR,"#{@command_file}.rb")
|
183
163
|
end
|
184
164
|
end
|
185
165
|
|
186
166
|
#
|
187
167
|
# Generates any optional generators for the library.
|
188
168
|
#
|
189
|
-
def
|
190
|
-
|
191
|
-
mkdir GENERATORS_DIR
|
192
|
-
|
193
|
-
options[:generators].each do |name|
|
194
|
-
@generator_file = name.downcase.gsub(/[_-]+/,'_')
|
195
|
-
@generator_class = @generator_file.to_const_string
|
169
|
+
def generate_generators
|
170
|
+
mkdir GENERATORS_DIR
|
196
171
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
end
|
201
|
-
end
|
172
|
+
@generators.each do |name|
|
173
|
+
@generator_file = name.downcase.gsub(/[_-]+/,'_')
|
174
|
+
@generator_class = @generator_file.to_const_string
|
202
175
|
|
203
|
-
|
204
|
-
|
205
|
-
#
|
206
|
-
def finalize
|
207
|
-
unless options[:no_git]
|
208
|
-
inside do
|
209
|
-
run('git add .')
|
210
|
-
run('git commit -m "Initial commit."')
|
211
|
-
end
|
176
|
+
template File.join(GENERATORS_DIR,'generator.rb.erb'),
|
177
|
+
File.join(GENERATORS_DIR,"#{@generator_file}.rb")
|
212
178
|
end
|
213
179
|
end
|
214
180
|
|
@@ -22,8 +22,6 @@ require 'ronin/gen/dir_generator'
|
|
22
22
|
require 'ronin/repository'
|
23
23
|
require 'ronin/version'
|
24
24
|
|
25
|
-
require 'set'
|
26
|
-
|
27
25
|
module Ronin
|
28
26
|
module Gen
|
29
27
|
module Generators
|
@@ -41,103 +39,66 @@ module Ronin
|
|
41
39
|
# The primary script directory
|
42
40
|
SCRIPT_DIR = Ronin::Repository::SCRIPT_DIRS.first
|
43
41
|
|
44
|
-
# Default license to use
|
45
|
-
DEFAULT_LICENSE = 'CC-by'
|
46
|
-
|
47
42
|
# Default authors to use
|
48
|
-
|
43
|
+
DEFAULT_AUTHOR = 'Anonymous'
|
49
44
|
|
50
|
-
|
51
|
-
DEFAULT_DESCRIPTION = 'This is a Ronin Repository'
|
45
|
+
data_dir File.join('ronin','gen','repository')
|
52
46
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
class_option :website, :type => :string
|
47
|
+
parameter :title, :type => String
|
48
|
+
parameter :uri, :type => String
|
49
|
+
parameter :source, :type => String
|
50
|
+
parameter :website, :type => String
|
58
51
|
|
59
|
-
|
60
|
-
|
61
|
-
:banner => 'LICENSE'
|
52
|
+
parameter :license, :type => String,
|
53
|
+
:default => 'CC-by'
|
62
54
|
|
63
|
-
|
64
|
-
|
65
|
-
:banner => 'TEXT'
|
55
|
+
parameter :description, :type => String,
|
56
|
+
:default => 'This is a Ronin Repository'
|
66
57
|
|
67
|
-
|
68
|
-
|
69
|
-
:banner => 'NAME [...]'
|
58
|
+
parameter :authors, :type => Array[String],
|
59
|
+
:default => []
|
70
60
|
|
71
|
-
|
72
|
-
|
61
|
+
parameter :tests, :type => true
|
62
|
+
parameter :docs, :type => true
|
73
63
|
|
64
|
+
#
|
65
|
+
# Sets up the repository generator.
|
66
|
+
#
|
74
67
|
def setup
|
75
|
-
@title
|
76
|
-
@uri = options[:uri]
|
77
|
-
@source = options[:source]
|
78
|
-
@website = options[:website]
|
79
|
-
@license = options[:license]
|
80
|
-
@description = options[:description]
|
81
|
-
@authors = options[:authors]
|
82
|
-
|
83
|
-
@test_suite = options[:test]
|
84
|
-
@docs = options[:docs]
|
85
|
-
|
86
|
-
@title ||= File.basename(self.path).gsub(/[_\s]+/,' ').capitalize
|
68
|
+
@title ||= File.basename(@path).gsub(/[_\s]+/,' ').capitalize
|
87
69
|
@website ||= @source
|
70
|
+
|
71
|
+
if @authors.empty?
|
72
|
+
@authors << DEFAULT_AUTHOR
|
73
|
+
end
|
88
74
|
end
|
89
75
|
|
90
76
|
#
|
91
77
|
# Generates a skeleton repository.
|
92
78
|
#
|
93
79
|
def generate
|
80
|
+
template 'ronin.yml.erb', 'ronin.yml'
|
81
|
+
template 'Rakefile.erb', 'Rakefile'
|
82
|
+
|
94
83
|
mkdir LIB_DIR
|
95
84
|
mkdir File.join(LIB_DIR,'ronin')
|
96
85
|
touch File.join(LIB_DIR,Ronin::Repository::INIT_FILE)
|
97
86
|
|
98
87
|
mkdir SCRIPT_DIR
|
99
88
|
mkdir Ronin::Repository::DATA_DIR
|
100
|
-
end
|
101
89
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
def rakefile
|
106
|
-
erb File.join('ronin','gen','repository','Rakefile.erb'),
|
107
|
-
'Rakefile'
|
108
|
-
end
|
90
|
+
if docs?
|
91
|
+
template '.yardopts.erb', '.yardopts'
|
92
|
+
end
|
109
93
|
|
110
|
-
|
111
|
-
|
112
|
-
#
|
113
|
-
def tests
|
114
|
-
if options.tests?
|
115
|
-
cp File.join('ronin','gen','repository','.rspec'), '.rspec'
|
94
|
+
if tests?
|
95
|
+
cp '.rspec'
|
116
96
|
|
117
97
|
mkdir 'spec'
|
118
|
-
cp File.join('
|
119
|
-
File.join('spec','spec_helper.rb')
|
98
|
+
cp File.join('spec','spec_helper.rb')
|
120
99
|
end
|
121
100
|
end
|
122
101
|
|
123
|
-
#
|
124
|
-
# Generate files needed for documentation.
|
125
|
-
#
|
126
|
-
def docs
|
127
|
-
if options.docs?
|
128
|
-
erb File.join('ronin','gen','repository','.yardopts.erb'),
|
129
|
-
'.yardopts'
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
#
|
134
|
-
# Generates the XML metadata file for the repository.
|
135
|
-
#
|
136
|
-
def metadata
|
137
|
-
erb File.join('ronin','gen','repository','ronin.yml.erb'),
|
138
|
-
'ronin.yml'
|
139
|
-
end
|
140
|
-
|
141
102
|
end
|
142
103
|
end
|
143
104
|
end
|
@@ -22,21 +22,54 @@ require 'ronin/gen/file_generator'
|
|
22
22
|
module Ronin
|
23
23
|
module Gen
|
24
24
|
#
|
25
|
-
# A {FileGenerator} class for creating
|
25
|
+
# A {FileGenerator} class for creating source-code files.
|
26
26
|
#
|
27
27
|
class SourceCodeGenerator < FileGenerator
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
parameter :editor, :type => String,
|
30
|
+
:default => ENV['EDITOR']
|
31
31
|
|
32
|
+
parameter :no_edit, :type => true,
|
33
|
+
:default => false
|
34
|
+
|
35
|
+
#
|
36
|
+
# Generates the source code file and spawns a text-editor.
|
32
37
|
#
|
33
|
-
#
|
38
|
+
# @since 1.1.0
|
34
39
|
#
|
35
|
-
|
36
|
-
|
40
|
+
# @api semipublic
|
41
|
+
#
|
42
|
+
def generate
|
43
|
+
template self.class.template, @path
|
44
|
+
|
45
|
+
if (no_edit? && editor?)
|
46
|
+
# spawn the text editor for the newly generated file
|
47
|
+
system(editor,@path)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
37
52
|
|
38
|
-
|
39
|
-
|
53
|
+
#
|
54
|
+
# The template the Source Code Generator will use.
|
55
|
+
#
|
56
|
+
# @param [String] name
|
57
|
+
# The new template name.
|
58
|
+
#
|
59
|
+
# @return [String]
|
60
|
+
# The template the Source Code Generator will use.
|
61
|
+
#
|
62
|
+
# @since 1.1.0
|
63
|
+
#
|
64
|
+
# @api semipublic
|
65
|
+
#
|
66
|
+
def self.template(name=nil)
|
67
|
+
if name
|
68
|
+
@template = name
|
69
|
+
else
|
70
|
+
@template ||= if superclass < SourceCodeGenerator
|
71
|
+
superclass.template
|
72
|
+
end
|
40
73
|
end
|
41
74
|
end
|
42
75
|
|