newgem 0.11.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/History.txt +42 -0
  2. data/Manifest.txt +84 -17
  3. data/README.txt +3 -2
  4. data/Rakefile +4 -106
  5. data/Todo.txt +1 -1
  6. data/app_generators/newgem/newgem_generator.rb +172 -0
  7. data/{templates → app_generators/newgem/templates}/History.txt +1 -1
  8. data/{templates → app_generators/newgem/templates}/License.txt +1 -1
  9. data/app_generators/newgem/templates/README.txt +1 -0
  10. data/app_generators/newgem/templates/Rakefile +4 -0
  11. data/{templates → app_generators/newgem/templates}/app.rb +3 -3
  12. data/app_generators/newgem/templates/config/hoe.rb +73 -0
  13. data/app_generators/newgem/templates/config/requirements.rb +17 -0
  14. data/app_generators/newgem/templates/empty.log +0 -0
  15. data/app_generators/newgem/templates/module.rb +5 -0
  16. data/app_generators/newgem/templates/script/destroy +14 -0
  17. data/app_generators/newgem/templates/script/generate +14 -0
  18. data/{templates → app_generators/newgem/templates}/setup.rb +0 -0
  19. data/{templates → app_generators/newgem/templates}/spec.opts +0 -0
  20. data/{templates → app_generators/newgem/templates}/spec.rb +0 -0
  21. data/app_generators/newgem/templates/tasks/deployment.rake +27 -0
  22. data/app_generators/newgem/templates/tasks/environment.rake +7 -0
  23. data/app_generators/newgem/templates/tasks/website.rake +9 -0
  24. data/{templates → app_generators/newgem/templates}/test.rb +1 -1
  25. data/app_generators/newgem/templates/test_helper.rb +2 -0
  26. data/app_generators/newgem/templates/version.rb +9 -0
  27. data/bin/newgem +9 -272
  28. data/bundles/RubyGem.tmbundle/Snippets/History header trunk.tmSnippet +18 -0
  29. data/bundles/RubyGem.tmbundle/Snippets/History header.tmSnippet +18 -0
  30. data/bundles/RubyGem.tmbundle/Syntaxes/Rdoc.tmLanguage +70 -0
  31. data/bundles/RubyGem.tmbundle/info.plist +16 -0
  32. data/config/hoe.rb +48 -0
  33. data/config/svn_branch.rb +15 -0
  34. data/lib/newgem.rb +2 -3
  35. data/lib/newgem/quick_template.rb +28 -0
  36. data/lib/newgem/tasks.rb +1 -0
  37. data/lib/newgem/version.rb +1 -1
  38. data/newgem_generators/install_website/USAGE +5 -0
  39. data/newgem_generators/install_website/install_website_generator.rb +76 -0
  40. data/{templates/scripts → newgem_generators/install_website/templates/script}/txt2html +15 -8
  41. data/newgem_generators/install_website/templates/tasks/website.rake +17 -0
  42. data/{templates → newgem_generators/install_website/templates}/website/index.html +2 -2
  43. data/newgem_generators/install_website/templates/website/index.txt +39 -0
  44. data/newgem_theme_generators/plain/USAGE +5 -0
  45. data/newgem_theme_generators/plain/plain_generator.rb +54 -0
  46. data/{templates → newgem_theme_generators/plain/templates}/website/javascripts/rounded_corners_lite.inc.js +0 -0
  47. data/{templates → newgem_theme_generators/plain/templates}/website/stylesheets/screen.css +0 -0
  48. data/{templates → newgem_theme_generators/plain/templates}/website/template.rhtml +6 -6
  49. data/rubygems_generators/application_generator/USAGE +28 -0
  50. data/rubygems_generators/application_generator/application_generator_generator.rb +58 -0
  51. data/rubygems_generators/application_generator/templates/bin +12 -0
  52. data/rubygems_generators/application_generator/templates/generator.rb +51 -0
  53. data/rubygems_generators/application_generator/templates/readme +24 -0
  54. data/rubygems_generators/application_generator/templates/test.rb +43 -0
  55. data/rubygems_generators/application_generator/templates/test_generator_helper.rb +19 -0
  56. data/rubygems_generators/application_generator/templates/usage +5 -0
  57. data/rubygems_generators/component_generator/USAGE +29 -0
  58. data/rubygems_generators/component_generator/component_generator_generator.rb +52 -0
  59. data/rubygems_generators/component_generator/templates/generator.rb +51 -0
  60. data/rubygems_generators/component_generator/templates/readme +28 -0
  61. data/rubygems_generators/component_generator/templates/test.rb +43 -0
  62. data/rubygems_generators/component_generator/templates/test_generator_helper.rb +19 -0
  63. data/rubygems_generators/component_generator/templates/usage +5 -0
  64. data/rubygems_generators/executable/executable_generator.rb +53 -0
  65. data/rubygems_generators/executable/templates/app.rb +44 -0
  66. data/rubygems_generators/install_jruby/USAGE +5 -0
  67. data/rubygems_generators/install_jruby/install_jruby_generator.rb +48 -0
  68. data/rubygems_generators/install_jruby/templates/tasks/jruby.rake +7 -0
  69. data/rubygems_generators/install_rspec/USAGE +5 -0
  70. data/rubygems_generators/install_rspec/install_rspec_generator.rb +55 -0
  71. data/rubygems_generators/install_rspec/templates/spec.rb +11 -0
  72. data/rubygems_generators/install_rspec/templates/spec/spec.opts +1 -0
  73. data/rubygems_generators/install_rspec/templates/spec/spec_helper.rb +7 -0
  74. data/rubygems_generators/install_rspec/templates/tasks/rspec.rake +21 -0
  75. data/script/destroy +14 -0
  76. data/script/generate +14 -0
  77. data/{scripts → script}/txt2html +3 -3
  78. data/{scripts → script}/txt2js +0 -0
  79. data/tasks/bundles.rake +12 -0
  80. data/tasks/deployment.rake +27 -0
  81. data/tasks/environment.rake +7 -0
  82. data/tasks/website.rake +19 -0
  83. data/test/test_application_generator_generator.rb +60 -0
  84. data/test/test_executable_generator.rb +28 -0
  85. data/test/test_generate_component_generator.rb +67 -0
  86. data/test/test_generator_helper.rb +19 -0
  87. data/test/test_install_jruby_generator.rb +29 -0
  88. data/test/test_install_rspec_generator.rb +33 -0
  89. data/test/test_install_website_generator.rb +50 -0
  90. data/test/test_newgem_generator.rb +120 -0
  91. data/test/test_plain_generator.rb +37 -0
  92. data/website/images/beginning-ruby.jpg +0 -0
  93. data/website/index.html +8 -6
  94. data/website/index.txt +4 -2
  95. data/website/rubyforge.html +3 -3
  96. data/website/version-raw.js +1 -1
  97. data/website/version.js +1 -1
  98. metadata +111 -27
  99. data/templates/Manifest.txt +0 -15
  100. data/templates/Rakefile +0 -123
  101. data/templates/website/index.txt +0 -38
  102. data/test/test_svn.rb +0 -13
