ronin-gen 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +14 -0
  3. data/Manifest.txt +4 -4
  4. data/README.txt +32 -30
  5. data/Rakefile +11 -1
  6. data/bin/ronin-gen +2 -2
  7. data/bin/ronin-gen-extension +1 -1
  8. data/bin/ronin-gen-overlay +1 -1
  9. data/lib/ronin/generators.rb +0 -2
  10. data/lib/ronin/generators/dir_generator.rb +38 -7
  11. data/lib/ronin/generators/generator.rb +93 -88
  12. data/lib/ronin/generators/platform/extension.rb +7 -11
  13. data/lib/ronin/generators/platform/overlay.rb +91 -106
  14. data/lib/ronin/generators/platform/static.rb +0 -2
  15. data/lib/ronin/generators/version.rb +1 -3
  16. data/lib/ronin/ui/command_line/commands/gen.rb +8 -19
  17. data/lib/ronin/ui/command_line/commands/gen_extension.rb +1 -24
  18. data/lib/ronin/ui/command_line/commands/gen_overlay.rb +1 -65
  19. data/spec/generated_overlay_examples.rb +6 -0
  20. data/spec/generators/classes/dir_generator.rb +2 -4
  21. data/spec/generators/classes/file_generator.rb +4 -4
  22. data/spec/generators/classes/templated_generator.rb +3 -7
  23. data/spec/generators/classes/touch_generator.rb +1 -3
  24. data/spec/generators/generator_spec.rb +8 -10
  25. data/spec/generators/helpers/static/generators/templated.txt.erb +1 -1
  26. data/spec/generators/platform/extension_spec.rb +1 -4
  27. data/spec/generators/platform/overlay_spec.rb +2 -4
  28. data/spec/spec_helper.rb +1 -1
  29. data/spec/ui/command_line/commands/gen_extension_spec.rb +1 -1
  30. data/spec/ui/command_line/commands/gen_overlay_spec.rb +4 -4
  31. data/static/ronin/generators/platform/Rakefile.erb +5 -0
  32. data/static/ronin/{platform/generators → generators/platform}/extension.rb +0 -0
  33. data/static/ronin/{platform/generators → generators/platform}/spec/spec_helper.rb +1 -1
  34. data/tasks/spec.rb +1 -0
  35. data/tasks/yard.rb +13 -0
  36. metadata +33 -14
  37. metadata.gz.sig +0 -0
  38. data/TODO.txt +0 -3
  39. data/lib/ronin/generators/platform/spec.rb +0 -46
@@ -1,5 +1,4 @@
1
1
  #
2
- #--
3
2
  # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
3
  #
5
4
  # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
@@ -17,7 +16,6 @@
17
16
  # You should have received a copy of the GNU General Public License
18
17
  # along with this program; if not, write to the Free Software
19
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #++
21
19
  #
22
20
 
23
21
  require 'ronin/generators/platform/static'
@@ -33,21 +31,19 @@ module Ronin
33
31
  LIB_DIR = Ronin::Platform::Extension::LIB_DIR
34
32
 
35
33
  # The default extension file
36
- EXTENSION_FILE = File.join('ronin','platform','generators','extension.rb')
37
-
38
- protected
34
+ EXTENSION_FILE = File.join('ronin','generators','platform','extension.rb')
39
35
 
40
36
  #
41
37
  # Generates a skeleton Extension.
42
38
  #
43
- def generate!
44
- name = File.basename(@path)
39
+ def generate
40
+ name = File.basename(self.path)
45
41
 
46
- directory LIB_DIR
47
- file File.join(LIB_DIR,name + '.rb')
48
- directory File.join(LIB_DIR,name)
42
+ mkdir LIB_DIR
43
+ touch File.join(LIB_DIR,name + '.rb')
44
+ mkdir File.join(LIB_DIR,name)
49
45
 
50
- copy EXTENSION_FILE, Ronin::Platform::Extension::EXTENSION_FILE
46
+ copy_file EXTENSION_FILE, Ronin::Platform::Extension::EXTENSION_FILE
51
47
  end
52
48
 
53
49
  end
@@ -1,5 +1,4 @@
1
1
  #
2
- #--
3
2
  # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
3
  #
5
4
  # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
