ronin-gen 0.2.0 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/.document +4 -0
  2. data/.rspec +1 -0
  3. data/.yardopts +1 -0
  4. data/ChangeLog.md +41 -0
  5. data/Gemfile +27 -0
  6. data/{README.txt → README.md} +30 -21
  7. data/Rakefile +24 -20
  8. data/bin/ronin-gen +27 -8
  9. data/data/ronin/gen/library/.document +5 -0
  10. data/data/ronin/gen/library/.gitignore +10 -0
  11. data/data/ronin/gen/library/.rspec +1 -0
  12. data/data/ronin/gen/library/.yardopts.erb +1 -0
  13. data/data/ronin/gen/library/COPYING.txt +339 -0
  14. data/data/ronin/gen/library/ChangeLog.md.erb +4 -0
  15. data/data/ronin/gen/library/Gemfile.erb +23 -0
  16. data/data/ronin/gen/library/README.md.erb +46 -0
  17. data/data/ronin/gen/library/Rakefile +30 -0
  18. data/data/ronin/gen/library/bin/ronin-command.erb +25 -0
  19. data/data/ronin/gen/library/bin/ronin-name.erb +27 -0
  20. data/data/ronin/gen/library/gemspec.yml.erb +20 -0
  21. data/data/ronin/gen/library/lib/ronin/_license.erb +19 -0
  22. data/data/ronin/gen/library/lib/ronin/gen/generators/generator.rb.erb +22 -0
  23. data/data/ronin/gen/library/lib/ronin/name.rb.erb +3 -0
  24. data/data/ronin/gen/library/lib/ronin/name/version.rb.erb +8 -0
  25. data/data/ronin/gen/library/lib/ronin/ui/command_line/commands/command.rb.erb +22 -0
  26. data/data/ronin/gen/library/library.gemspec.erb +10 -0
  27. data/data/ronin/gen/library/spec/name/name_spec.rb.erb +8 -0
  28. data/data/ronin/gen/library/spec/spec_helper.rb.erb +4 -0
  29. data/data/ronin/gen/repository/.rspec +1 -0
  30. data/data/ronin/gen/repository/Rakefile.erb +32 -0
  31. data/data/ronin/gen/repository/ronin.yml.erb +18 -0
  32. data/{static/ronin/generators/platform → data/ronin/gen/repository}/spec/spec_helper.rb +0 -0
  33. data/gemspec.yml +24 -0
  34. data/lib/ronin/gen.rb +26 -0
  35. data/lib/ronin/{ui/command_line/commands/gen_overlay.rb → gen/config.rb} +6 -8
  36. data/lib/ronin/{generators → gen}/dir_generator.rb +25 -21
  37. data/lib/ronin/{generators.rb → gen/exceptions.rb} +2 -5
  38. data/lib/ronin/{generators/platform/static.rb → gen/exceptions/unknown_generator.rb} +3 -6
  39. data/lib/ronin/gen/file_generator.rb +73 -0
  40. data/lib/ronin/gen/gen.rb +85 -0
  41. data/lib/ronin/gen/generatable.rb +36 -0
  42. data/lib/ronin/gen/generator.rb +312 -0
  43. data/lib/ronin/{ui/command_line/commands/gen_extension.rb → gen/generators.rb} +8 -9
  44. data/lib/ronin/gen/generators/library.rb +196 -0
  45. data/lib/ronin/gen/generators/repository.rb +130 -0
  46. data/lib/ronin/gen/ruby_generator.rb +34 -0
  47. data/lib/ronin/gen/source_code_generator.rb +46 -0
  48. data/lib/ronin/{generators → gen}/version.rb +3 -3
  49. data/lib/ronin/ui/{command_line → cli}/commands/gen.rb +18 -19
  50. data/ronin-gen.gemspec +10 -0
  51. data/spec/gen/classes/basic_generator.rb +16 -0
  52. data/spec/gen/classes/dir_generator.rb +9 -0
  53. data/spec/{generators → gen}/classes/file_generator.rb +2 -2
  54. data/spec/{generators → gen}/classes/templated_generator.rb +3 -3
  55. data/spec/gen/classes/touch_generator.rb +9 -0
  56. data/spec/gen/gen_spec.rb +22 -0
  57. data/spec/gen/generator_spec.rb +68 -0
  58. data/spec/gen/generators/library_spec.rb +132 -0
  59. data/spec/gen/generators/repository_spec.rb +92 -0
  60. data/spec/gen/helpers/data.rb +9 -0
  61. data/spec/{generators/helpers/static → gen/helpers/data}/generators/templated.txt.erb +0 -0
  62. data/spec/spec_helper.rb +3 -5
  63. metadata +190 -114
  64. data.tar.gz.sig +0 -0
  65. data/History.txt +0 -41
  66. data/Manifest.txt +0 -39
  67. data/bin/ronin-gen-extension +0 -12
  68. data/bin/ronin-gen-overlay +0 -12
  69. data/lib/ronin/generators/generator.rb +0 -165
  70. data/lib/ronin/generators/platform/extension.rb +0 -52
  71. data/lib/ronin/generators/platform/overlay.rb +0 -223
  72. data/spec/generated_extension_examples.rb +0 -27
  73. data/spec/generated_overlay_examples.rb +0 -72
  74. data/spec/generators/classes/dir_generator.rb +0 -9
  75. data/spec/generators/classes/touch_generator.rb +0 -9
  76. data/spec/generators/generator_spec.rb +0 -50
  77. data/spec/generators/generators_spec.rb +0 -9
  78. data/spec/generators/helpers/generators.rb +0 -3
  79. data/spec/generators/platform/extension_spec.rb +0 -22
  80. data/spec/generators/platform/overlay_spec.rb +0 -36
  81. data/spec/ui/command_line/commands/gen_extension_spec.rb +0 -22
  82. data/spec/ui/command_line/commands/gen_overlay_spec.rb +0 -38
  83. data/static/ronin/generators/platform/Rakefile.erb +0 -5
  84. data/static/ronin/generators/platform/extension.rb +0 -9
  85. data/tasks/spec.rb +0 -10
  86. data/tasks/yard.rb +0 -13
  87. metadata.gz.sig +0 -0
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
-
5
- lib_dir = File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
6
- unless $LOAD_PATH.include?(lib_dir)
7
- $LOAD_PATH << lib_dir
8
- end
9
-
10
- require 'ronin/ui/command_line/commands/gen_extension'
11
-
12
- Ronin::UI::CommandLine::Commands::GenExtension.start
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
-
5
- lib_dir = File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
6
- unless $LOAD_PATH.include?(lib_dir)
7
- $LOAD_PATH << lib_dir
8
- end
9
-
10
- require 'ronin/ui/command_line/commands/gen_overlay'
11
-
12
- Ronin::UI::CommandLine::Commands::GenOverlay.start
@@ -1,165 +0,0 @@
1
- #
2
- # Ronin Gen - A Ruby library for Ronin that provides various generators.
3
- #
4
- # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at example.com)
5
- #
6
- # This program is free software; you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # This program is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
- #
20
-
21
- require 'ronin/templates/template'
22
- require 'ronin/static/finders'
23
-
24
- require 'extlib'
25
- require 'erb'
26
- require 'thor'
27
-
28
- module Ronin
29
- module Generators
30
- class Generator < Thor::Group
31
-
32
- include Thor::Actions
33
- include Templates::Template
34
- include Static::Finders
35
-
36
- def self.inherited(super_class)
37
- class_name = super_class.name.split('::').last.snake_case
38
- super_class.namespace("ronin #{class_name}")
39
- end
40
-
41
- #
42
- # Defines the default source root of the generator as the current
43
- # working directory.
44
- #
45
- # @since 0.2.0
46
- #
47
- def self.source_root
48
- Dir.pwd
49
- end
50
-
51
- #
52
- # Invokes the generator.
53
- #
54
- # @param [Hash] options
55
- # Class options to use with the generator.
56
- #
57
- # @param [Array] arguments
58
- # Additional arguments for the generator.
59
- #
60
- # @example
61
- # gen.generate
62
- #
63
- # @since 0.2.0
64
- #
65
- def self.generate(options={},arguments=[])
66
- generator = self.new(arguments, options)
67
- generator.invoke()
68
- end
69
-
70
- desc "default generator task"
71
-
72
- #
73
- # Default generator method.
74
- #
75
- # @since 0.2.0
76
- #
77
- def generate
78
- end
79
-
80
- protected
81
-
82
- #
83
- # Touches a file.
84
- #
85
- # @param [String] destination
86
- # The relative path to the file to touch.
87
- #
88
- # @example
89
- # touch 'TODO.txt'
90
- #
91
- # @since 0.2.0
92
- #
93
- def touch(destination)
94
- create_file(destination)
95
- end
96
-
97
- #
98
- # Creates an empty directory.
99
- #
100
- # @param [String] destination
101
- # The relative path of the directory to create.
102
- #
103
- # @example
104
- # directory 'sub/dir'
105
- #
106
- # @since 0.2.0
107
- #
108
- def mkdir(destination)
109
- empty_directory(destination)
110
- end
111
-
112
- #
113
- # Copies a static-file.
114
- #
115
- # @param [String] static_file
116
- # The relative path to the static file.
117
- #
118
- # @param [String] destination
119
- # The destination to copy the static file to.
120
- #
121
- # @example
122
- # copy_file 'ronin/platform/generators/extension.rb',
123
- # 'myext/extension.rb'
124
- #
125
- # @since 0.2.0
126
- #
127
- def copy_file(static_file,destination)
128
- super(find_static_file(static_file),destination)
129
- end
130
-
131
- #
132
- # Renders the ERB template at the specified _template_path_ and
133
- # saves the result at the given _destination_.
134
- #
135
- # @param [String] template_path
136
- # The relative path to the template.
137
- #
138
- # @param [String, nil] destination
139
- # The destination to write the result of the rendered template to.
140
- #
141
- # @return [nil, String]
142
- # If destination is +nil+, the result of the rendered template
143
- # will be returned.
144
- #
145
- # @example
146
- # template 'ronin/platform/generators/Rakefile.erb', 'Rakefile.erb'
147
- #
148
- # @example
149
- # template '_helpers.erb'
150
- #
151
- # @since 0.2.0
152
- #
153
- def template(template_path,destination=nil)
154
- enter_template(template_path) do |path|
155
- if destination
156
- super(path,destination)
157
- else
158
- ERB.new(File.read(path)).result(binding).chomp
159
- end
160
- end
161
- end
162
-
163
- end
164
- end
165
- end
@@ -1,52 +0,0 @@
1
- #
2
- # Ronin Gen - A Ruby library for Ronin that provides various generators.
3
- #
4
- # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
5
- #
6
- # This program is free software; you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # This program is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
- #
20
-
21
- require 'ronin/generators/platform/static'
22
- require 'ronin/generators/dir_generator'
23
- require 'ronin/platform/extension'
24
-
25
- module Ronin
26
- module Generators
27
- module Platform
28
- class Extension < DirGenerator
29
-
30
- # The lib/ directory of the extension
31
- LIB_DIR = Ronin::Platform::Extension::LIB_DIR
32
-
33
- # The default extension file
34
- EXTENSION_FILE = File.join('ronin','generators','platform','extension.rb')
35
-
36
- #
37
- # Generates a skeleton Extension.
38
- #
39
- def generate
40
- name = File.basename(self.path)
41
-
42
- mkdir LIB_DIR
43
- touch File.join(LIB_DIR,name + '.rb')
44
- mkdir File.join(LIB_DIR,name)
45
-
46
- copy_file EXTENSION_FILE, Ronin::Platform::Extension::EXTENSION_FILE
47
- end
48
-
49
- end
50
- end
51
- end
52
- end
@@ -1,223 +0,0 @@
1
- #
2
- # Ronin Gen - A Ruby library for Ronin that provides various generators.
3
- #
4
- # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
5
- #
6
- # This program is free software; you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # This program is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
- #
20
-
21
- require 'ronin/generators/platform/static'
22
- require 'ronin/generators/dir_generator'
23
- require 'ronin/platform/overlay'
24
- require 'ronin/version'
25
-
26
- require 'nokogiri'
27
- require 'set'
28
-
29
- module Ronin
30
- module Generators
31
- module Platform
32
- class Overlay < DirGenerator
33
-
34
- include Nokogiri
35
-
36
- # The Overlay metadata file
37
- METADATA_FILE = Ronin::Platform::Overlay::METADATA_FILE
38
-
39
- # The Overlay metadata XSL URL
40
- METADATA_XSL = File.join('ronin','platform','overlay.xsl')
41
-
42
- # The Overlay lib directory
43
- LIB_DIR = Ronin::Platform::Overlay::LIB_DIR
44
-
45
- # The Overlay objects directory
46
- OBJECTS_DIR = Ronin::Platform::Overlay::OBJECTS_DIR
47
-
48
- # Default license to use
49
- DEFAULT_LICENSE = 'CC-by'
50
-
51
- # Default maintainer to use
52
- DEFAULT_MAINTAINER = {'Name' => 'name@example.com'}
53
-
54
- # Default description to use
55
- DEFAULT_DESCRIPTION = 'This is an Overlay'
56
-
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
88
-
89
- super(*names,&block)
90
- end
91
- end
92
-
93
- #
94
- # Generates a skeleton Overlay.
95
- #
96
- def generate
97
- mkdir 'static'
98
-
99
- inside File.join('static','ronin','platform') do
100
- copy_file METADATA_XSL, File.basename(METADATA_XSL)
101
- end
102
-
103
- mkdir LIB_DIR
104
- touch File.join(LIB_DIR,Ronin::Platform::Overlay::INIT_FILE)
105
-
106
- mkdir OBJECTS_DIR
107
- mkdir 'tasks'
108
- end
109
-
110
- #
111
- # Generates the Rakefile of the Overlay.
112
- #
113
- def rakefile
114
- case @test_suite
115
- when 'rspec', 'spec'
116
- @tasks << 'spec' unless @tasks.include?('spec')
117
- end
118
-
119
- template File.join('ronin','generators','platform','Rakefile.erb'), 'Rakefile'
120
- end
121
-
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'
132
- end
133
- end
134
-
135
- #
136
- # Generates the XML metadata file for the Overlay.
137
- #
138
- def metadata
139
- create_file(METADATA_FILE) do
140
- doc = XML::Document.new
141
- doc << XML::ProcessingInstruction.new(
142
- doc,
143
- 'xml-stylesheet',
144
- "type=\"text/xsl\" href=\"static/#{METADATA_XSL}\""
145
- )
146
-
147
- root = XML::Node.new('ronin-overlay',doc)
148
- root['version'] = Ronin::VERSION
149
-
150
- title_tag = XML::Node.new('title',doc)
151
- title_tag << XML::Text.new(@title,doc)
152
- root << title_tag
153
-
154
- if options[:source]
155
- source_tag = XML::Node.new('source',doc)
156
- source_tag << XML::Text.new(@source,doc)
157
- root << source_tag
158
- end
159
-
160
- if @source_view
161
- source_view_tag = XML::Node.new('source-view',doc)
162
- source_view_tag << XML::Text.new(@source_view,doc)
163
- root << source_view_tag
164
- end
165
-
166
- if @website
167
- url_tag = XML::Node.new('website',doc)
168
- url_tag << XML::Text.new(@website,doc)
169
- root << url_tag
170
- end
171
-
172
- license_tag = XML::Node.new('license',doc)
173
- license_tag << XML::Text.new(@license,doc)
174
- root << license_tag
175
-
176
- maintainers_tag = XML::Node.new('maintainers',doc)
177
-
178
- @maintainers.each do |name,email|
179
- maintainer_tag = XML::Node.new('maintainer',doc)
180
-
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
186
-
187
- if email
188
- email_tag = XML::Node.new('email',doc)
189
- email_tag << XML::Text.new(email,doc)
190
- maintainer_tag << email_tag
191
- end
192
-
193
- maintainers_tag << maintainer_tag
194
- end
195
-
196
- root << maintainers_tag
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
-
211
- description_tag = XML::Node.new('description',doc)
212
- description_tag << XML::Text.new(@description,doc)
213
- root << description_tag
214
-
215
- doc << root
216
- doc.to_xml
217
- end
218
- end
219
-
220
- end
221
- end
222
- end
223
- end