@@ -0,0 +1,28 @@
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.
@@ -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,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,53 @@
1
+ class ExecutableGenerator < RubiGen::Base
2
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
3
+ Config::CONFIG['ruby_install_name'])
4
+
5
+ default_options :shebang => DEFAULT_SHEBANG,
6
+ :author => nil
7
+
8
+ attr_reader :bin_name, :author
9
+
10
+ def initialize(runtime_args, runtime_options = {})
11
+ super
12
+ usage if args.empty?
13
+ @bin_name = args.shift
14
+ extract_options
15
+ end
16
+
17
+ def manifest
18
+ # Use /usr/bin/env if no special shebang was specified
19
+ script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
20
+ dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
21
+ windows = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
22
+
23
+ record do |m|
24
+ # Ensure bin folder exists
25
+ m.directory "bin"
26
+
27
+ # App stub
28
+ m.template "app.rb", "bin/#{bin_name}"
29
+ end
30
+ end
31
+
32
+ protected
33
+ def banner
34
+ <<-EOS
35
+ Create an executable Ruby script that is deployed
36
+ with this RubyGem.
37
+
38
+ USAGE: #{$0} generate bin_name"
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
+ @author = options[:author]
52
+ end
53
+ end
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created <%= "by #{author} " if author %>on <%= (now = Time.now).year %>-<%= now.month %>-<%= now.day %>.
4
+ # Copyright (c) <%= now.year %>. All rights reserved.
5
+
6
+ begin
7
+ require 'rubygems'
8
+ rescue LoadError
9
+ # no rubygems to load, so we fail silently
10
+ end
11
+
12
+ require 'optparse'
13
+
14
+ # NOTE: the option -p/--path= is given as an example, and should probably be replaced in your application.
15
+
16
+ OPTIONS = {
17
+ :path => '~'
18
+ }
19
+ MANDATORY_OPTIONS = %w( )
20
+
21
+ parser = OptionParser.new do |opts|
22
+ opts.banner = <<BANNER
23
+ This application is wonderful because...
24
+
25
+ Usage: #{File.basename($0)} [options]
26
+
27
+ Options are:
28
+ BANNER
29
+ opts.separator ""
30
+ opts.on("-p", "--path=PATH", String,
31
+ "The root path for selecting files",
32
+ "Default: ~") { |OPTIONS[:path]| }
33
+ opts.on("-h", "--help",
34
+ "Show this help message.") { puts opts; exit }
35
+ opts.parse!(ARGV)
36
+
37
+ if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
38
+ puts opts; exit
39
+ end
40
+ end
41
+
42
+ path = OPTIONS[:path]
43
+
44
+ # do stuff
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,48 @@
1
+ class InstallJrubyGenerator < 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 'tasks'
18
+
19
+ m.file_copy_each %w( jruby.rake ), "tasks"
20
+ end
21
+ end
22
+
23
+ protected
24
+ def banner
25
+ <<-EOS
26
+ Creates a ...
27
+
28
+ USAGE: #{$0} #{name} name"
29
+ EOS
30
+ end
31
+
32
+ def add_options!(opts)
33
+ # opts.separator ''
34
+ # opts.separator 'Options:'
35
+ # For each option below, place the default
36
+ # at the top of the file next to "default_options"
37
+ # opts.on("-a", "--author=\"Your Name\"", String,
38
+ # "Some comment about this option",
39
+ # "Default: none") { |options[:author]| }
40
+ end
41
+
42
+ def extract_options
43
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
44
+ # Templates can access these value via the attr_reader-generated methods, but not the
45
+ # raw instance variable value.
46
+ # @author = options[:author]
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ if RUBY_PLATFORM =~ /java/
2
+ require 'java'
3
+ else
4
+ puts "Java RubyGem only! You are not running within jruby."
5
+ puts "Try: jruby -S rake #{ARGV.join(' ')}"
6
+ exit(1)
7
+ end
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,55 @@
1
+ class InstallRspecGenerator < RubiGen::Base
2
+
3
+ default_options :author => nil
4
+
5
+ attr_reader :gem_name, :module_name
6
+
7
+ def initialize(runtime_args, runtime_options = {})
8
+ super
9
+ @gem_name = File.basename(File.expand_path(destination_root))
10
+ @module_name = @gem_name.camelcase
11
+ extract_options
12
+ end
13
+
14
+ def manifest
15
+ record do |m|
16
+ # Ensure appropriate folder(s) exists
17
+ m.directory 'spec'
18
+ m.directory 'tasks'
19
+
20
+ m.template 'spec.rb', "spec/#{gem_name}_spec.rb"
21
+
22
+ m.template_copy_each %w( spec.opts spec_helper.rb ), 'spec'
23
+ m.file_copy_each %w( rspec.rake ), 'tasks'
24
+ end
25
+ end
26
+
27
+ protected
28
+ def banner
29
+ <<-EOS
30
+ Install rspec BDD testing support.
31
+
32
+ Includes a rake task (tasks/rspec.rake) to be loaded by the root Rakefile,
33
+ which provides a "spec" task.
34
+
35
+ USAGE: #{$0} [options]"
36
+ EOS
37
+ end
38
+
39
+ def add_options!(opts)
40
+ # opts.separator ''
41
+ # opts.separator 'Options:'
42
+ # For each option below, place the default
43
+ # at the top of the file next to "default_options"
44
+ # opts.on("-a", "--author=\"Your Name\"", String,
45
+ # "Some comment about this option",
46
+ # "Default: none") { |options[:author]| }
47
+ end
48
+
49
+ def extract_options
50
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
51
+ # Templates can access these value via the attr_reader-generated methods, but not the
52
+ # raw instance variable value.
53
+ # @author = options[:author]
54
+ end
55
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.rubyforge.org/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/*_spec.rb']
21
+ end
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! :rubygems
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! :rubygems, :newgem
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -29,14 +29,14 @@ def convert_syntax(syntax, source)
29
29
  return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
30
30
  end
31
31
 
32
- require File.dirname(__FILE__) + '/../lib/newgem/version.rb'
32
+ require File.join(File.dirname(__FILE__), '/../lib/newgem/version.rb')
33
33
 
34
34
  version = Newgem::VERSION::STRING
35
35
  download = ENV['DOWNLOAD_PATH']
36
36
 
37
37
  if ARGV.length >= 1
38
38
  src, template = ARGV
39
- template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
40
40
 
41
41
  else
42
42
  puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
@@ -54,7 +54,7 @@ File.open(src) do |fsrc|
54
54
  body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
55
55
  ident = syntax_items.length
56
56
  element, syntax, source = $1, $2, $3
57
- syntax_items << "<#{element} class=\"syntax\">#{convert_syntax(syntax, source)}</#{element}>"
57
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
58
58
  "syntax-temp-#{ident}"
59
59
  }
60
60
  title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
File without changes
@@ -0,0 +1,12 @@
1
+ namespace :bundles do
2
+
3
+ desc 'Install TextMate bundles for RubyGems'
4
+ task :tm do
5
+ require 'tmpdir'
6
+ bundle = "RubyGem.tmbundle"
7
+ bundle_dir = File.join(File.dirname(__FILE__), 'bundles/', bundle)
8
+ `cp -R #{bundle_dir} #{Dir.tmpdir}`
9
+ `open "#{File.join(Dir.tmpdir, bundle)}"`
10
+ end
11
+ end
12
+