@@ -17,7 +16,6 @@
17
16
  # You should have received a copy of the GNU General Public License
18
17
  # along with this program; if not, write to the Free Software
19
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #++
21
19
  #
22
20
 
23
21
  require 'ronin/generators/platform/static'
@@ -39,7 +37,7 @@ module Ronin
39
37
  METADATA_FILE = Ronin::Platform::Overlay::METADATA_FILE
40
38
 
41
39
  # The Overlay metadata XSL URL
42
- METADATA_XSL = 'http://ronin.rubyforge.org/static/ronin/platform/overlay.xsl'
40
+ METADATA_XSL = File.join('ronin','platform','overlay.xsl')
43
41
 
44
42
  # The Overlay lib directory
45
43
  LIB_DIR = Ronin::Platform::Overlay::LIB_DIR
@@ -51,123 +49,99 @@ module Ronin
51
49
  DEFAULT_LICENSE = 'CC-by'
52
50
 
53
51
  # Default maintainer to use
54
- DEFAULT_MAINTAINER = {:name => 'Name', :email => 'name@example.com'}
52
+ DEFAULT_MAINTAINER = {'Name' => 'name@example.com'}
55
53
 
56
54
  # Default description to use
57
55
  DEFAULT_DESCRIPTION = 'This is an Overlay'
58
56
 
59
- # Title of the overlay
60
- attr_accessor :title
61
-
62
- # Source URL for the overlay
63
- attr_accessor :source
64
-
65
- # Source View URL for the overlay
66
- attr_accessor :source_view
67
-
68
- # Website of the overlay
69
- attr_accessor :website
70
-
71
- # License of the overlay
72
- attr_accessor :license
73
-
74
- # Maintainers of the overlay
75
- attr_reader :maintainers
76
-
77
- # Description of the overlay
78
- attr_accessor :description
79
-
80
- # Tasks to require for the overlay
81
- attr_reader :tasks
82
-
83
- #
84
- # Creates a new Metadata object with the given _options_.
85
- #
86
- # _options_ may include the following keys:
87
- # <tt>:title</tt>:: Title for the overlay.
88
- # <tt>:source</tt>:: Source URL for the overlay.
89
- # <tt>:source_view</tt>:: Source View URL for the overlay.
90
- # <tt>:website</tt>:: Website for the overlay.
91
- # <tt>:license</tt>:: License for the overlay. Defaults to
92
- # DEFUALT_LICENSE, if not given.
93
- # <tt>:maintainers</tt>:: List of maintainers for the overlay.
94
- # <tt>:description</tt>:: The description of the overlay.
95
- # Defaults to DEFAULT_DESCRIPTION,
96
- # if not given.
97
- #
98
- def initialize(options={})
99
- @title = options[:title]
100
- @source = options[:source]
101
- @source_view = options[:source_view]
102
- @website = options[:website]
103
- @license = (options[:license] || DEFAULT_LICENSE)
104
- @maintainers = []
105
-
106
- if options[:maintainers]
107
- @maintainers.merge!(options[:maintainers])
108
- end
109
-
110
- @description = (options[:description] || DEFAULT_DESCRIPTION)
111
- @tasks = Set[]
57
+ class_option :title, :type => :string
58
+ class_option :source, :type => :string
59
+ class_option :source_view, :type => :string
60
+ class_option :website, :type => :string
61
+ class_option :license, :type => :string, :default => DEFAULT_LICENSE
62
+ class_option :description, :type => :string, :default => DEFAULT_DESCRIPTION
63
+ class_option :maintainers, :type => :hash, :default => {}, :banner => 'NAME:EMAIL ...'
64
+ class_option :gems, :type => :array, :default => [], :banner => 'GEM ...'
65
+ class_option :tasks, :type => :array, :default => [], :banner => 'TASK ...'
66
+ class_option :test_suite, :type => :string, :banner => 'test|spec'
67
+
68
+ no_tasks do
69
+ def invoke(*names,&block)
70
+ @title = options[:title]
71
+ @source = options[:source]
72
+ @source_view = options[:source_view]
73
+ @website = options[:website]
74
+ @license = options[:license]
75
+ @description = options[:description]
76
+ @maintainers = options[:maintainers]
77
+ @gems = options[:gems]
78
+ @tasks = options[:tasks]
79
+ @test_suite = options[:test_suite]
80
+
81
+ @title ||= File.basename(self.path).gsub(/[_\s]+/,' ').capitalize
82
+ @source_view ||= @source
83
+ @website ||= @source_view
84
+
85
+ if @maintainers
86
+ @maintainers = DEFAULT_MAINTAINER
87
+ end
112
88
 
