newgem 0.14.2 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. data/History.txt +5 -0
  2. data/Manifest.txt +2 -17
  3. data/config/hoe.rb +1 -1
  4. data/lib/newgem/version.rb +2 -2
  5. data/script/txt2html.rb +70 -0
  6. data/tasks/generator_report.rake +19 -0
  7. data/website/index.html +1 -1
  8. data/website/rubyforge.html +2 -2
  9. data/website/version-raw.js +1 -1
  10. data/website/version.js +1 -1
  11. metadata +5 -22
  12. data/rubygems_generators/application_generator/USAGE +0 -28
  13. data/rubygems_generators/application_generator/application_generator_generator.rb +0 -62
  14. data/rubygems_generators/application_generator/templates/bin +0 -12
  15. data/rubygems_generators/application_generator/templates/generator.rb +0 -69
  16. data/rubygems_generators/application_generator/templates/readme +0 -19
  17. data/rubygems_generators/application_generator/templates/test.rb +0 -43
  18. data/rubygems_generators/application_generator/templates/test_generator_helper.rb +0 -20
  19. data/rubygems_generators/application_generator/templates/usage +0 -5
  20. data/rubygems_generators/component_generator/USAGE +0 -29
  21. data/rubygems_generators/component_generator/component_generator_generator.rb +0 -52
  22. data/rubygems_generators/component_generator/templates/generator.rb +0 -51
  23. data/rubygems_generators/component_generator/templates/readme +0 -28
  24. data/rubygems_generators/component_generator/templates/test.rb +0 -43
  25. data/rubygems_generators/component_generator/templates/test_generator_helper.rb +0 -20
  26. data/rubygems_generators/component_generator/templates/usage +0 -5
  27. data/test/test_application_generator_generator.rb +0 -60
  28. data/test/test_generate_component_generator.rb +0 -67
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.15.0 2007-11-05
2
+
3
+ * Promoted 'application_generator' and 'component_generator' to Rubigen
4
+ from NewGem project (they are available even if newgem not installed)
5
+
1
6
  == 0.14.2 2007-11-03
2
7
 
3
8
  * Application generator inserts scopes passed in at cmd line, not app name
data/Manifest.txt CHANGED
@@ -49,21 +49,6 @@ newgem_theme_generators/plain_theme/plain_theme_generator.rb
49
49
  newgem_theme_generators/plain_theme/templates/website/javascripts/rounded_corners_lite.inc.js
50
50
  newgem_theme_generators/plain_theme/templates/website/stylesheets/screen.css
51
51
  newgem_theme_generators/plain_theme/templates/website/template.rhtml
52
- rubygems_generators/application_generator/USAGE
53
- rubygems_generators/application_generator/application_generator_generator.rb
54
- rubygems_generators/application_generator/templates/bin
55
- rubygems_generators/application_generator/templates/generator.rb
56
- rubygems_generators/application_generator/templates/readme
57
- rubygems_generators/application_generator/templates/test.rb
58
- rubygems_generators/application_generator/templates/test_generator_helper.rb
59
- rubygems_generators/application_generator/templates/usage
60
- rubygems_generators/component_generator/USAGE
61
- rubygems_generators/component_generator/component_generator_generator.rb
62
- rubygems_generators/component_generator/templates/generator.rb
63
- rubygems_generators/component_generator/templates/readme
64
- rubygems_generators/component_generator/templates/test.rb
65
- rubygems_generators/component_generator/templates/test_generator_helper.rb
66
- rubygems_generators/component_generator/templates/usage
67
52
  rubygems_generators/executable/USAGE
68
53
  rubygems_generators/executable/executable_generator.rb
69
54
  rubygems_generators/executable/templates/app.rb
@@ -79,15 +64,15 @@ rubygems_generators/install_rspec/templates/tasks/rspec.rake
79
64
  script/destroy
80
65
  script/generate
81
66
  script/txt2html
67
+ script/txt2html.rb
82
68
  script/txt2js
