rubigen 1.0.8 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/History.txt +7 -0
  2. data/Manifest.txt +23 -0
  3. data/bin/install_rubigen_scripts +2 -2
  4. data/generators/install_rubigen_scripts/install_rubigen_scripts_generator.rb +2 -2
  5. data/lib/rubigen/version.rb +2 -2
  6. data/rubygems_generators/application_generator/USAGE +28 -0
  7. data/rubygems_generators/application_generator/application_generator_generator.rb +63 -0
  8. data/rubygems_generators/application_generator/templates/bin +12 -0
  9. data/rubygems_generators/application_generator/templates/generator.rb +69 -0
  10. data/rubygems_generators/application_generator/templates/readme +29 -0
  11. data/rubygems_generators/application_generator/templates/test.rb +43 -0
  12. data/rubygems_generators/application_generator/templates/test_generator_helper.rb +20 -0
  13. data/rubygems_generators/application_generator/templates/usage +5 -0
  14. data/rubygems_generators/component_generator/USAGE +27 -0
  15. data/rubygems_generators/component_generator/component_generator_generator.rb +52 -0
  16. data/rubygems_generators/component_generator/templates/generator.rb +51 -0
  17. data/rubygems_generators/component_generator/templates/readme +25 -0
  18. data/rubygems_generators/component_generator/templates/test.rb +43 -0
  19. data/rubygems_generators/component_generator/templates/test_generator_helper.rb +20 -0
  20. data/rubygems_generators/component_generator/templates/usage +5 -0
  21. data/script/txt2js +59 -0
  22. data/tasks/website.rake +2 -0
  23. data/test/test_application_generator_generator.rb +60 -0
  24. data/test/test_component_generator_generator.rb +67 -0
  25. data/website/index.html +1 -1
  26. data/website/template.js +3 -0
  27. data/website/version-raw.js +3 -0
  28. data/website/version-raw.txt +2 -0
  29. data/website/version.js +4 -0
  30. data/website/version.txt +3 -0
  31. metadata +29 -2
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 1.1.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
+ * install_rubigen_scripts default test fixed by mapping scopes to strings
6
+ * version.js uploaded to website
7
+
1
8
  == 1.0.8 2007-11-03
2
9
 
3
10
  * install_rubigen_scripts adds 'test_unit' to scopes unless a test-related scope is added
data/Manifest.txt CHANGED
@@ -35,9 +35,25 @@ lib/rubigen/simple_logger.rb
35
35
  lib/rubigen/spec.rb
36
36
  lib/rubigen/version.rb
37
37
  log/debug.log
38
+ rubygems_generators/application_generator/USAGE
39
+ rubygems_generators/application_generator/application_generator_generator.rb
40
+ rubygems_generators/application_generator/templates/bin
41
+ rubygems_generators/application_generator/templates/generator.rb
42
+ rubygems_generators/application_generator/templates/readme
43
+ rubygems_generators/application_generator/templates/test.rb
44
+ rubygems_generators/application_generator/templates/test_generator_helper.rb
45
+ rubygems_generators/application_generator/templates/usage
46
+ rubygems_generators/component_generator/USAGE
47
+ rubygems_generators/component_generator/component_generator_generator.rb
48
+ rubygems_generators/component_generator/templates/generator.rb
49
+ rubygems_generators/component_generator/templates/readme
50
+ rubygems_generators/component_generator/templates/test.rb
51
+ rubygems_generators/component_generator/templates/test_generator_helper.rb
52
+ rubygems_generators/component_generator/templates/usage
38
53
  script/destroy
39
54
  script/generate
40
55
  script/txt2html
56
+ script/txt2js
41
57
  setup.rb
42
58
  tasks/deployment.rake
43
59
  tasks/environment.rake
@@ -45,6 +61,8 @@ tasks/website.rake
45
61
  test/examples_from_rails/generator_test_helper.rb
46
62
  test/examples_from_rails/test_rails_resource_generator.rb
47
63
  test/examples_from_rails/test_rails_scaffold_generator.rb
64
+ test/test_application_generator_generator.rb
65
+ test/test_component_generator_generator.rb
48
66
  test/test_generate_builtin_application.rb
49
67
  test/test_generate_builtin_test_unit.rb
50
68
  test/test_generator_helper.rb
@@ -58,4 +76,9 @@ website/index.html
58
76
  website/index.txt
59
77
  website/javascripts/rounded_corners_lite.inc.js
60
78
  website/stylesheets/screen.css
79
+ website/template.js
61
80
  website/template.rhtml
81
+ website/version-raw.js
82
+ website/version-raw.txt
83
+ website/version.js
84
+ website/version.txt
@@ -2,8 +2,8 @@ require 'rubygems'
2
2
  require 'rubigen'
3
3
 