113
- if options[:tasks]
114
- @tasks.merge!(options[:tasks])
89
+ super(*names,&block)
115
90
  end
116
91
  end
117
92
 
118
- #
119
- # Adds a new maintainer with the specified _name_ and _email_.
120
- #
121
- def maintainer(name,email)
122
- @maintainers << {:name => name, :email => email}
123
- end
124
-
125
- protected
126
-
127
93
  #
128
94
  # Generates a skeleton Overlay.
129
95
  #
130
- def generate!
131
- @title ||= File.basename(@path).gsub(/[_\s]+/,' ').capitalize
132
- @source_view ||= @source
133
- @website ||= @source_view
134
- @maintainers << DEFAULT_MAINTAINER if @maintainers.empty?
96
+ def generate
97
+ mkdir 'static'
135
98
 
136
- directory LIB_DIR
137
- touch File.join(LIB_DIR,Ronin::Platform::Overlay::INIT_FILE)
99
+ inside File.join('static','ronin','platform') do
100
+ copy_file METADATA_XSL, File.basename(METADATA_XSL)
101
+ end
138
102
 
139
- directory OBJECTS_DIR
140
- directory 'tasks'
103
+ mkdir LIB_DIR
104
+ touch File.join(LIB_DIR,Ronin::Platform::Overlay::INIT_FILE)
141
105
 
142
- generate_rakefile!
143
- generate_metadata!
106
+ mkdir OBJECTS_DIR
107
+ mkdir 'tasks'
144
108
  end
145
109
 
146
110
  #
147
111
  # Generates the Rakefile of the Overlay.
148
112
  #
149
- def generate_rakefile!
150
- file('Rakefile') do |rakefile|
151
- rakefile << "# -*- ruby -*-\n\n"
113
+ def rakefile
114
+ case @test_suite
115
+ when 'rspec', 'spec'
116
+ @tasks << 'spec' unless @tasks.include?('spec')
117
+ end
152
118
 
153
- @tasks.each do |task|
154
- rakefile << "require 'ronin/platform/tasks/#{task}'"
155
- end
119
+ template File.join('ronin','generators','platform','Rakefile.erb'), 'Rakefile'
120
+ end
156
121
 
157
- rakefile << "\n# vim: syntax=Ruby"
122
+ #
123
+ # Generates a base test suite for the Overlay.
124
+ #
125
+ def test_suite
126
+ case @test_suite
127
+ when 'test','unit'
128
+ mkdir 'test'
129
+ when 'rspec', 'spec'
130
+ mkdir 'spec'
131
+ copy_file File.join('ronin','generators','platform','spec','spec_helper.rb'),'spec'
158
132
  end
159
133
  end
160
134
 
161
135
  #
162
136
  # Generates the XML metadata file for the Overlay.
163
137
  #
164
- def generate_metadata!
165
- file(METADATA_FILE) do |metadata_file|
138
+ def metadata
139
+ create_file(METADATA_FILE) do
166
140
  doc = XML::Document.new
167
141
  doc << XML::ProcessingInstruction.new(
168
142
  doc,
169
143
  'xml-stylesheet',
170
- "type=\"text/xsl\" href=\"#{METADATA_XSL}\""
144
+ "type=\"text/xsl\" href=\"static/#{METADATA_XSL}\""
171
145
  )
172
146
 
173
147
  root = XML::Node.new('ronin-overlay',doc)
@@ -177,7 +151,7 @@ module Ronin
177
151
  title_tag << XML::Text.new(@title,doc)
178
152
  root << title_tag
179
153
 
180
- if @source
154
+ if options[:source]
181
155
  source_tag = XML::Node.new('source',doc)
182
156
  source_tag << XML::Text.new(@source,doc)
183
157
  root << source_tag
@@ -201,34 +175,45 @@ module Ronin
201
175
 
202
176
  maintainers_tag = XML::Node.new('maintainers',doc)
203
177
 
