ronin-gen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/COPYING.txt +339 -0
  2. data/History.txt +9 -0
  3. data/Manifest.txt +37 -0
  4. data/README.txt +79 -0
  5. data/Rakefile +15 -0
  6. data/TODO.txt +3 -0
  7. data/bin/ronin-gen +16 -0
  8. data/bin/ronin-gen-extension +12 -0
  9. data/bin/ronin-gen-overlay +12 -0
  10. data/lib/ronin/generators.rb +26 -0
  11. data/lib/ronin/generators/dir_generator.rb +42 -0
  12. data/lib/ronin/generators/generator.rb +150 -0
  13. data/lib/ronin/generators/platform/extension.rb +56 -0
  14. data/lib/ronin/generators/platform/overlay.rb +229 -0
  15. data/lib/ronin/generators/platform/spec.rb +46 -0
  16. data/lib/ronin/generators/platform/static.rb +31 -0
  17. data/lib/ronin/generators/version.rb +28 -0
  18. data/lib/ronin/ui/command_line/commands/gen_extension.rb +56 -0
  19. data/lib/ronin/ui/command_line/commands/gen_overlay.rb +97 -0
  20. data/spec/generated_extension_examples.rb +27 -0
  21. data/spec/generated_overlay_examples.rb +66 -0
  22. data/spec/generators/generator_spec.rb +40 -0
  23. data/spec/generators/generators_spec.rb +9 -0
  24. data/spec/generators/helpers/generators.rb +7 -0
  25. data/spec/generators/helpers/generators/dir_generator.rb +11 -0
  26. data/spec/generators/helpers/generators/file_generator.rb +11 -0
  27. data/spec/generators/helpers/generators/templated_generator.rb +17 -0
  28. data/spec/generators/helpers/static/generators/templated.txt.erb +1 -0
  29. data/spec/generators/platform/extension_spec.rb +25 -0
  30. data/spec/generators/platform/overlay_spec.rb +38 -0
  31. data/spec/spec_helper.rb +7 -0
  32. data/spec/ui/command_line/commands/gen_extension_spec.rb +22 -0
  33. data/spec/ui/command_line/commands/gen_overlay_spec.rb +38 -0
  34. data/static/ronin/platform/generators/extension.rb +9 -0
  35. data/static/ronin/platform/generators/spec/spec_helper.rb +9 -0
  36. data/tasks/spec.rb +9 -0
  37. metadata +115 -0