83
69
  setup.rb
84
70
  tasks/bundles.rake
85
71
  tasks/deployment.rake
86
72
  tasks/environment.rake
73
+ tasks/generator_report.rake
87
74
  tasks/website.rake
88
- test/test_application_generator_generator.rb
89
75
  test/test_executable_generator.rb
90
- test/test_generate_component_generator.rb
91
76
  test/test_generator_helper.rb
92
77
  test/test_helper.rb
93
78
  test/test_install_jruby_generator.rb
data/config/hoe.rb CHANGED
@@ -52,7 +52,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
52
52
  ['RedCloth','>=3.0.4'],
53
53
  ['syntax','>=1.0.0'],
54
54
  ['activesupport','>=1.4.2'],
55
- ['rubigen','>=1.0.8']
55
+ ['rubigen','>=1.1.0']
56
56
  ]
57
57
  #p.spec_extras - A hash of extra values to set in the gemspec.
58
58
  end
@@ -1,8 +1,8 @@
1
1
  module Newgem #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 14
5
- TINY = 2
4
+ MINOR = 15
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+
8
+ class Fixnum
9
+ def ordinal
10
+ # teens
11
+ return 'th' if (10..19).include?(self % 100)
12
+ # others
13
+ case self % 10
14
+ when 1: return 'st'
15
+ when 2: return 'nd'
16
+ when 3: return 'rd'
17
+ else return 'th'
18
+ end
19
+ end
20
+ end
21
+
22
+ class Time
23
+ def pretty
24
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
25
+ end
26
+ end
27
+
28
+ module Txt2Html
29
+ def convert_syntax(syntax, source)
30
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
31
+ end
32
+
33
+ require File.dirname(__FILE__) + '/../lib/newgem/version.rb'
34
+
35
+ version = Newgem::VERSION::STRING
36
+ download = ENV['HOMEPAGE']
37
+
38
+ if ARGV.length >= 1
39
+ src, template = ARGV
40
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
41
+
42
+ else
43
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
44
+ exit!
45
+ end
46
+
47
+ template = ERB.new(File.open(template).read)
48
+
49
+ title = nil
50
+ body = nil
51
+ File.open(src) do |fsrc|
52
+ title_text = fsrc.readline
53
+ body_text = fsrc.read
54
+ syntax_items = []
55
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
56
+ ident = syntax_items.length
57
+ element, syntax, source = $1, $2, $3
58
+ syntax_items << "<#{element} class=\"syntax\">#{convert_syntax(syntax, source)}</#{element}>"
59
+ "syntax-temp-#{ident}"
60
+ }
61
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
62
+ body = RedCloth.new(body_text).to_html
63
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
64
+ end
65
+ stat = File.stat(src)
66
+ created = stat.ctime
67
+ modified = stat.mtime
68
+
69
+ $stdout << template.result(binding)
70
+ end
@@ -0,0 +1,19 @@
1
+ desc 'Check that files included in generators match those in use by newgem itself'
2
+ task :generator_report do
3
+ files = [
4
+ %w( script/generate app_generators/newgem ),
5
+ %w( script/destroy app_generators/newgem ),
6
+ %w( tasks/deployment.rake app_generators/newgem ),
7
+ %w( tasks/environment.rake app_generators/newgem ),
8
+ %w( test/test_generator_helper.rb rubygems_generators/component_generator ),
9
+ %w( tasks/website.rake newgem_generators/website ),
10
+ ]
11
+ # add "templates/#{source}" to each 2nd string
12
+ end
13
+
14
+ # def identical?(source, destination, &block)
15
+ # return false if File.directory? destination
16
+ # source = block_given? ? File.open(source) {|sf| yield(sf)} : IO.read(source)
17
+ # destination = IO.read(destination)
18
+ # source == destination
19
+ # end
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>New Gem Generator</h1>
34
34
  <div id="version"> <!-- class="clickable" onclick='document.location = ""; return true' -->