204
- @maintainers.each do |author|
205
- if (author[:name] || author[:email])
206
- maintainer_tag = XML::Node.new('maintainer',doc)
178
+ @maintainers.each do |name,email|
179
+ maintainer_tag = XML::Node.new('maintainer',doc)
207
180
 
208
- if author[:name]
209
- name_tag = XML::Node.new('name',doc)
210
- name_tag << XML::Text.new(author[:name],doc)
211
- maintainer_tag << name_tag
212
- end
213
-
214
- if author[:email]
215
- email_tag = XML::Node.new('email',doc)
216
- email_tag << XML::Text.new(author[:email],doc)
217
- maintainer_tag << email_tag
218
- end
181
+ if name
182
+ name_tag = XML::Node.new('name',doc)
183
+ name_tag << XML::Text.new(name,doc)
184
+ maintainer_tag << name_tag
185
+ end
219
186
 
220
- maintainers_tag << maintainer_tag
187
+ if email
188
+ email_tag = XML::Node.new('email',doc)
189
+ email_tag << XML::Text.new(email,doc)
190
+ maintainer_tag << email_tag
221
191
  end
192
+
193
+ maintainers_tag << maintainer_tag
222
194
  end
223
195
 
224
196
  root << maintainers_tag
225
197
 
198
+ unless @gems.empty?
199
+ dependencies_tag = XML::Node.new('dependencies',doc)
200
+ dependencies_tag << XML::Text.new(gems_tag,doc)
201
+
202
+ @gems.each do |gem_name|
203
+ gem_tag = XML::Node.new('gem',doc)
204
+ gem_tag << XML::Text.new(gem_name,doc)
205
+ dependencies_tag << gem_tag
206
+ end
207
+
208
+ root << dependencies_tag
209
+ end
210
+
226
211
  description_tag = XML::Node.new('description',doc)
227
212
  description_tag << XML::Text.new(@description,doc)
228
213
  root << description_tag
229
214
 
230
215
  doc << root
231
- doc.write_xml_to(metadata_file)
216
+ doc.to_xml
232
217
  end
233
218
  end
234
219
 
@@ -1,5 +1,4 @@
1
1
  #
2
- #--
3
2
  # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
3
  #
5
4
  # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at example.com)
@@ -17,7 +16,6 @@
17
16
  # You should have received a copy of the GNU General Public License
18
17
  # along with this program; if not, write to the Free Software
19
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #++
21
19
  #
22
20
 
23
21
  require 'ronin/static'
@@ -1,5 +1,4 @@
1
1
  #
2
- #--
3
2
  # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
3
  #
5
4
  # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at example.com)
@@ -17,12 +16,11 @@
17
16
  # You should have received a copy of the GNU General Public License
18
17
  # along with this program; if not, write to the Free Software
19
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #++
21
19
  #
22
20
 
23
21
  module Ronin
24
22
  module Generators
25
23
  # Ronin Gen version
26
- VERSION = '0.1.1'
24
+ VERSION = '0.2.0'
27
25
  end
28
26
  end
@@ -1,5 +1,4 @@
1
1
  #
2
- #--
3
2
  # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
3
  #
5
4
  # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
@@ -17,7 +16,6 @@
17
16
  # You should have received a copy of the GNU General Public License
18
17
  # along with this program; if not, write to the Free Software
19
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #++
21
19
  #
22
20
 
23
21
  require 'ronin/generators/version'
@@ -30,26 +28,17 @@ module Ronin
30
28
  module Commands
31
29
  class Gen < Command
32
30
 
33
- def define_options(opts)
34
- opts.usage = '[options] NAME'
35
-
36
- opts.options do
37
- opts.on('-V','--version','Print version information and exit') do
38
- success { puts "Ronin Gen #{Ronin::Generators::VERSION}" }
39
- end
40
- end
41
-
42
- opts.arguments(
43
- 'NAME' => 'Name of the Generator to run'
44
- )
45
-
46
- opts.summary('Runs the Generator with the specified NAME and options')
31
+ desc "version", "Prints the version and exists"
32
+ def version
33
+ puts "Ronin Gen #{Ronin::Generators::VERSION}"
34
+ exit
47
35
  end
48
36
 