4
4
  if %w(-v --version).include? ARGV.first
5
- require 'newgem/version'
6
- puts "#{File.basename($0)} #{Newgem::VERSION::STRING}"
5
+ require 'rubigen/version'
6
+ puts "#{File.basename($0)} (via rubigen - #{Rubigen::VERSION::STRING})"
7
7
  exit(0)
8
8
  end
9
9
 
@@ -64,8 +64,8 @@ EOS
64
64
  end
65
65
 
66
66
  def default_scopes
67
- if (scopes & %w[test_unit rspec test_spec mini_spec]).blank?
68
- scopes << 'test_unit'
67
+ if (scopes.map { |s| s.to_s } & %w[test_unit rspec test_spec mini_spec]).blank?
68
+ scopes << :test_unit
69
69
  end
70
70
  end
71
71
 
@@ -1,8 +1,8 @@
1
1
  module Rubigen #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 0
5
- TINY = 8
4
+ MINOR = 1
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -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,63 @@
1
+ class ApplicationGeneratorGenerator < RubiGen::Base
2
+
3
+ default_options
4
+
5
+ attr_reader :name, :class_name, :app_model_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
+ @app_model_name = name.camelize
15
+ @class_name = "#{name}_generator".camelize
16
+ @generator_path = "app_generators"
17
+ extract_options
18
+ end
19
+
20
+ def manifest
21
+ path = "#{generator_path}/#{name}"
22
+ record do |m|
23
+ # Ensure appropriate generators folder exists
24
+ m.directory "#{path}/templates"
25
+ m.directory "bin"
26
+ m.directory "test"
27
+
28
+ # Generator stub
29
+ m.template "generator.rb", "#{path}/#{name}_generator.rb"
30
+ m.template "test.rb", "test/test_#{name}_generator.rb"
31
+ m.file "test_generator_helper.rb", "test/test_generator_helper.rb"
32
+ m.file "usage", "#{path}/USAGE"
33
+ m.template "bin", "bin/#{name}"
34
+ m.readme 'readme'
35
+ end
36
+ end
37
+
38
+ protected
39
+ def banner
40
+ <<-EOS
41
+ Creates a application generator stub within your RubyGem.
42
+
43
+ Application Generators are used to create new applications
44
+ from scratch, and create the default scaffolding for
45
+ an application (directories) plus any starter files
46
+ that are useful to developers.
47
+
48
+ USAGE: #{$0} #{spec.name} name
49
+ EOS
50
+ end
51
+
52
+ def add_options!(opts)
53
+ # opts.separator ''
54
+ # opts.separator 'Options:'
55
+ # opts.on("-a", "--author=\"Your Name\"", String,
56
+ # "Generated app file will include your name.",
57
+ # "Default: none") { |options[:author]| }
58
+ end
59
+
60
+ def extract_options
61
+ end
62
+
63
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rubigen'
3
+
4
+ if %w(-v --version).include? ARGV.first
5
+ require '<%= name %>/version'
6
+ puts "#{File.basename($0)} #{<%= app_model_name %>::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,69 @@
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
@@ -0,0 +1,29 @@
1
+ How to create a Generator (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
10
+ app_genearators/myapp/myapp_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
13
+ your templates need access to.
14
+ 5. Run unit tests.
15
+ 6. If your application generator uses other generators (called 'dependencies')
16
+ e.g. (m.dependency "generator-from-rubygems", [arg1, arg2], options)
17
+ then you must add this generators' scope into the executable bin/myapp.
18
+ For example, if you wanted to use a rubygems and/or merb generator, then
19
+ replace the use_application_sources! call in bin/myapp:
20
+
21
+ RubiGen::Base.use_application_sources! :rubygems, :merb
22
+
23
+ Without this, RubiGen will not be able to find your dependent generators.
24
+ 7. Update your Manifest.txt with the new files (rake manifest:refresh)
25
+ 8. Build and install your RubyGem locally. Run: rake install_gem
26
+ 9. Go to a directory where you can create new test apps.
27
+ 10. Run 'myapp [path]' and your application skeleton will be created.
28
+
29
+ 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
+ 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
@@ -0,0 +1,20 @@
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'
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,27 @@
1
+ How to create a Generator (aka Component Generator)
2
+ ======================================
3
+
4
+ 1. Run this generator: script/generate component_generator mygen scope
5
+ Where "mygen" is the name of the generator, and scope is scope restriction.
6
+ A scope of "rubygems" means this generator will only be available to RubyGems developers.
7
+ A scope of "merb" means the generator is only accessible to Merb applications (v0.4+).
8
+ If you use "rails", then your generator is only accessible by Rails applications (v2.0+).
9
+ 2. Using the generated test class, assert what directories, files, classes etc should
10
+ be generated.
11
+ 3. Add these files into the scope_genearators/mygen/templates folder. Your files can use
12
+ ERb (that is, <%= ... %>), and are called 'templates'.
13
+ 4. Specify the files in /templates are copied/templated at generation time within rubygems_genearators/mygen/mygen_generators.rb's #manifest method.
14
+ Use m.file for files to copy over.
15
+ Use m.template for files containing ERb. Create attr_reader accessors for any variables your
16
+ templates need access to.
17
+ 5. Run unit tests.
18
+ 6. Add usage information in the USAGE file.
19
+ 7. Update your Manifest.txt with the new files (if you are using Hoe)
20
+ 8. Build and install your RubyGem locally. Run: rake install_gem
21
+ 9. Go to a work area for your scope (e.g. go to the root folder of a Merb application
22
+ to use a "merb" scoped generator)
23
+ 10. Run "script/generate" and your generator should appear in the list of available generators.
24
+ 11. Run "script/generate mygen" to see the options and usage information for your generator.
25
+ 12. Run "script/generator mygen arguments" to execute the generator.
26
+
27
+ 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
@@ -0,0 +1,25 @@
1
+ How to create a Generator (Component Generator)
2
+ ======================================
3
+
4
+ 1. DONE - Run the generator: script/generate component_generator mygen
5
+ 2. Using the generated test class, assert what directories, files, classes etc should
6
+ be generated.
7
+ 3. Add these files into the *scope*_generators/mygen/templates folder. Your files can use
8
+ ERb (that is, <%= ... %>), and are called 'templates'.
9
+ 4. Specify who the files in /templates are copied/templated at generation time within
10
+ app_generators/mygen/mygen_generators.rb 's #manifest method.
11
+ * Use m.file for files to copy over.
12
+ * Use m.template for files containing ERb.
13
+ Create attr_reader accessors for any variables your templates need access to.
14
+ 5. Run unit tests.
15
+ 6. Add usage information in the USAGE file.
16
+ 7. Update your Manifest.txt with the new files (if you are using Hoe)
17
+ 8. Build and install your RubyGem locally. Run: rake install_gem
18
+ 9. Go to a work area whose script/generate for your scope (e.g. go to the root folder
19
+ of a Merb application to use a 'merb' scoped generator.
20
+ 10. Run "script/generate" and your new generator should appear in the list of available generators.
21
+ 11. Run "script/generate mygen" to see the options and usage information for your generator.
22
+ 12. Run "script/generator mygen arguments" to execute the generator.
23
+ 13. Done.
24
+
25
+ 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,20 @@
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'
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
data/script/txt2js ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+ require 'active_support'
8
+ require File.dirname(__FILE__) + '/../lib/rubigen/version.rb'
9
+
10
+ version = Rubigen::VERSION::STRING
11
+ download = 'http://rubyforge.org/projects/rubigen'
12
+
13
+ class Fixnum
14
+ def ordinal
15
+ # teens
16
+ return 'th' if (10..19).include?(self % 100)
17
+ # others
18
+ case self % 10
19
+ when 1: return 'st'
20
+ when 2: return 'nd'
21
+ when 3: return 'rd'
22
+ else return 'th'
23
+ end
24
+ end
25
+ end
26
+
27
+ class Time
28
+ def pretty
29
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
30
+ end
31
+ end
32
+
33
+ def convert_syntax(syntax, source)
34
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
35
+ end
36
+
37
+ if ARGV.length >= 1
38
+ src, template = ARGV
39
+ template ||= File.dirname(__FILE__) + '/../website/template.js'
40
+ else
41
+ puts("Usage: #{File.split($0).last} source.txt [template.js] > output.html")
42
+ exit!
43
+ end
44
+
45
+ template = ERB.new(File.open(template).read)
46
+
47
+ title = nil
48
+ body = nil
49
+ File.open(src) do |fsrc|
50
+ title_text = fsrc.readline
51
+ body_text = fsrc.read
52
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
53
+ body = RedCloth.new(body_text)
54
+ end
55
+ stat = File.stat(src)
56
+ created = stat.ctime
57
+ modified = stat.mtime
58
+
59
+ $stdout << template.result(binding)
data/tasks/website.rake CHANGED
@@ -3,6 +3,8 @@ task :website_generate => :ruby_env do
3
3
  (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
4
  sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
5
  end
6
+ sh %{ #{RUBY_APP} script/txt2js website/version.txt > website/version.js }
7
+ sh %{ #{RUBY_APP} script/txt2js website/version-raw.txt > website/version-raw.js }
6
8
  end
7
9
 
8
10
  desc 'Upload website files to rubyforge'
@@ -0,0 +1,60 @@
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
@@ -0,0 +1,67 @@
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
data/website/index.html CHANGED
@@ -31,7 +31,7 @@
31
31
  <h1>rubigen</h1>
32
32
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/rubigen"; return false'>
33
33
  <p>Get Version</p>
34
- <a href="http://rubyforge.org/projects/rubigen" class="numbers">1.0.8</a>
34
+ <a href="http://rubyforge.org/projects/rubigen" class="numbers">1.1.0</a>
35
35
  </div>
36
36
  <h1>Ruby Generator Framework</h1>
37
37
 
@@ -0,0 +1,3 @@
1
+ // <%= title %>
2
+ var version = <%= version.to_json %>;
3
+ <%= body %>
@@ -0,0 +1,3 @@
1
+ // Announcement JS file
2
+ var version = "1.1.0";
3
+ MagicAnnouncement.show('compositekeys', version);
@@ -0,0 +1,2 @@
1
+ h1. Announcement JS file
2
+ MagicAnnouncement.show('compositekeys', version);
@@ -0,0 +1,4 @@
1
+ // Version JS file
2
+ var version = "1.1.0";
3
+
4
+ document.write(" - " + version);
@@ -0,0 +1,3 @@
1
+ h1. Version JS file
2
+
3
+ document.write(" - " + version);
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4.3
3
3
  specification_version: 1
4
4
  name: rubigen
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.8
7
- date: 2007-11-04 00:00:00 -04:00
6
+ version: 1.1.0
7
+ date: 2007-11-05 00:00:00 -08:00
8
8
  summary: "A framework to allow Ruby applications to generate file/folder stubs (like the rails command does for Ruby on Rails, and the \xE2\x80\x98script/generate\xE2\x80\x99 command within a Rails application during development)."
9
9
  require_paths:
10
10
  - lib
@@ -67,9 +67,25 @@ files:
67
67
  - lib/rubigen/spec.rb
68
68
  - lib/rubigen/version.rb
69
69
  - log/debug.log
70
+ - rubygems_generators/application_generator/USAGE
71
+ - rubygems_generators/application_generator/application_generator_generator.rb
72
+ - rubygems_generators/application_generator/templates/bin
73
+ - rubygems_generators/application_generator/templates/generator.rb
74
+ - rubygems_generators/application_generator/templates/readme
75
+ - rubygems_generators/application_generator/templates/test.rb
76
+ - rubygems_generators/application_generator/templates/test_generator_helper.rb
77
+ - rubygems_generators/application_generator/templates/usage
78
+ - rubygems_generators/component_generator/USAGE
79
+ - rubygems_generators/component_generator/component_generator_generator.rb
80
+ - rubygems_generators/component_generator/templates/generator.rb
81
+ - rubygems_generators/component_generator/templates/readme
82
+ - rubygems_generators/component_generator/templates/test.rb
83
+ - rubygems_generators/component_generator/templates/test_generator_helper.rb
84
+ - rubygems_generators/component_generator/templates/usage
70
85
  - script/destroy
71
86
  - script/generate
72
87
  - script/txt2html
88
+ - script/txt2js
73
89
  - setup.rb
74
90
  - tasks/deployment.rake
75
91
  - tasks/environment.rake
@@ -77,6 +93,8 @@ files:
77
93
  - test/examples_from_rails/generator_test_helper.rb
78
94
  - test/examples_from_rails/test_rails_resource_generator.rb
79
95
  - test/examples_from_rails/test_rails_scaffold_generator.rb
96
+ - test/test_application_generator_generator.rb
97
+ - test/test_component_generator_generator.rb
80
98
  - test/test_generate_builtin_application.rb
81
99
  - test/test_generate_builtin_test_unit.rb
82
100
  - test/test_generator_helper.rb
@@ -90,10 +108,17 @@ files:
90
108
  - website/index.txt
91
109
  - website/javascripts/rounded_corners_lite.inc.js
92
110
  - website/stylesheets/screen.css
111
+ - website/template.js
93
112
  - website/template.rhtml
113
+ - website/version-raw.js
114
+ - website/version-raw.txt
115
+ - website/version.js
116
+ - website/version.txt
94
117
  test_files:
95
118
  - test/examples_from_rails/test_rails_resource_generator.rb
96
119
  - test/examples_from_rails/test_rails_scaffold_generator.rb
120
+ - test/test_application_generator_generator.rb
121
+ - test/test_component_generator_generator.rb
97
122
  - test/test_generate_builtin_application.rb
98
123
  - test/test_generate_builtin_test_unit.rb
99
124
  - test/test_generator_helper.rb
@@ -111,6 +136,8 @@ extra_rdoc_files:
111
136
  - Todo.txt
112
137
  - app_generators/ruby_app/templates/README.txt
113
138
  - website/index.txt
139
+ - website/version-raw.txt
140
+ - website/version.txt
114
141
  executables:
115
142
  - install_rubigen_scripts
116
143
  - ruby_app