35
35
  <p>Get Version</p>
36
- <a href="" class="numbers">0.14.2</a>
36
+ <a href="" class="numbers">0.15.0</a>
37
37
  <p>Featured in</p>
38
38
  <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&location=http%3A%2F%2Fwww.amazon.com%2FBeginning-Ruby-Novice-Professional-Experts%2Fdp%2F1590597664%2F&tag=drnic-20&linkCode=ur2&camp=1789&creative=9325" class="book"><img src="images/beginning-ruby.jpg" /></a>
39
39
  </div>
@@ -33,7 +33,7 @@
33
33
  <h1>New Gem Generator</h1>
34
34
  <div id="version"> <!-- class="clickable" onclick='document.location = ""; return true' -->
35
35
  <p>Get Version</p>
36
- <a href="" class="numbers">0.14.2</a>
36
+ <a href="" class="numbers">0.15.0</a>
37
37
  <p>Featured in</p>
38
38
  <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&location=http%3A%2F%2Fwww.amazon.com%2FBeginning-Ruby-Novice-Professional-Experts%2Fdp%2F1590597664%2F&tag=drnic-20&linkCode=ur2&camp=1789&creative=9325" class="book"><img src="images/beginning-ruby.jpg" /></a>
39
39
  </div>
@@ -263,7 +263,7 @@ OPTIONS
263
263
  specify whether release_notes/changes are preformatted
264
264
  </pre>
265
265
  <p class="coda">
266
- <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 24th June 2007<br>
266
+ <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 23rd June 2007<br>
267
267
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
268
268
  </p>
269
269
  </div>
@@ -1,3 +1,3 @@
1
1
  // Announcement JS file
2
- var version = "0.14.2";
2
+ var version = "0.15.0";
3
3
  MagicAnnouncement.show('compositekeys', version);
data/website/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Version JS file
2
- var version = "0.14.2";
2
+ var version = "0.15.0";
3
3
 
4
4
  document.write(" - " + version);
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4.3
3
3
  specification_version: 1
4
4
  name: newgem
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.14.2
7
- date: 2007-11-04 00:00:00 -04:00
6
+ version: 0.15.0
7
+ date: 2007-11-05 00:00:00 -08:00
8
8
  summary: Make your own gems at home
9
9
  require_paths:
10
10
  - lib
@@ -80,21 +80,6 @@ files:
80
80
  - newgem_theme_generators/plain_theme/templates/website/javascripts/rounded_corners_lite.inc.js
81
81
  - newgem_theme_generators/plain_theme/templates/website/stylesheets/screen.css
82
82
  - newgem_theme_generators/plain_theme/templates/website/template.rhtml
83
- - rubygems_generators/application_generator/USAGE
84
- - rubygems_generators/application_generator/application_generator_generator.rb
85
- - rubygems_generators/application_generator/templates/bin
86
- - rubygems_generators/application_generator/templates/generator.rb
87
- - rubygems_generators/application_generator/templates/readme
88
- - rubygems_generators/application_generator/templates/test.rb
89
- - rubygems_generators/application_generator/templates/test_generator_helper.rb
90
- - rubygems_generators/application_generator/templates/usage
91
- - rubygems_generators/component_generator/USAGE
92
- - rubygems_generators/component_generator/component_generator_generator.rb
93
- - rubygems_generators/component_generator/templates/generator.rb
94
- - rubygems_generators/component_generator/templates/readme
95
- - rubygems_generators/component_generator/templates/test.rb
96
- - rubygems_generators/component_generator/templates/test_generator_helper.rb
97
- - rubygems_generators/component_generator/templates/usage
98
83
  - rubygems_generators/executable/USAGE
99
84
  - rubygems_generators/executable/executable_generator.rb
100
85
  - rubygems_generators/executable/templates/app.rb
@@ -110,15 +95,15 @@ files:
110
95
  - script/destroy
111
96
  - script/generate
112
97
  - script/txt2html