49
- def arguments(*args)
50
- puts CommandLine.commands.map { |name|
37
+ desc "default", "Prints the list of available generators"
38
+ def default
39
+ print_array CommandLine.commands.map { |name|
51
40
  if name =~ /^gen_/
52
- name.gsub(/^gen_/,' ')
41
+ name.gsub(/^gen_/,'')
53
42
  else
54
43
  nil
55
44
  end
@@ -1,5 +1,4 @@
1
1
  #
2
- #--
3
2
  # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
3
  #
5
4
  # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
@@ -17,37 +16,15 @@
17
16
  # You should have received a copy of the GNU General Public License
18
17
  # along with this program; if not, write to the Free Software
19
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #++
21
19
  #
22
20
 
23
- require 'ronin/ui/command_line/command'
24
21
  require 'ronin/generators/platform/extension'
25
22
 
26
23
  module Ronin
27
24
  module UI
28
25
  module CommandLine
29
26
  module Commands
30
- class GenExtension < Command
31
-
32
- def defaults
33
- @generator = Generators::Platform::Extension.new
34
- end
35
-
36
- def define_options(opts)
37
- opts.usage = 'PATH [...]'
38
-
39
- opts.arguments(
40
- 'PATH' => 'The PATH of the Extension to be created'
41
- )
42
-
43
- opts.summary('Create an empty Extension at the specified PATH')
44
- end
45
-
46
- def arguments(*args)
47
- args.each do |path|
48
- @generator.run(File.expand_path(path))
49
- end
50
- end
27
+ class GenExtension < Generators::Platform::Extension
51
28
 
52
29
  end
53
30
  end
@@ -1,5 +1,4 @@
1
1
  #
2
- #--
3
2
  # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
3
  #
5
4
  # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
@@ -17,78 +16,15 @@
17
16
  # You should have received a copy of the GNU General Public License
18
17
  # along with this program; if not, write to the Free Software
19
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #++
21
19
  #
22
20
 
23
- require 'ronin/ui/command_line/command'
24
21
  require 'ronin/generators/platform/overlay'
25
22
 
26
23
  module Ronin
27
24
  module UI
28
25
  module CommandLine
29
26
  module Commands
30
- class GenOverlay < Command
31
-
32
- def defaults
33
- @generator = Generators::Platform::Overlay.new
34
- end
35
-
36
- def define_options(opts)
37
- opts.usage = '[options] PATH'
38
-
39
- opts.options do
40
- opts.on('-t','--title NAME','Name of the Overlay') do |title|
41
- @generator.title = title
42
- end
43
-
44
- opts.on('-S','--source URL','The URL where the source of the Overlay will be hosted') do |url|
45
- @generator.source = url
46
- end
47
-
48
- opts.on('-V','--source-view URL','The URL for viewing the contents of the Overlay') do |url|
49
- @generator.source_view = url
50
- end
51
-
52
- opts.on('-U','--website URL','The URL of the website of the Overlay') do |url|
53
- @generator.website = url
54
- end
55
-
56
- opts.on('-L','--license LICENSE','The license of the contents of the Overlay') do |license|
57
- @generator.license = license
58
- end
59
-
60
- opts.on('-m','--maintainer "NAME <EMAIL>"','Name of a maintainer of the Overlay') do |text|
61
- name = text.scan(/^[^<]+[^<\s]/).first
62
- email = text.scan(/<([^<>]+)>\s*$/).first
63
-
64
- email = email.first if email
65
-
66
- @generator.maintainers << {:name => name, :email => email}
67
- end
68
-
69
- opts.on('-D','--description TEXT','The description for the Overlay') do |text|
70
- @generator.description = text
71
- end
72
-
73
- opts.on('--task TASK','Add the TASK to the Overlay') do |task|
74
- @generator.tasks << task.to_s
75
- end
76
- end
77
-
78
- opts.arguments(
79
- 'PATH' => 'The PATH of the Overlay to be created'
80
- )
81
-
82
- opts.summary('Create an empty Overlay at the specified PATH')
83
- end
84
-
85
- def arguments(*args)
86
- unless args.length == 1
87
- fail('only one Overlay path maybe specified')
88
- end
89
-
90
- @generator.run(File.expand_path(args.first))
91
- end
27
+ class GenOverlay < Generators::Platform::Overlay
92
28
 
93
29
  end
94
30
  end