@@ -0,0 +1,46 @@
1
+ #
2
+ #--
3
+ # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
+ #
5
+ # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ #++
21
+ #
22
+
23
+ require 'ronin/generators/generator'
24
+
25
+ module Ronin
26
+ module Generators
27
+ module Platform
28
+ class Spec < Generator
29
+
30
+ # The default spec_helper.rb file
31
+ SPEC_HELPER = File.join('ronin','platform','generators','spec','spec_helper.rb')
32
+
33
+ protected
34
+
35
+ #
36
+ # Generates a basic Spec test directory.
37
+ #
38
+ def generate!
39
+ directory 'spec'
40
+ copy SPEC_HELPER, 'spec'
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ #--
3
+ # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
+ #
5
+ # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at example.com)
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ #++
21
+ #
22
+
23
+ require 'ronin/static'
24
+
25
+ module Ronin
26
+ module Generators
27
+ module Platform
28
+ Static.directory File.join(File.dirname(__FILE__),'..','..','..','..','static')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ #
2
+ #--
3
+ # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
+ #
5
+ # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at example.com)
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ #++
21
+ #
22
+
23
+ module Ronin
24
+ module Generators
25
+ # Ronin Gen version
26
+ VERSION = '0.1.0'
27
+ end
28
+ end
@@ -0,0 +1,56 @@
1
+ #
2
+ #--
3
+ # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
+ #
5
+ # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ #++
21
+ #
22
+
23
+ require 'ronin/ui/command_line/command'
24
+ require 'ronin/generators/platform/extension'
25
+
26
+ module Ronin
27
+ module UI
28
+ module CommandLine
29
+ 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
51
+
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,97 @@
1
+ #
2
+ #--
3
+ # Ronin Gen - A Ruby library for Ronin that provides various generators.
4
+ #
5
+ # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ #++
21
+ #
22
+
23
+ require 'ronin/ui/command_line/command'
24
+ require 'ronin/generators/platform/overlay'
25
+
26
+ module Ronin
27
+ module UI
28
+ module CommandLine
29
+ 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
92
+
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,27 @@
1
+ require 'ronin/platform/extension'
2
+
3
+ require 'spec_helper'
4
+
5
+ shared_examples_for "Generated Extension" do
6
+
7
+ before(:all) do
8
+ @lib_dir = File.join(@path,Ronin::Platform::Extension::LIB_DIR)
9
+ end
10
+
11
+ it "should create the extension directory" do
12
+ File.directory?(@path).should == true
13
+ end
14
+
15
+ it "should create a lib/ directory" do
16
+ File.directory?(@lib_dir).should == true
17
+ end
18
+
19
+ it "should create an empty load file in the lib/ directory" do
20
+ File.file?(File.join(@lib_dir,@name + '.rb')).should == true
21
+ end
22
+
23
+ it "should create an empty directory within the lib/ directory" do
24
+ File.directory?(File.join(@lib_dir,@name)).should == true
25
+ end
26
+
27
+ end
@@ -0,0 +1,66 @@
1
+ require 'ronin/platform/overlay'
2
+
3
+ require 'spec_helper'
4
+ require 'nokogiri'
5
+
6
+ shared_examples_for "Generated Overlay" do
7
+
8
+ it "should create the overlay directory" do
9
+ File.directory?(@path).should == true
10
+ end
11
+
12
+ it "should create a lib directory" do
13
+ lib_dir = File.join(@path,Ronin::Platform::Overlay::LIB_DIR)
14
+
15
+ File.directory?(lib_dir).should == true
16
+ end
17
+
18
+ it "should create a objects directory" do
19
+ objects_dir = File.join(@path,Ronin::Platform::Overlay::OBJECTS_DIR)
20
+
21
+ File.directory?(objects_dir).should == true
22
+ end
23
+
24
+ it "should create a Rakefile" do
25
+ rakefile = File.join(@path,'Rakefile')
26
+
27
+ File.file?(rakefile).should == true
28
+ end
29
+
30
+ it "should create a XML metadata file" do
31
+ metadata_file = File.join(@path,Ronin::Platform::Overlay::METADATA_FILE)
32
+
33
+ File.file?(metadata_file).should == true
34
+ end
35
+
36
+ describe "XML metadata file" do
37
+ before(:all) do
38
+ @doc = Nokogiri::XML(open(File.join(@path,Ronin::Platform::Overlay::METADATA_FILE)))
39
+ end
40
+
41
+ it "should have the title" do
42
+ @doc.at('/ronin-overlay/title').inner_text.should == @title
43
+ end
44
+
45
+ it "should have the source URL" do
46
+ @doc.at('/ronin-overlay/source').inner_text.should == @source
47
+ end
48
+
49
+ it "should have the source-view URL" do
50
+ @doc.at('/ronin-overlay/source-view').inner_text.should == @source_view
51
+ end
52
+
53
+ it "should have the website URL" do
54
+ @doc.at('/ronin-overlay/website').inner_text.should == @website
55
+ end
56
+
57
+ it "should have the license" do
58
+ @doc.at('/ronin-overlay/license').inner_text.should == @license
59
+ end
60
+
61
+ it "should have the description" do
62
+ @doc.at('/ronin-overlay/description').inner_text.should == @description
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,40 @@
1
+ require 'ronin/generators/generator'
2
+
3
+ require 'spec_helper'
4
+ require 'generators/helpers/generators'
5
+
6
+ require 'tmpdir'
7
+ require 'fileutils'
8
+
9
+ describe Generators::Generator do
10
+ before(:all) do
11
+ @dir = File.join(Dir.tmpdir,'ronin_generators')
12
+
13
+ FileUtils.mkdir(@dir)
14
+ end
15
+
16
+ it "should generate files" do
17
+ generator = FileGenerator.new
18
+ generator.run(@dir)
19
+
20
+ File.read(File.join(@dir,'test.txt')).should == "hello\n"
21
+ end
22
+
23
+ it "should generate directories" do
24
+ generator = DirGenerator.new
25
+ generator.run(@dir)
26
+
27
+ File.directory?(File.join(@dir,'test')).should == true
28
+ end
29
+
30
+ it "should generate files using templates" do
31
+ generator = TemplatedGenerator.new('hello')
32
+ generator.run(@dir)
33
+
34
+ File.read(File.join(@dir,'templated.txt')).should == "message: hello\n"
35
+ end
36
+
37
+ after(:all) do
38
+ FileUtils.rm_r(@dir)
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ require 'ronin/generators/version'
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Generators do
6
+ it "should have a version" do
7
+ Generators.const_defined?('VERSION').should == true
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'ronin/static/static'
2
+
3
+ require 'generators/helpers/generators/file_generator'
4
+ require 'generators/helpers/generators/dir_generator'
5
+ require 'generators/helpers/generators/templated_generator'
6
+
7
+ Static.directory File.join(File.dirname(__FILE__),'static')
@@ -0,0 +1,11 @@
1
+ require 'ronin/generators/generator'
2
+
3
+ class DirGenerator < Generators::Generator
4
+
5
+ protected
6
+
7
+ def generate!
8
+ directory 'test'
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'ronin/generators/generator'
2
+
3
+ class FileGenerator < Generators::Generator
4
+
5
+ protected
6
+
7
+ def generate!
8
+ file('test.txt') { |test| test.puts("hello") }
9
+ end
10
+
11
+ end