98
+ - script/txt2html.rb
113
99
  - script/txt2js
114
100
  - setup.rb
115
101
  - tasks/bundles.rake
116
102
  - tasks/deployment.rake
117
103
  - tasks/environment.rake
104
+ - tasks/generator_report.rake
118
105
  - tasks/website.rake
119
- - test/test_application_generator_generator.rb
120
106
  - test/test_executable_generator.rb
121
- - test/test_generate_component_generator.rb
122
107
  - test/test_generator_helper.rb
123
108
  - test/test_helper.rb
124
109
  - test/test_install_jruby_generator.rb
@@ -140,9 +125,7 @@ files:
140
125
  - website/version.js
141
126
  - website/version.txt
142
127
  test_files:
143
- - test/test_application_generator_generator.rb
144
128
  - test/test_executable_generator.rb
145
- - test/test_generate_component_generator.rb
146
129
  - test/test_generator_helper.rb
147
130
  - test/test_helper.rb
148
131
  - test/test_install_jruby_generator.rb
@@ -217,7 +200,7 @@ dependencies:
217
200
  requirements:
218
201
  - - ">="
219
202
  - !ruby/object:Gem::Version
220
- version: 1.0.8
203
+ version: 1.1.0
221
204
  version:
222
205
  - !ruby/object:Gem::Dependency
223
206
  name: hoe
