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,7 +1,7 @@
1
1
  #
2
2
  # Ronin Gen - A Ruby library for Ronin that provides various generators.
3
3
  #
4
- # Copyright (c) 2009 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
5
  #
6
6
  # This program is free software; you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
@@ -18,31 +18,30 @@
18
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
19
  #
20
20
 
21
- require 'ronin/generators/version'
22
- require 'ronin/ui/command_line/command'
23
- require 'ronin/ui/command_line/command_line'
21
+ require 'ronin/ui/cli/command'
22
+ require 'ronin/gen/gen'
23
+ require 'ronin/gen/version'
24
24
 
25
25
  module Ronin
26
26
  module UI
27
- module CommandLine
27
+ module CLI
28
28
  module Commands
29
+ #
30
+ # Lists the available generators.
31
+ #
29
32
  class Gen < Command
30
33
 
31
- desc "version", "Prints the version and exists"
32
- def version
33
- puts "Ronin Gen #{Ronin::Generators::VERSION}"
34
- exit
35
- end
34
+ desc "Prints the list of available generators"
35
+ class_option :version, :type => :boolean
36
+
37
+ def execute
38
+ if options.version?
39
+ puts "ronin-gen #{Ronin::Gen::VERSION}"
40
+ return
41
+ end
36
42
 
37
- desc "default", "Prints the list of available generators"
38
- def default
39
- print_array CommandLine.commands.map { |name|
40
- if name =~ /^gen_/
41
- name.gsub(/^gen_/,'')
42
- else
43
- nil
44
- end
45
- }.compact.sort
43
+ print_title 'Available Generators'
44
+ print_array Ronin::Gen.generators.keys.sort
46
45
  end
47
46
 
48
47
  end
@@ -0,0 +1,10 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ begin
4
+ Ore::Specification.new do |gemspec|
5
+ # custom logic here
6
+ end
7
+ rescue NameError
8
+ STDERR.puts "The 'ronin-gen.gemspec' file requires Ore."
9
+ STDERR.puts "Run `gem install ore` to install Ore."
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'ronin/gen/generator'
2
+
3
+ class BasicGenerator < Gen::Generator
4
+
5
+ attr_reader :var
6
+
7
+ def generate
8
+ end
9
+
10
+ protected
11
+
12
+ def setup
13
+ @var = 'test'
14
+ end
15
+
16
+ end
@@ -0,0 +1,9 @@
1
+ require 'ronin/gen/dir_generator'
2
+
3
+ class DirGenerator < Gen::Generator
4
+
5
+ def generate
6
+ mkdir 'test'
7
+ end
8
+
9
+ end
@@ -1,6 +1,6 @@
1
- require 'ronin/generators/generator'
1
+ require 'ronin/gen/generator'
2
2
 
3
- class FileGenerator < Generators::Generator
3
+ class FileGenerator < Gen::Generator
4
4
 
5
5
  def generate
6
6
  create_file('test.txt') do
@@ -1,13 +1,13 @@
1
- require 'ronin/generators/generator'
1
+ require 'ronin/gen/generator'
2
2
 
3
- class TemplatedGenerator < Generators::Generator
3
+ class TemplatedGenerator < Gen::Generator
4
4
 
5
5
  TEMPLATE_FILE = File.join('generators','templated.txt.erb')
6
6
 
7
7
  class_option :message, :type => :string
8
8
 
9
9
  def generate
10
- template TEMPLATE_FILE, 'templated.txt'
10
+ erb TEMPLATE_FILE, 'templated.txt'
11
11
  end
12
12
 
13
13
  end
