newgem 0.11.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +42 -0
- data/Manifest.txt +84 -17
- data/README.txt +3 -2
- data/Rakefile +4 -106
- data/Todo.txt +1 -1
- data/app_generators/newgem/newgem_generator.rb +172 -0
- data/{templates → app_generators/newgem/templates}/History.txt +1 -1
- data/{templates → app_generators/newgem/templates}/License.txt +1 -1
- data/app_generators/newgem/templates/README.txt +1 -0
- data/app_generators/newgem/templates/Rakefile +4 -0
- data/{templates → app_generators/newgem/templates}/app.rb +3 -3
- data/app_generators/newgem/templates/config/hoe.rb +73 -0
- data/app_generators/newgem/templates/config/requirements.rb +17 -0
- data/app_generators/newgem/templates/empty.log +0 -0
- data/app_generators/newgem/templates/module.rb +5 -0
- data/app_generators/newgem/templates/script/destroy +14 -0
- data/app_generators/newgem/templates/script/generate +14 -0
- data/{templates → app_generators/newgem/templates}/setup.rb +0 -0
- data/{templates → app_generators/newgem/templates}/spec.opts +0 -0
- data/{templates → app_generators/newgem/templates}/spec.rb +0 -0
- data/app_generators/newgem/templates/tasks/deployment.rake +27 -0
- data/app_generators/newgem/templates/tasks/environment.rake +7 -0
- data/app_generators/newgem/templates/tasks/website.rake +9 -0
- data/{templates → app_generators/newgem/templates}/test.rb +1 -1
- data/app_generators/newgem/templates/test_helper.rb +2 -0
- data/app_generators/newgem/templates/version.rb +9 -0
- data/bin/newgem +9 -272
- data/bundles/RubyGem.tmbundle/Snippets/History header trunk.tmSnippet +18 -0
- data/bundles/RubyGem.tmbundle/Snippets/History header.tmSnippet +18 -0
- data/bundles/RubyGem.tmbundle/Syntaxes/Rdoc.tmLanguage +70 -0
- data/bundles/RubyGem.tmbundle/info.plist +16 -0
- data/config/hoe.rb +48 -0
- data/config/svn_branch.rb +15 -0
- data/lib/newgem.rb +2 -3
- data/lib/newgem/quick_template.rb +28 -0
- data/lib/newgem/tasks.rb +1 -0
- data/lib/newgem/version.rb +1 -1
- data/newgem_generators/install_website/USAGE +5 -0
- data/newgem_generators/install_website/install_website_generator.rb +76 -0
- data/{templates/scripts → newgem_generators/install_website/templates/script}/txt2html +15 -8
- data/newgem_generators/install_website/templates/tasks/website.rake +17 -0
- data/{templates → newgem_generators/install_website/templates}/website/index.html +2 -2
- data/newgem_generators/install_website/templates/website/index.txt +39 -0
- data/newgem_theme_generators/plain/USAGE +5 -0
- data/newgem_theme_generators/plain/plain_generator.rb +54 -0
- data/{templates → newgem_theme_generators/plain/templates}/website/javascripts/rounded_corners_lite.inc.js +0 -0
- data/{templates → newgem_theme_generators/plain/templates}/website/stylesheets/screen.css +0 -0
- data/{templates → newgem_theme_generators/plain/templates}/website/template.rhtml +6 -6
- data/rubygems_generators/application_generator/USAGE +28 -0
- data/rubygems_generators/application_generator/application_generator_generator.rb +58 -0
- data/rubygems_generators/application_generator/templates/bin +12 -0
- data/rubygems_generators/application_generator/templates/generator.rb +51 -0
- data/rubygems_generators/application_generator/templates/readme +24 -0
- data/rubygems_generators/application_generator/templates/test.rb +43 -0
- data/rubygems_generators/application_generator/templates/test_generator_helper.rb +19 -0
- data/rubygems_generators/application_generator/templates/usage +5 -0
- data/rubygems_generators/component_generator/USAGE +29 -0
- data/rubygems_generators/component_generator/component_generator_generator.rb +52 -0
- data/rubygems_generators/component_generator/templates/generator.rb +51 -0
- data/rubygems_generators/component_generator/templates/readme +28 -0
- data/rubygems_generators/component_generator/templates/test.rb +43 -0
- data/rubygems_generators/component_generator/templates/test_generator_helper.rb +19 -0
- data/rubygems_generators/component_generator/templates/usage +5 -0
- data/rubygems_generators/executable/executable_generator.rb +53 -0
- data/rubygems_generators/executable/templates/app.rb +44 -0
- data/rubygems_generators/install_jruby/USAGE +5 -0
- data/rubygems_generators/install_jruby/install_jruby_generator.rb +48 -0
- data/rubygems_generators/install_jruby/templates/tasks/jruby.rake +7 -0
- data/rubygems_generators/install_rspec/USAGE +5 -0
- data/rubygems_generators/install_rspec/install_rspec_generator.rb +55 -0
- data/rubygems_generators/install_rspec/templates/spec.rb +11 -0
- data/rubygems_generators/install_rspec/templates/spec/spec.opts +1 -0
- data/rubygems_generators/install_rspec/templates/spec/spec_helper.rb +7 -0
- data/rubygems_generators/install_rspec/templates/tasks/rspec.rake +21 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/{scripts → script}/txt2html +3 -3
- data/{scripts → script}/txt2js +0 -0
- data/tasks/bundles.rake +12 -0
- data/tasks/deployment.rake +27 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +19 -0
- data/test/test_application_generator_generator.rb +60 -0
- data/test/test_executable_generator.rb +28 -0
- data/test/test_generate_component_generator.rb +67 -0
- data/test/test_generator_helper.rb +19 -0
- data/test/test_install_jruby_generator.rb +29 -0
- data/test/test_install_rspec_generator.rb +33 -0
- data/test/test_install_website_generator.rb +50 -0
- data/test/test_newgem_generator.rb +120 -0
- data/test/test_plain_generator.rb +37 -0
- data/website/images/beginning-ruby.jpg +0 -0
- data/website/index.html +8 -6
- data/website/index.txt +4 -2
- data/website/rubyforge.html +3 -3
- data/website/version-raw.js +1 -1
- data/website/version.js +1 -1
- metadata +111 -27
- data/templates/Manifest.txt +0 -15
- data/templates/Rakefile +0 -123
- data/templates/website/index.txt +0 -38
- data/test/test_svn.rb +0 -13
@@ -0,0 +1,54 @@
|
|
1
|
+
class PlainGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
default_options :author => "TODO",
|
4
|
+
:email => "todo@todo.com"
|
5
|
+
|
6
|
+
attr_reader :author, :email
|
7
|
+
|
8
|
+
def initialize(runtime_args, runtime_options = {})
|
9
|
+
super
|
10
|
+
extract_options
|
11
|
+
end
|
12
|
+
|
13
|
+
def manifest
|
14
|
+
record do |m|
|
15
|
+
# Ensure appropriate folder(s) exists
|
16
|
+
m.directory 'website/javascripts'
|
17
|
+
m.directory 'website/stylesheets'
|
18
|
+
|
19
|
+
# Website
|
20
|
+
m.template_copy_each %w( template.rhtml ), "website"
|
21
|
+
m.file_copy_each %w( stylesheets/screen.css javascripts/rounded_corners_lite.inc.js ), "website"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
def banner
|
27
|
+
<<-EOS
|
28
|
+
Installs the plain blue-ish website theme for newgem's website framework.
|
29
|
+
|
30
|
+
USAGE: #{$0} #{spec.name}"
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_options!(opts)
|
35
|
+
opts.separator ''
|
36
|
+
opts.separator 'Options:'
|
37
|
+
# For each option below, place the default
|
38
|
+
# at the top of the file next to "default_options"
|
39
|
+
opts.on("-a", "--author=\"Your Name\"", String,
|
40
|
+
"You. The author of this RubyGem. You name goes in in the website.",
|
41
|
+
"Default: 'TODO'") { |options[:author]| }
|
42
|
+
opts.on("-e", "--email=your@email.com", String,
|
43
|
+
"Your email for people to contact you.",
|
44
|
+
"Default: nil") { |options[:author]| }
|
45
|
+
end
|
46
|
+
|
47
|
+
def extract_options
|
48
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
49
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
50
|
+
# raw instance variable value.
|
51
|
+
@author = options[:author]
|
52
|
+
@email = options[:email]
|
53
|
+
end
|
54
|
+
end
|
File without changes
|
File without changes
|
@@ -5,7 +5,7 @@
|
|
5
5
|
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
6
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
7
|
<title>
|
8
|
-
|
8
|
+
<%%= title %>
|
9
9
|
</title>
|
10
10
|
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
11
|
<style>
|
@@ -30,14 +30,14 @@
|
|
30
30
|
<body>
|
31
31
|
<div id="main">
|
32
32
|
|
33
|
-
<h1
|
34
|
-
<div id="version" class="clickable" onclick='document.location = "
|
33
|
+
<h1><%%= title %></h1>
|
34
|
+
<div id="version" class="clickable" onclick='document.location = "<%%= download %>"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="
|
36
|
+
<a href="<%%= download %>" class="numbers"><%%= version %></a>
|
37
37
|
</div>
|
38
|
-
|
38
|
+
<%%= body %>
|
39
39
|
<p class="coda">
|
40
|
-
<a href="
|
40
|
+
<a href="<%= email %>"><%= author %></a>, <%%= modified.pretty %><br>
|
41
41
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
42
42
|
</p>
|
43
43
|
</div>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
How to create an Application Generator
|
2
|
+
======================================
|
3
|
+
|
4
|
+
1. Create a new RubyGem (using newgem or hoe) or you can use an existing one.
|
5
|
+
2. Run the generator: script/generate application_generator foobar
|
6
|
+
3. Using the generated test class, assert what directories, files, classes etc should
|
7
|
+
be generated.
|
8
|
+
4. Add these files into the app_genearators/foobar/templates folder. Your files can use
|
9
|
+
ERb (that is, <%= ... %>).
|
10
|
+
5. Specify who the files in /templates are copied/templated at generation time within app_generators/foobar/foobar_generators.rb 's #manifest method.
|
11
|
+
Use m.file for files to copy over.
|
12
|
+
Use m.template for files containing ERb. Create attr_reader accessors for any variables your
|
13
|
+
templates need access to.
|
14
|
+
6. Run unit tests.
|
15
|
+
7. If your application generator uses other generators (m.dependency "gen-name", [arg1, arg2], :option1 => 'value')
|
16
|
+
then you must add this into the generated bin/foobar file.
|
17
|
+
For example, if you wanted to use a rubygems and/or merb generator, then replace the use_application_sources!
|
18
|
+
call in bin/foobar:
|
19
|
+
|
20
|
+
RubiGen::Base.use_application_sources! :rubygems, :merb
|
21
|
+
|
22
|
+
Without this, RubiGen will not be able to find your dependent generators.
|
23
|
+
8. Update your Manifest.txt with the new files (if you are using Hoe; using newgem? it uses Hoe; so you need to do this)
|
24
|
+
9. Build and install your RubyGem locally. Run: rake install_gem
|
25
|
+
10. Test your foobar application to ensure that it connects to the generator correctly and generates files.
|
26
|
+
11. Done.
|
27
|
+
|
28
|
+
You will see this message again after running the generator and by using the -h/--help option.
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class ApplicationGeneratorGenerator < RubiGen::Base
|
2
|
+
default_options
|
3
|
+
|
4
|
+
attr_reader :name, :class_name, :generator_path
|
5
|
+
|
6
|
+
def initialize(runtime_args, runtime_options = {})
|
7
|
+
super
|
8
|
+
usage if args.empty?
|
9
|
+
@name = args.shift
|
10
|
+
@class_name = "#{name}_generator".camelize
|
11
|
+
@generator_path = "app_generators"
|
12
|
+
extract_options
|
13
|
+
end
|
14
|
+
|
15
|
+
def manifest
|
16
|
+
path = "#{generator_path}/#{name}"
|
17
|
+
record do |m|
|
18
|
+
# Ensure appropriate generators folder exists
|
19
|
+
m.directory "#{path}/templates"
|
20
|
+
m.directory "bin"
|
21
|
+
m.directory "test"
|
22
|
+
|
23
|
+
# Generator stub
|
24
|
+
m.template "generator.rb", "#{path}/#{name}_generator.rb"
|
25
|
+
m.template "test.rb", "test/test_#{name}_generator.rb"
|
26
|
+
m.file "test_generator_helper.rb", "test/test_generator_helper.rb"
|
27
|
+
m.file "usage", "#{path}/USAGE"
|
28
|
+
m.template "bin", "bin/#{name}"
|
29
|
+
m.readme 'readme'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
def banner
|
35
|
+
<<-EOS
|
36
|
+
Creates a application generator stub within your RubyGem.
|
37
|
+
|
38
|
+
Application Generators are used to create new applications
|
39
|
+
from scratch, and create the default scaffolding for
|
40
|
+
an application (directories) plus any starter files
|
41
|
+
that are useful to developers.
|
42
|
+
|
43
|
+
USAGE: #{$0} #{spec.name} name
|
44
|
+
EOS
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_options!(opts)
|
48
|
+
# opts.separator ''
|
49
|
+
# opts.separator 'Options:'
|
50
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
51
|
+
# "Generated app file will include your name.",
|
52
|
+
# "Default: none") { |options[:author]| }
|
53
|
+
end
|
54
|
+
|
55
|
+
def extract_options
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubigen'
|
3
|
+
|
4
|
+
if %w(-v --version).include? ARGV.first
|
5
|
+
require 'newgem/version'
|
6
|
+
puts "#{File.basename($0)} #{Newgem::VERSION::STRING}"
|
7
|
+
exit(0)
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
RubiGen::Base.use_application_sources! <%= name.to_sym.inspect %>
|
12
|
+
RubiGen::Scripts::Generate.new.run(ARGV, :generator => '<%= name %>')
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class <%= class_name %> < RubiGen::Base
|
2
|
+
|
3
|
+
default_options :author => nil
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@name = args.shift
|
11
|
+
extract_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def manifest
|
15
|
+
record do |m|
|
16
|
+
# Ensure appropriate folder(s) exists
|
17
|
+
m.directory 'some_folder'
|
18
|
+
|
19
|
+
# Create stubs
|
20
|
+
# m.template "template.rb", "some_file_after_erb.rb"
|
21
|
+
# m.file "file", "some_file_copied"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
def banner
|
27
|
+
<<-EOS
|
28
|
+
Creates a ...
|
29
|
+
|
30
|
+
USAGE: #{spec.name} name"
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_options!(opts)
|
35
|
+
opts.separator ''
|
36
|
+
opts.separator 'Options:'
|
37
|
+
# For each option below, place the default
|
38
|
+
# at the top of the file next to "default_options"
|
39
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
40
|
+
# "Some comment about this option",
|
41
|
+
# "Default: none") { |options[:author]| }
|
42
|
+
opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
43
|
+
end
|
44
|
+
|
45
|
+
def extract_options
|
46
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
47
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
48
|
+
# raw instance variable value.
|
49
|
+
# @author = options[:author]
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
How to create a Generator (aka Component Generator)
|
2
|
+
======================================
|
3
|
+
|
4
|
+
1. DONE - Run the generator: script/generate component_generator foobar rubygems
|
5
|
+
2. Using the generated test class, assert what directories, files, classes etc should
|
6
|
+
be generated.
|
7
|
+
3. Add these files into the rubygems_genearators/foobar/templates folder. Your files can use
|
8
|
+
ERb (that is, <%= ... %>).
|
9
|
+
4. Specify who the files in /templates are copied/templated at generation time within rubygems_genearators/foobar/foobar_generators.rb's #manifest method.
|
10
|
+
Use m.file for files to copy over.
|
11
|
+
Use m.template for files containing ERb. Create attr_reader accessors for any variables your
|
12
|
+
templates need access to.
|
13
|
+
5. Run unit tests.
|
14
|
+
6. If your generator uses other generators (m.dependency "gen-name", [arg1, arg2], :option1 => 'value')
|
15
|
+
it should only use generates from the same scope ('rubygems' in this example),
|
16
|
+
otherwise RubiGen may not be able to find the dependent generators.
|
17
|
+
7. Update your Manifest.txt with the new files (if you are using Hoe; using newgem? it uses Hoe; so you need to do this)
|
18
|
+
8. Build and install your RubyGem locally. Run: rake install_gem
|
19
|
+
9. Go to a work area whose script/generate is scoped to 'rubygems' (e.g. a RubyGem scaffold created by newgem has a script/generate that can use rubygems, newgem, and newgem_template scoped generators)
|
20
|
+
10. Run "script/generate" and your generator should appear in the list of available generators.
|
21
|
+
11. Run "script/generate foobar" to see the options and usage information for your generator.
|
22
|
+
12. Run "script/generator foobar arguments" to execute the generator.
|
23
|
+
|
24
|
+
See this message again using the -h/--help option.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
|
2
|
+
|
3
|
+
class Test<%= class_name %> < Test::Unit::TestCase
|
4
|
+
include RubiGen::GeneratorTestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
bare_setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
bare_teardown
|
12
|
+
end
|
13
|
+
|
14
|
+
# Some generator-related assertions:
|
15
|
+
# assert_generated_file(name, &block) # block passed the file contents
|
16
|
+
# assert_directory_exists(name)
|
17
|
+
# assert_generated_class(name, &block)
|
18
|
+
# assert_generated_module(name, &block)
|
19
|
+
# assert_generated_test_for(name, &block)
|
20
|
+
# The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
|
21
|
+
# assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
|
22
|
+
#
|
23
|
+
# Other helper methods are:
|
24
|
+
# app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
|
25
|
+
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
|
26
|
+
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
27
|
+
|
28
|
+
def test_generator_without_options
|
29
|
+
name = "myapp"
|
30
|
+
run_generator('<%= name %>', [name], sources)
|
31
|
+
assert_generated_file("some_file")
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def sources
|
36
|
+
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
|
37
|
+
]
|
38
|
+
end
|
39
|
+
|
40
|
+
def generator_path
|
41
|
+
"<%= generator_path %>"
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
# Must set before requiring generator libs.
|
5
|
+
TMP_ROOT = File.dirname(__FILE__) + "/tmp" unless defined?(TMP_ROOT)
|
6
|
+
app_root = File.join(TMP_ROOT, "myproject")
|
7
|
+
if defined?(APP_ROOT)
|
8
|
+
APP_ROOT.replace(app_root)
|
9
|
+
else
|
10
|
+
APP_ROOT = app_root
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'rubigen'
|
15
|
+
rescue LoadError
|
16
|
+
require 'rubygems'
|
17
|
+
require 'rubigen'
|
18
|
+
end
|
19
|
+
require 'rubigen/helpers/generator_test_helper'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
How to create a Generator (aka Component Generator)
|
2
|
+
======================================
|
3
|
+
|
4
|
+
1. Run this generator: script/generate component_generator foobar rubygems
|
5
|
+
Where "foobar" is the name of the generator, and "rubygems" is the optional (but recommended)
|
6
|
+
scope. A scope of "rubygems" means this generator will only be available to RubyGems
|
7
|
+
developers. A scope of "merb" means the generator is only available to Merb applications, etc.
|
8
|
+
If you use "rails", then your generator WILL be accessible by Rails applications
|
9
|
+
for Edge Rails or Rails releases after 1.2.3 (due to patch in Rails' own generator system)
|
10
|
+
2. Using the generated test class, assert what directories, files, classes etc should
|
11
|
+
be generated.
|
12
|
+
3. Add these files into the rubygems_genearators/foobar/templates folder. Your files can use
|
13
|
+
ERb (that is, <%= ... %>).
|
14
|
+
4. Specify who the files in /templates are copied/templated at generation time within rubygems_genearators/foobar/foobar_generators.rb's #manifest method.
|
15
|
+
Use m.file for files to copy over.
|
16
|
+
Use m.template for files containing ERb. Create attr_reader accessors for any variables your
|
17
|
+
templates need access to.
|
18
|
+
5. Run unit tests.
|
19
|
+
6. If your generator uses other generators (m.dependency "gen-name", [arg1, arg2], :option1 => 'value')
|
20
|
+
it should only use generates from the same scope ('rubygems' in this example),
|
21
|
+
otherwise RubiGen may not be able to find the dependent generators.
|
22
|
+
7. Update your Manifest.txt with the new files (if you are using Hoe; using newgem? it uses Hoe; so you need to do this)
|
23
|
+
8. Build and install your RubyGem locally. Run: rake install_gem
|
24
|
+
9. Go to a work area whose script/generate is scoped to 'rubygems' (e.g. a RubyGem scaffold created by newgem has a script/generate that can use rubygems, newgem, and newgem_template scoped generators)
|
25
|
+
10. Run "script/generate" and your generator should appear in the list of available generators.
|
26
|
+
11. Run "script/generate foobar" to see the options and usage information for your generator.
|
27
|
+
12. Run "script/generator foobar arguments" to execute the generator.
|
28
|
+
|
29
|
+
You will see this message again when you run the generator and by using the -h/--help option.
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class ComponentGeneratorGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
default_options
|
4
|
+
|
5
|
+
attr_reader :name, :class_name, :generator_type, :generator_path
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@name = args.shift
|
11
|
+
@class_name = "#{name}_generator".camelize
|
12
|
+
@generator_type = args.shift # optional
|
13
|
+
@generator_path = @generator_type ? "#{generator_type}_generators" : "generators"
|
14
|
+
extract_options
|
15
|
+
end
|
16
|
+
|
17
|
+
def manifest
|
18
|
+
path = "#{generator_path}/#{name}"
|
19
|
+
record do |m|
|
20
|
+
# Ensure appropriate generators folder exists
|
21
|
+
m.directory "#{path}/templates"
|
22
|
+
m.directory "test"
|
23
|
+
|
24
|
+
# Generator stub
|
25
|
+
m.template "generator.rb", "#{path}/#{name}_generator.rb"
|
26
|
+
m.template "test.rb", "test/test_#{name}_generator.rb"
|
27
|
+
m.file "test_generator_helper.rb", "test/test_generator_helper.rb"
|
28
|
+
m.file "usage", "#{path}/USAGE"
|
29
|
+
m.readme 'readme'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
def banner
|
35
|
+
<<-EOS
|
36
|
+
Creates a generator stub within your RubyGem.
|
37
|
+
|
38
|
+
USAGE: #{$0} #{spec.name} name [generator_type]
|
39
|
+
EOS
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_options!(opts)
|
43
|
+
# opts.separator ''
|
44
|
+
# opts.separator 'Options:'
|
45
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
46
|
+
# "Generated app file will include your name.",
|
47
|
+
# "Default: none") { |options[:author]| }
|
48
|
+
end
|
49
|
+
|
50
|
+
def extract_options
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class <%= class_name %> < RubiGen::Base
|
2
|
+
|
3
|
+
default_options :author => nil
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@name = args.shift
|
11
|
+
extract_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def manifest
|
15
|
+
record do |m|
|
16
|
+
# Ensure appropriate folder(s) exists
|
17
|
+
m.directory 'some_folder'
|
18
|
+
|
19
|
+
# Create stubs
|
20
|
+
# m.template "template.rb", "some_file_after_erb.rb"
|
21
|
+
# m.file "file", "some_file_copied"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
def banner
|
27
|
+
<<-EOS
|
28
|
+
Creates a ...
|
29
|
+
|
30
|
+
USAGE: #{$0} #{spec.name} name"
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_options!(opts)
|
35
|
+
# opts.separator ''
|
36
|
+
# opts.separator 'Options:'
|
37
|
+
# For each option below, place the default
|
38
|
+
# at the top of the file next to "default_options"
|
39
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
40
|
+
# "Some comment about this option",
|
41
|
+
# "Default: none") { |options[:author]| }
|
42
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
43
|
+
end
|
44
|
+
|
45
|
+
def extract_options
|
46
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
47
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
48
|
+
# raw instance variable value.
|
49
|
+
# @author = options[:author]
|
50
|
+
end
|
51
|
+
end
|