@@ -1,28 +0,0 @@
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.
@@ -1,62 +0,0 @@
1
- class ApplicationGeneratorGenerator < RubiGen::Base
2
-
3
- default_options
4
-
5
- attr_reader :name, :class_name, :generator_path, :scopes, :scope_str
6
-
7
- def initialize(runtime_args, runtime_options = {})
8
- super
9
- usage if args.empty?
10
- @name = args.shift
11
- @scopes = args
12
- @scopes = [name] if scopes.blank?
13
- @scope_str = scopes.map { |scope| "'#{scope}'" }.join ', '
14
- @class_name = "#{name}_generator".camelize
15
- @generator_path = "app_generators"
16
- extract_options
17
- end
18
-
19
- def manifest
20
- path = "#{generator_path}/#{name}"
21
- record do |m|
22
- # Ensure appropriate generators folder exists
23
- m.directory "#{path}/templates"
24
- m.directory "bin"
25
- m.directory "test"
26
-
27
- # Generator stub
28
- m.template "generator.rb", "#{path}/#{name}_generator.rb"
29
- m.template "test.rb", "test/test_#{name}_generator.rb"
30
- m.file "test_generator_helper.rb", "test/test_generator_helper.rb"
31
- m.file "usage", "#{path}/USAGE"
32
- m.template "bin", "bin/#{name}"
33
- m.readme 'readme'
34
- end
35
- end
36
-
37
- protected
38
- def banner
39
- <<-EOS
40
- Creates a application generator stub within your RubyGem.
41
-
42
- Application Generators are used to create new applications
43
- from scratch, and create the default scaffolding for
44
- an application (directories) plus any starter files
45
- that are useful to developers.
46
-
47
- USAGE: #{$0} #{spec.name} name
48
- EOS
49
- end
50
-
51
- def add_options!(opts)
52
- # opts.separator ''
53
- # opts.separator 'Options:'
54
- # opts.on("-a", "--author=\"Your Name\"", String,
55
- # "Generated app file will include your name.",
56
- # "Default: none") { |options[:author]| }
57
- end
58
-
59
- def extract_options
60
- end
61
-
62
- end
@@ -1,12 +0,0 @@
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 %>')
@@ -1,69 +0,0 @@
1
- class <%= class_name %> < RubiGen::Base
2
-
3
- DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
- Config::CONFIG['ruby_install_name'])
5
-
6
- default_options :author => nil
7
-
8
- attr_reader :name
9
-
10
- def initialize(runtime_args, runtime_options = {})
11
- super
12
- usage if args.empty?
13
- @destination_root = File.expand_path(args.shift)
14
- @name = base_name
15
- extract_options
16
- end
17
-
18
- def manifest
19
- record do |m|
20
- # Ensure appropriate folder(s) exists
21
- m.directory ''
22
- BASEDIRS.each { |path| m.directory path }
23
-
24
- # Create stubs
25
- # m.template "template.rb", "some_file_after_erb.rb"
26
- # m.file "file", "some_file_copied"
27
-
28
- m.dependency "install_rubigen_scripts", [destination_root, <%= scope_str %>],
29
- :shebang => options[:shebang], :collision => :force
30
- end
31
- end
32
-
33
- protected
34
- def banner
35
- <<-EOS
36
- Creates a ...
37
-
38
- USAGE: #{spec.name} name"
39
- EOS
40
- end
41
-
42
- def add_options!(opts)
43
- opts.separator ''
44
- opts.separator 'Options:'
45
- # For each option below, place the default
46
- # at the top of the file next to "default_options"
47
- # opts.on("-a", "--author=\"Your Name\"", String,
48
- # "Some comment about this option",
49
- # "Default: none") { |options[:author]| }
50
- opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
51
- end
52
-
53
- def extract_options
54
- # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
55
- # Templates can access these value via the attr_reader-generated methods, but not the
56
- # raw instance variable value.
57
- # @author = options[:author]
58
- end
59
-
60
- # Installation skeleton. Intermediate directories are automatically
61
- # created so don't sweat their absence here.
62
- BASEDIRS = %w(
63
- lib
64
- log
65
- script
66
- test
67
- tmp
68
- )
69
- end
@@ -1,19 +0,0 @@
1
- How to create a Generator (aka Application Generator)
2
- ======================================
3
-
4
- 1. DONE - Run the generator: script/generate application_generator myapp
5
- 2. Using the generated test class, assert what directories, files, classes etc should
6
- be generated.
7
- 3. Add these files into the app_genearators/myapp/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 app_genearators/myapp/myapp_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. Update your Manifest.txt with the new files (rake manifest:refresh)
15
- 7. Build and install your RubyGem locally. Run: rake install_gem
16
- 8. Go to a directory where you can create new test apps.
17
- 9. Run 'myapp [path]' and your application skeleton will be created.
18
-
19
- See this message again using the -h/--help option.
@@ -1,43 +0,0 @@
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
- run_generator('<%= name %>', [APP_ROOT], sources)
30
- assert_directory_exists "path/to/included/folder"
31
- assert_generated_file "path/to/included/folder/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
@@ -1,20 +0,0 @@
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
- PROJECT_NAME = "myproject" unless defined?(PROJECT_NAME)
7
- app_root = File.join(TMP_ROOT, PROJECT_NAME)
8
- if defined?(APP_ROOT)
9
- APP_ROOT.replace(app_root)
10
- else
11
- APP_ROOT = app_root
12
- end
13
-
14
- begin
15
- require 'rubigen'
16
- rescue LoadError
17
- require 'rubygems'
18
- require 'rubigen'
19
- end
20
- require 'rubigen/helpers/generator_test_helper'
@@ -1,5 +0,0 @@
1
- Description:
2
-
3
-
4
- Usage:
5
-
@@ -1,29 +0,0 @@
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.
@@ -1,52 +0,0 @@
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
@@ -1,51 +0,0 @@
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
@@ -1,28 +0,0 @@
1
- How to create an Application Generator
2
- ======================================
3
-
4
- 1. DONE - Create a new RubyGem (using newgem or hoe) or you can use an existing one.
5
- 2. DONE - 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
- See this message again using the -h/--help option.
@@ -1,43 +0,0 @@
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
@@ -1,20 +0,0 @@
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
- PROJECT_NAME = "myproject" unless defined?(PROJECT_NAME)
7
- app_root = File.join(TMP_ROOT, PROJECT_NAME)
8
- if defined?(APP_ROOT)
9
- APP_ROOT.replace(app_root)
10
- else
11
- APP_ROOT = app_root
12
- end
13
-
14
- begin
15
- require 'rubigen'
16
- rescue LoadError
17
- require 'rubygems'
18
- require 'rubigen'
19
- end
20
- require 'rubigen/helpers/generator_test_helper'
@@ -1,5 +0,0 @@
1
- Description:
2
-
3
-
4
- Usage:
5
-
@@ -1,60 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
-
3
- class TestApplicationGeneratorGenerator < 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 = "genname"
30
- run_generator('application_generator', [name], sources)
31
-
32
- assert_directory_exists "app_generators"
33
- assert_directory_exists "app_generators/#{name}"
34
- assert_directory_exists "app_generators/#{name}/templates"
35
- assert_generated_file "app_generators/#{name}/USAGE"
36
- assert_generated_class "app_generators/#{name}/#{name}_generator" do |body|
37
- assert_has_method "manifest"
38
- end
39
- assert_generated_test_for("#{name}_generator") do |body|
40
- assert_has_method body, "setup"
41
- assert_has_method body, "teardown"
42
- assert_has_method body, "test_generator_without_options"
43
- assert_has_method body, "sources"
44
- assert_has_method body, "generator_path"
45
- end
46
-
47
- assert_directory_exists "bin"
48
- assert_generated_file "bin/#{name}"
49
- end
50
-
51
- private
52
- def sources
53
- [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
54
- ]
55
- end
56
-
57
- def generator_path
58
- "rubygems_generators"
59
- end
60
- end
@@ -1,67 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
2
-
3
- class TestGenerateComponentGenerator < 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
- def test_generator_without_options
15
- name = "genname"
16
- run_generator('component_generator', [name], sources)
17
- assert_generated_file("generators/#{name}/#{name}_generator.rb")
18
- assert_generated_file("generators/#{name}/USAGE")
19
- assert_generated_file("test/test_#{name}_generator.rb")
20
- assert_generated_file("test/test_generator_helper.rb")
21
- assert_directory_exists("generators/#{name}/templates")
22
- assert_generated_class("generators/#{name}/#{name}_generator") do |body|
23
- # assert_has_method body, "initialize" # as_has_m cannot pickup initialize(...) only initialize
24
- assert_has_method body, "manifest"
25
- end
26
- assert_generated_class("test/test_#{name}_generator") do |body|
27
- assert_has_method body, "setup"
28
- assert_has_method body, "teardown"
29
- assert_has_method body, "test_generator_without_options"
30
- assert_has_method body, "sources"
31
- assert_has_method body, "generator_path"
32
- end
33
- end
34
-
35
- def test_generator_with_generator_type
36
- name = "genname"
37
- gen_type = "fooapp"
38
- run_generator('component_generator', [name, gen_type], sources)
39
-
40
- assert_generated_file "#{gen_type}_generators/#{name}/#{name}_generator.rb"
41
- assert_generated_file "#{gen_type}_generators/#{name}/USAGE"
42
- assert_generated_file "test/test_#{name}_generator.rb"
43
- assert_generated_file "test/test_generator_helper.rb"
44
- assert_directory_exists "#{gen_type}_generators/#{name}/templates"
45
- assert_generated_class "#{gen_type}_generators/#{name}/#{name}_generator" do |body|
46
- # assert_has_method body, "initialize" # as_has_m cannot pickup initialize(...) only initialize
47
- assert_has_method body, "manifest"
48
- end
49
- assert_generated_class "test/test_#{name}_generator" do |body|
50
- assert_has_method body, "setup"
51
- assert_has_method body, "teardown"
52
- assert_has_method body, "test_generator_without_options"
53
- assert_has_method body, "sources"
54
- assert_has_method body, "generator_path"
55
- end
56
- end
57
-
58
- private
59
- def sources
60
- [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"../#{generator_path}"))
61
- ]
62
- end
63
-
64
- def generator_path
65
- "rubygems_generators"
66
- end
67
- end