@@ -0,0 +1,9 @@
1
+ require 'ronin/gen/generator'
2
+
3
+ class TouchGenerator < Gen::Generator
4
+
5
+ def generate
6
+ touch('test2.txt')
7
+ end
8
+
9
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'ronin/gen/gen'
3
+ require 'ronin/gen/version'
4
+
5
+ describe Gen do
6
+ it "should have a version" do
7
+ subject.const_defined?('VERSION').should == true
8
+ end
9
+
10
+ it "should load generators from 'ronin/gen/generators'" do
11
+ generator = subject.generator('library')
12
+
13
+ generator.should_not be_nil
14
+ generator.name.should == 'Ronin::Gen::Generators::Library'
15
+ end
16
+
17
+ it "should raise an UnknownGenerator exception on missing generators" do
18
+ lambda {
19
+ subject.generator('lolbadfail')
20
+ }.should raise_error(Gen::UnknownGenerator)
21
+ end
22
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'ronin/gen/generator'
3
+
4
+ require 'gen/helpers/data'
5
+ require 'gen/classes/basic_generator'
6
+ require 'gen/classes/file_generator'
7
+ require 'gen/classes/touch_generator'
8
+ require 'gen/classes/dir_generator'
9
+ require 'gen/classes/templated_generator'
10
+ require 'tmpdir'
11
+ require 'fileutils'
12
+
13
+ describe Gen::Generator do
14
+ it "should include Thor::Actions" do
15
+ Gen::Generator.should include(Thor::Actions)
16
+ end
17
+
18
+ describe "setup" do
19
+ subject { BasicGenerator.new }
20
+
21
+ before(:all) do
22
+ subject.invoke_all
23
+ end
24
+
25
+ it "should set default values before invoking any tasks" do
26
+ subject.var.should == 'test'
27
+ end
28
+ end
29
+
30
+ describe "actions" do
31
+ before(:all) do
32
+ @previous_dir = Dir.pwd
33
+ @dir = File.join(Dir.tmpdir,'ronin_generators')
34
+
35
+ FileUtils.mkdir(@dir)
36
+ Dir.chdir(@dir)
37
+ end
38
+
39
+ it "should generate files" do
40
+ FileGenerator.generate
41
+
42
+ File.read(File.join(@dir,'test.txt')).should == "hello"
43
+ end
44
+
45
+ it "should touch files" do
46
+ TouchGenerator.generate
47
+
48
+ File.file?(File.join(@dir,'test2.txt')).should == true
49
+ end
50
+
51
+ it "should generate directories" do
52
+ DirGenerator.generate
53
+
54
+ File.directory?(File.join(@dir,'test')).should == true
55
+ end
56
+
57
+ it "should generate files using templates" do
58
+ TemplatedGenerator.generate(:message => 'hello')
59
+
60
+ File.read(File.join(@dir,'templated.txt')).should == "message: hello\n"
61
+ end
62
+
63
+ after(:all) do
64
+ FileUtils.rm_r(@dir)
65
+ Dir.chdir(@previous_dir)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+ require 'ronin/gen/generators/library'
3
+
4
+ require 'pathname'
5
+ require 'tmpdir'
6
+
7
+ describe Gen::Generators::Library do
8
+ context "defaults" do
9
+ let(:path) { Pathname.new(Dir.tmpdir).join('ronin-name') }
10
+
11
+ before(:all) do
12
+ Gen::Generators::Library.generate(path)
13
+ end
14
+
15
+ it "should initialize a git repository" do
16
+ path.join('.git').should be_directory
17
+ end
18
+
19
+ it "should create a bin/ directory" do
20
+ path.join('bin').should be_directory
21
+ end
22
+
23
+ it "should create a lib/ directory" do
24
+ path.join('lib').should be_directory
25
+ end
26
+
27
+ it "should create a lib/ronin directory" do
28
+ path.join('lib','ronin').should be_directory
29
+ end
30
+
31
+ it "should create a lib/ronin/name.rb directory" do
32
+ path.join('lib','ronin','name.rb').should be_file
33
+ end
34
+
35
+ it "should create a lib/ronin/name directory" do
36
+ path.join('lib','ronin','name').should be_directory
37
+ end
38
+
39
+ it "should create a lib/ronin/name/version.rb file" do
40
+ path.join('lib','ronin','name','version.rb').should be_file
41
+ end
42
+
43
+ it "should create a data/ directory" do
44
+ path.join('data').should be_directory
45
+ end
46
+
47
+ it "should create a spec/ directory" do
48
+ path.join('spec').should be_directory
49
+ end
50
+
51
+ it "should create a spec/spec_helper.rb file" do
52
+ path.join('spec','spec_helper.rb').should be_file
53
+ end
54
+
55
+ it "should create a spec/name directory" do
56
+ path.join('spec','name').should be_directory
57
+ end
58
+
59
+ it "should create a spec/name/name_spec.rb file" do
60
+ path.join('spec','name','name_spec.rb').should be_file
61
+ end
62
+
63
+ it "should create a COPYING.txt file" do
64
+ path.join('COPYING.txt').should be_file
65
+ end
66
+
67
+ it "should create a README.md file" do
68
+ path.join('README.md').should be_file
69
+ end
70
+
71
+ it "should create a ChangeLog.md file" do
72
+ path.join('ChangeLog.md').should be_file
73
+ end
74
+
75
+ it "should create a Gemfile" do
76
+ path.join('Gemfile').should be_file
77
+ end
78
+
79
+ it "should create a Rakefile" do
80
+ path.join('Rakefile').should be_file
81
+ end
82
+
83
+ it "should create a .rspec file" do
84
+ path.join('.rspec').should be_file
85
+ end
86
+
87
+ it "should create a .yardopts file" do
88
+ path.join('.yardopts').should be_file
89
+ end
90
+
91
+ after(:all) do
92
+ path.rmtree
93
+ end
94
+ end
95
+
96
+ context "custom path and name" do
97
+ let(:name) { 'ronin-name' }
98
+ let(:path) { Pathname.new(Dir.tmpdir).join('ronin-library') }
99
+
100
+ before(:all) do
101
+ Gen::Generators::Library.generate(path, {:name => name})
102
+ end
103
+
104
+ it "should create a lib/ronin/name.rb file" do
105
+ path.join('lib','ronin','name.rb').should be_file
106
+ end
107
+
108
+ it "should create a lib/ronin/name/ directory" do
109
+ path.join('lib','ronin','name').should be_directory
110
+ end
111
+
112
+ it "should create a lib/ronin/name/version.rb file" do
113
+ path.join('lib','ronin','name','version.rb').should be_file
114
+ end
115
+
116
+ it "should create a bin/ronin-name file" do
117
+ path.join('bin','ronin-name').should be_file
118
+ end
119
+
120
+ it "should create a spec/name directory" do
121
+ path.join('spec','name').should be_directory
122
+ end
123
+
124
+ it "should create a spec/name/name_spec.rb file" do
125
+ path.join('spec','name','name_spec.rb').should be_file
126
+ end
127
+
128
+ after(:all) do
129
+ path.rmtree
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+ require 'ronin/gen/generators/repository'
3
+
4
+ require 'pathname'
5
+ require 'tmpdir'
6
+
7
+ describe Gen::Generators::Repository do
8
+ let(:name) { 'ronin_generated_repo' }
9
+ let(:path) { Pathname.new(Dir.tmpdir).join(name) }
10
+ let(:title) { 'Test Repository' }
11
+ let(:uri) { 'ssh+svn://www.example.com/var/svn/test/' }
12
+ let(:source) { 'http://www.example.com/test/' }
13
+ let(:website) { 'http://www.example.com/blog/' }
14
+ let(:license) { 'GPL-2' }
15
+ let(:description) { 'This is a test repository' }
16
+
17
+ before(:all) do
18
+ Gen::Generators::Repository.generate(
19
+ path,
20
+ :title => title,
21
+ :uri => uri,
22
+ :source => source,
23
+ :website => website,
24
+ :license => license,
25
+ :description => description
26
+ )
27
+ end
28
+
29
+ it "should create the repository directory" do
30
+ path.should be_directory
31
+ end
32
+
33
+ it "should create a data/ directory" do
34
+ path.join('data').should be_directory
35
+ end
36
+
37
+ it "should create a lib/ directory" do
38
+ path.join(Ronin::Repository::LIB_DIR).should be_directory
39
+ end
40
+
41
+ it "should create a lib/ronin/ directory" do
42
+ path.join(Ronin::Repository::LIB_DIR,'ronin').should be_directory
43
+ end
44
+
45
+ it "should create a cache/ directory" do
46
+ path.join(Ronin::Repository::CACHE_DIR).should be_directory
47
+ end
48
+
49
+ it "should create a Rakefile" do
50
+ path.join('Rakefile').should be_file
51
+ end
52
+
53
+ it "should create a XML metadata file" do
54
+ path.join(Ronin::Repository::METADATA_FILE).should be_file
55
+ end
56
+
57
+ describe "metadata" do
58
+ subject { YAML.load_file(path.join(Ronin::Repository::METADATA_FILE)) }
59
+
60
+ it "should contain a Hash" do
61
+ subject.should be_kind_of(Hash)
62
+ end
63
+
64
+ it "should have the title" do
65
+ subject['title'].should == title
66
+ end
67
+
68
+ it "should have the repository URI" do
69
+ subject['uri'].should == uri
70
+ end
71
+
72
+ it "should have the source URL" do
73
+ subject['source'].should == source
74
+ end
75
+
76
+ it "should have the website URL" do
77
+ subject['website'].should == website
78
+ end
79
+
80
+ it "should have the license" do
81
+ subject['license'].should == license
82
+ end
83
+
84
+ it "should have the description" do
85
+ subject['description'].should == description
86
+ end
87
+ end
88
+
89
+ after(:all) do
90
+ path.rmtree
91
+ end
92
+ end