rubigen 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/History.txt +3 -0
  2. data/License.txt +17 -0
  3. data/Manifest.txt +119 -0
  4. data/README.txt +204 -0
  5. data/Rakefile +142 -0
  6. data/bin/ruby_app +12 -0
  7. data/examples/rails_generators/applications/app/USAGE +16 -0
  8. data/examples/rails_generators/applications/app/app_generator.rb +177 -0
  9. data/examples/rails_generators/components/controller/USAGE +29 -0
  10. data/examples/rails_generators/components/controller/controller_generator.rb +37 -0
  11. data/examples/rails_generators/components/controller/templates/controller.rb +10 -0
  12. data/examples/rails_generators/components/controller/templates/functional_test.rb +18 -0
  13. data/examples/rails_generators/components/controller/templates/helper.rb +2 -0
  14. data/examples/rails_generators/components/controller/templates/view.html.erb +2 -0
  15. data/examples/rails_generators/components/integration_test/USAGE +8 -0
  16. data/examples/rails_generators/components/integration_test/integration_test_generator.rb +16 -0
  17. data/examples/rails_generators/components/integration_test/templates/integration_test.rb +10 -0
  18. data/examples/rails_generators/components/mailer/USAGE +16 -0
  19. data/examples/rails_generators/components/mailer/mailer_generator.rb +34 -0
  20. data/examples/rails_generators/components/mailer/templates/fixture.erb +3 -0
  21. data/examples/rails_generators/components/mailer/templates/fixture.rhtml +0 -0
  22. data/examples/rails_generators/components/mailer/templates/mailer.rb +13 -0
  23. data/examples/rails_generators/components/mailer/templates/unit_test.rb +37 -0
  24. data/examples/rails_generators/components/mailer/templates/view.erb +3 -0
  25. data/examples/rails_generators/components/mailer/templates/view.rhtml +0 -0
  26. data/examples/rails_generators/components/migration/USAGE +24 -0
  27. data/examples/rails_generators/components/migration/migration_generator.rb +20 -0
  28. data/examples/rails_generators/components/migration/templates/migration.rb +7 -0
  29. data/examples/rails_generators/components/model/USAGE +27 -0
  30. data/examples/rails_generators/components/model/model_generator.rb +38 -0
  31. data/examples/rails_generators/components/model/templates/fixtures.yml +15 -0
  32. data/examples/rails_generators/components/model/templates/migration.rb +14 -0
  33. data/examples/rails_generators/components/model/templates/model.rb +2 -0
  34. data/examples/rails_generators/components/model/templates/unit_test.rb +10 -0
  35. data/examples/rails_generators/components/observer/USAGE +13 -0
  36. data/examples/rails_generators/components/observer/observer_generator.rb +16 -0
  37. data/examples/rails_generators/components/observer/templates/observer.rb +2 -0
  38. data/examples/rails_generators/components/observer/templates/unit_test.rb +10 -0
  39. data/examples/rails_generators/components/plugin/USAGE +25 -0
  40. data/examples/rails_generators/components/plugin/plugin_generator.rb +39 -0
  41. data/examples/rails_generators/components/plugin/templates/MIT-LICENSE +20 -0
  42. data/examples/rails_generators/components/plugin/templates/README +13 -0
  43. data/examples/rails_generators/components/plugin/templates/Rakefile +22 -0
  44. data/examples/rails_generators/components/plugin/templates/USAGE +8 -0
  45. data/examples/rails_generators/components/plugin/templates/generator.rb +8 -0
  46. data/examples/rails_generators/components/plugin/templates/init.rb +1 -0
  47. data/examples/rails_generators/components/plugin/templates/install.rb +1 -0
  48. data/examples/rails_generators/components/plugin/templates/plugin.rb +1 -0
  49. data/examples/rails_generators/components/plugin/templates/tasks.rake +4 -0
  50. data/examples/rails_generators/components/plugin/templates/uninstall.rb +1 -0
  51. data/examples/rails_generators/components/plugin/templates/unit_test.rb +8 -0
  52. data/examples/rails_generators/components/resource/USAGE +23 -0
  53. data/examples/rails_generators/components/resource/resource_generator.rb +72 -0
  54. data/examples/rails_generators/components/resource/templates/USAGE +18 -0
  55. data/examples/rails_generators/components/resource/templates/controller.rb +2 -0
  56. data/examples/rails_generators/components/resource/templates/fixtures.yml +0 -0
  57. data/examples/rails_generators/components/resource/templates/functional_test.rb +20 -0
  58. data/examples/rails_generators/components/resource/templates/helper.rb +2 -0
  59. data/examples/rails_generators/components/scaffold/USAGE +25 -0
  60. data/examples/rails_generators/components/scaffold/scaffold_generator.rb +90 -0
  61. data/examples/rails_generators/components/scaffold/templates/controller.rb +85 -0
  62. data/examples/rails_generators/components/scaffold/templates/functional_test.rb +57 -0
  63. data/examples/rails_generators/components/scaffold/templates/helper.rb +2 -0
  64. data/examples/rails_generators/components/scaffold/templates/layout.html.erb +17 -0
  65. data/examples/rails_generators/components/scaffold/templates/style.css +74 -0
  66. data/examples/rails_generators/components/scaffold/templates/view_edit.html.erb +19 -0
  67. data/examples/rails_generators/components/scaffold/templates/view_index.html.erb +24 -0
  68. data/examples/rails_generators/components/scaffold/templates/view_new.html.erb +18 -0
  69. data/examples/rails_generators/components/scaffold/templates/view_show.html.erb +10 -0
  70. data/examples/rails_generators/components/session_migration/USAGE +10 -0
  71. data/examples/rails_generators/components/session_migration/session_migration_generator.rb +18 -0
  72. data/examples/rails_generators/components/session_migration/templates/migration.rb +16 -0
  73. data/examples/rails_generators/components/web_service/USAGE +24 -0
  74. data/examples/rails_generators/components/web_service/templates/api_definition.rb +5 -0
  75. data/examples/rails_generators/components/web_service/templates/controller.rb +8 -0
  76. data/examples/rails_generators/components/web_service/templates/functional_test.rb +19 -0
  77. data/examples/rails_generators/components/web_service/web_service_generator.rb +29 -0
  78. data/lib/rubigen/base.rb +168 -0
  79. data/lib/rubigen/commands.rb +632 -0
  80. data/lib/rubigen/generated_attribute.rb +40 -0
  81. data/lib/rubigen/generators/applications/ruby_app/USAGE +10 -0
  82. data/lib/rubigen/generators/applications/ruby_app/ruby_app_generator.rb +78 -0
  83. data/lib/rubigen/generators/applications/ruby_app/templates/README.txt +1 -0
  84. data/lib/rubigen/generators/applications/ruby_app/templates/configs/empty.log +0 -0
  85. data/lib/rubigen/generators/applications/ruby_app/templates/fresh_rakefile +10 -0
  86. data/lib/rubigen/generators/applications/ruby_app/templates/module.rb +5 -0
  87. data/lib/rubigen/generators/applications/ruby_app/templates/script/generate +13 -0
  88. data/lib/rubigen/generators/applications/ruby_app/templates/test_helper.rb +2 -0
  89. data/lib/rubigen/generators/components/test_unit/USAGE +14 -0
  90. data/lib/rubigen/generators/components/test_unit/templates/test +14 -0
  91. data/lib/rubigen/generators/components/test_unit/test_unit_generator.rb +26 -0
  92. data/lib/rubigen/helpers/generator_test_helper.rb +133 -0
  93. data/lib/rubigen/lookup.rb +296 -0
  94. data/lib/rubigen/manifest.rb +51 -0
  95. data/lib/rubigen/options.rb +136 -0
  96. data/lib/rubigen/scripts/destroy.rb +27 -0
  97. data/lib/rubigen/scripts/generate.rb +7 -0
  98. data/lib/rubigen/scripts/update.rb +12 -0
  99. data/lib/rubigen/scripts.rb +69 -0
  100. data/lib/rubigen/simple_logger.rb +44 -0
  101. data/lib/rubigen/spec.rb +42 -0
  102. data/lib/rubigen/version.rb +9 -0
  103. data/lib/rubigen.rb +44 -0
  104. data/script/destroy +9 -0
  105. data/script/generate +9 -0
  106. data/script/txt2html +65 -0
  107. data/setup.rb +1585 -0
  108. data/test/examples_from_rails/generator_test_helper.rb +195 -0
  109. data/test/examples_from_rails/test_rails_resource_generator.rb +106 -0
  110. data/test/examples_from_rails/test_rails_scaffold_generator.rb +185 -0
  111. data/test/test_generate_builtin_application.rb +24 -0
  112. data/test/test_generate_builtin_test_unit.rb +22 -0
  113. data/test/test_helper.rb +33 -0
  114. data/test/test_lookup.rb +103 -0
  115. data/website/index.html +352 -0
  116. data/website/index.txt +252 -0
  117. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  118. data/website/stylesheets/screen.css +138 -0
  119. data/website/template.rhtml +44 -0
  120. metadata +183 -0
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == =0.1.0 2007-08-17
2
+ * 1 major enhancement:
3
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,17 @@
1
+ Copyright (c) 2007 Dr Nic Williams
2
+ Permission is hereby granted, free of charge, to any person obtaining
3
+ a copy of this software and associated documentation files (the
4
+ "Software"), to deal in the Software without restriction, including
5
+ without limitation the rights to use, copy, modify, merge, publish,
6
+ distribute, sublicense, and/or sell copies of the Software, and to
7
+ permit persons to whom the Software is furnished to do so, subject to
8
+ the following conditions:
9
+ The above copyright notice and this permission notice shall be
10
+ included in all copies or substantial portions of the Software.
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
15
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
16
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
17
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,119 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/ruby_app
7
+ examples/rails_generators/applications/app/USAGE
8
+ examples/rails_generators/applications/app/app_generator.rb
9
+ examples/rails_generators/components/controller/USAGE
10
+ examples/rails_generators/components/controller/controller_generator.rb
11
+ examples/rails_generators/components/controller/templates/controller.rb
12
+ examples/rails_generators/components/controller/templates/functional_test.rb
13
+ examples/rails_generators/components/controller/templates/helper.rb
14
+ examples/rails_generators/components/controller/templates/view.html.erb
15
+ examples/rails_generators/components/integration_test/USAGE
16
+ examples/rails_generators/components/integration_test/integration_test_generator.rb
17
+ examples/rails_generators/components/integration_test/templates/integration_test.rb
18
+ examples/rails_generators/components/mailer/USAGE
19
+ examples/rails_generators/components/mailer/mailer_generator.rb
20
+ examples/rails_generators/components/mailer/templates/fixture.erb
21
+ examples/rails_generators/components/mailer/templates/fixture.rhtml
22
+ examples/rails_generators/components/mailer/templates/mailer.rb
23
+ examples/rails_generators/components/mailer/templates/unit_test.rb
24
+ examples/rails_generators/components/mailer/templates/view.erb
25
+ examples/rails_generators/components/mailer/templates/view.rhtml
26
+ examples/rails_generators/components/migration/USAGE
27
+ examples/rails_generators/components/migration/migration_generator.rb
28
+ examples/rails_generators/components/migration/templates/migration.rb
29
+ examples/rails_generators/components/model/USAGE
30
+ examples/rails_generators/components/model/model_generator.rb
31
+ examples/rails_generators/components/model/templates/fixtures.yml
32
+ examples/rails_generators/components/model/templates/migration.rb
33
+ examples/rails_generators/components/model/templates/model.rb
34
+ examples/rails_generators/components/model/templates/unit_test.rb
35
+ examples/rails_generators/components/observer/USAGE
36
+ examples/rails_generators/components/observer/observer_generator.rb
37
+ examples/rails_generators/components/observer/templates/observer.rb
38
+ examples/rails_generators/components/observer/templates/unit_test.rb
39
+ examples/rails_generators/components/plugin/USAGE
40
+ examples/rails_generators/components/plugin/plugin_generator.rb
41
+ examples/rails_generators/components/plugin/templates/MIT-LICENSE
42
+ examples/rails_generators/components/plugin/templates/README
43
+ examples/rails_generators/components/plugin/templates/Rakefile
44
+ examples/rails_generators/components/plugin/templates/USAGE
45
+ examples/rails_generators/components/plugin/templates/generator.rb
46
+ examples/rails_generators/components/plugin/templates/init.rb
47
+ examples/rails_generators/components/plugin/templates/install.rb
48
+ examples/rails_generators/components/plugin/templates/plugin.rb
49
+ examples/rails_generators/components/plugin/templates/tasks.rake
50
+ examples/rails_generators/components/plugin/templates/uninstall.rb
51
+ examples/rails_generators/components/plugin/templates/unit_test.rb
52
+ examples/rails_generators/components/resource/USAGE
53
+ examples/rails_generators/components/resource/resource_generator.rb
54
+ examples/rails_generators/components/resource/templates/USAGE
55
+ examples/rails_generators/components/resource/templates/controller.rb
56
+ examples/rails_generators/components/resource/templates/fixtures.yml
57
+ examples/rails_generators/components/resource/templates/functional_test.rb
58
+ examples/rails_generators/components/resource/templates/helper.rb
59
+ examples/rails_generators/components/scaffold/USAGE
60
+ examples/rails_generators/components/scaffold/scaffold_generator.rb
61
+ examples/rails_generators/components/scaffold/templates/controller.rb
62
+ examples/rails_generators/components/scaffold/templates/functional_test.rb
63
+ examples/rails_generators/components/scaffold/templates/helper.rb
64
+ examples/rails_generators/components/scaffold/templates/layout.html.erb
65
+ examples/rails_generators/components/scaffold/templates/style.css
66
+ examples/rails_generators/components/scaffold/templates/view_edit.html.erb
67
+ examples/rails_generators/components/scaffold/templates/view_index.html.erb
68
+ examples/rails_generators/components/scaffold/templates/view_new.html.erb
69
+ examples/rails_generators/components/scaffold/templates/view_show.html.erb
70
+ examples/rails_generators/components/session_migration/USAGE
71
+ examples/rails_generators/components/session_migration/session_migration_generator.rb
72
+ examples/rails_generators/components/session_migration/templates/migration.rb
73
+ examples/rails_generators/components/web_service/USAGE
74
+ examples/rails_generators/components/web_service/templates/api_definition.rb
75
+ examples/rails_generators/components/web_service/templates/controller.rb
76
+ examples/rails_generators/components/web_service/templates/functional_test.rb
77
+ examples/rails_generators/components/web_service/web_service_generator.rb
78
+ lib/rubigen.rb
79
+ lib/rubigen/base.rb
80
+ lib/rubigen/commands.rb
81
+ lib/rubigen/generated_attribute.rb
82
+ lib/rubigen/generators/applications/ruby_app/USAGE
83
+ lib/rubigen/generators/applications/ruby_app/ruby_app_generator.rb
84
+ lib/rubigen/generators/applications/ruby_app/templates/README.txt
85
+ lib/rubigen/generators/applications/ruby_app/templates/configs/empty.log
86
+ lib/rubigen/generators/applications/ruby_app/templates/fresh_rakefile
87
+ lib/rubigen/generators/applications/ruby_app/templates/module.rb
88
+ lib/rubigen/generators/applications/ruby_app/templates/script/generate
89
+ lib/rubigen/generators/applications/ruby_app/templates/test_helper.rb
90
+ lib/rubigen/generators/components/test_unit/USAGE
91
+ lib/rubigen/generators/components/test_unit/templates/test
92
+ lib/rubigen/generators/components/test_unit/test_unit_generator.rb
93
+ lib/rubigen/helpers/generator_test_helper.rb
94
+ lib/rubigen/lookup.rb
95
+ lib/rubigen/manifest.rb
96
+ lib/rubigen/options.rb
97
+ lib/rubigen/scripts.rb
98
+ lib/rubigen/scripts/destroy.rb
99
+ lib/rubigen/scripts/generate.rb
100
+ lib/rubigen/scripts/update.rb
101
+ lib/rubigen/simple_logger.rb
102
+ lib/rubigen/spec.rb
103
+ lib/rubigen/version.rb
104
+ script/destroy
105
+ script/generate
106
+ script/txt2html
107
+ setup.rb
108
+ test/examples_from_rails/generator_test_helper.rb
109
+ test/examples_from_rails/test_rails_resource_generator.rb
110
+ test/examples_from_rails/test_rails_scaffold_generator.rb
111
+ test/test_generate_builtin_application.rb
112
+ test/test_generate_builtin_test_unit.rb
113
+ test/test_helper.rb
114
+ test/test_lookup.rb
115
+ website/index.html
116
+ website/index.txt
117
+ website/javascripts/rounded_corners_lite.inc.js
118
+ website/stylesheets/screen.css
119
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,204 @@
1
+ = RubiGen - Ruby Generator Framework
2
+
3
+ A framework to allow Ruby applications to generate file/folder stubs
4
+ (like the `rails` command does for Ruby on Rails, and the 'script/generate'
5
+ command within a Rails application during development).
6
+
7
+ == Background
8
+
9
+ RubiGen is originally extracted from Ruby on Rails (specifically the rails_generator
10
+ from its railties gem).
11
+
12
+ The rails_generator was hardcoded with Rails-specific dependencies (`RAILS_ROOT`),
13
+ Rails generators ('app' = Rails application; 'model' = Rails model+tests+migration),
14
+ and generally assumed it was the only generator framework within the Ruby world (it was).
15
+ So, any RubyGem whose name ended with '_generator' was assumed to be a generator for
16
+ a Rails application.
17
+
18
+ But if you are developing a Merb application, then you may want a different set of generators.
19
+ If you are developing a RubyGem, then you will want a different set of generators.
20
+
21
+ RubiGen exists to give different development environments their own generator framework.
22
+
23
+ == Installation
24
+
25
+ RubiGen is only required at development time, and normally isn't required at deployment time
26
+ (unless your application uses it to generate files etc for its users).
27
+
28
+ On your development machine:
29
+
30
+ gem install rubigen -y
31
+
32
+ == Usage
33
+
34
+ RubiGen will be normally integrated into another RubyGem, such as `newgem` or `merb` or `camping`,
35
+ rather than be used on its own.
36
+
37
+ These frameworks might use RubiGen for two reasons:
38
+
39
+ 1. To generate an initial stub for developers, e.g. `rails` generated a stub to write a Rails application.
40
+ `newgem` generates a stub to write a RubyGem.
41
+ BTW - RubiGen has a builtin application `ruby_app` which generates a bare-bones Ruby application
42
+ stub (lib, test, and script folders, plus a Rakefile, and a script/generate script)
43
+ 2. To generate components within their development areas, e.g. Rails had its `script/generate`
44
+ script within each Rails application, which hooked back into the rails_generator to lookup
45
+ and execute generators.
46
+
47
+ So, there are two steps to integrating RubiGen into your framework:
48
+
49
+ 1. Use it to generate an initial stub for the developers of your framework. This would create the folders
50
+ (`lib/app`, `test`, `script`, `doc`, `log`, etc) and starting files (`Rakefile`,
51
+ `README.txt`, `test/test_helper.rb` etc). Importantly, it would generate a `script/generate` file.
52
+ The `script/generate` file (example below) will allow developers of your framework to
53
+ generate components/extensions within the framework.
54
+ RubiGen allows you to restrict which generators are available. For example, within
55
+ RubyGem development environment (as generated by `newgem`), the `script/generator`
56
+ only shows `rubygem`-related generators. Merb could restrict `script/generator`
57
+ to only show Merb related generators (or perhaps Merb and/or Rails generators)
58
+ 2. Your framework RubyGem (e.g. `newgem` or `merb` RubyGems) needs to add `rubigen` as a
59
+ dependency, so that users of your RubyGem can access the generator framework.
60
+
61
+ = Creating generators
62
+
63
+ There are two types of generators:
64
+
65
+ 1. Application Generators - used by developers of your framework to get started.
66
+ Generally, you will create one Application Generator for your framework.
67
+ It generates a base stub (such as the `rails` stub for new Rails applications)
68
+ for your framework users.
69
+ 2. Component Generators - used by developers to extend their application.
70
+ You may include 1+ built-in generators with your framework.
71
+ Developers can also write generators for your framework, and like Rails' generator
72
+ install them in various places and have access to their via RubiGen.
73
+
74
+ == Creating an Application Generator for your Framework
75
+
76
+ Without RubiGen, to give your users a head start and create a stub for them, you will
77
+ copiously use `mkdir_p` and `File.open`. Your script will either be primitive (only
78
+ create the bare folders and very few files) or it will be very long and unreadable
79
+ (ok, perhaps I'm just talking about the `newgem` script, which I am dubiously responsible
80
+ for... :P).
81
+
82
+ With RubiGen, you can create stubs using powerful, yet simple, syntax. Templates are
83
+ extracted into a `templates` folder, and activating the generator from a script requires
84
+ only a few lines of code.
85
+
86
+ These are the `newgem` files related to its Application Generator.
87
+
88
+ bin/
89
+ bin/newgem # Appliction Generator script; Usage: newgem gemname [options]
90
+ app_generators/
91
+ app_generators/newgem/
92
+ app_generators/newgem/newgem_generator.rb
93
+ app_generators/newgem/USAGE
94
+ app_generators/newgem/templates/
95
+ app_generators/newgem/templates/app.rb
96
+ app_generators/newgem/templates/History.txt
97
+ app_generators/newgem/templates/... lots and lots of templates
98
+
99
+ The `bin/newgem` script is very simple, and looks like:
100
+
101
+ require 'rubygems'
102
+ require 'rubigen'
103
+
104
+ if %w(-v --version).include? ARGV.first
105
+ require 'newgem/version'
106
+ puts "#{File.basename($0)} #{Newgem::VERSION::STRING}"
107
+ exit(0)
108
+ end
109
+
110
+ require 'rubigen/scripts/generate'
111
+ RubiGen::Base.use_application_sources!
112
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'newgem')
113
+
114
+ You can copy and paste this for your own generator script, and place it in your RubyGem's `bin` folder.
115
+ Change `newgem` to your RubyGem's name in the script above (and in all the folders listed above too)
116
+
117
+ NOTE: If you leave `newgem` there, then it will execute the `newgem_generator.rb` generator;
118
+ as the generators are loaded from all RubyGem's having `/app_generators` folders.
119
+
120
+ So, for your RubyGem, you need to keep the `/app_generators` folder (as you are creating an
121
+ Application Generator, not a Component Generator), but change `newgem` to `your gem name` in
122
+ all the subfolders and files. ESPECIALLY `newgem_generator.rb` -> `yourgem_generator.rb`,
123
+ as this is how the generator is discovered (via `RubiGen::Base.use_application_sources!`).
124
+
125
+ All the generator work is performed within `yourgem_generator.rb`. A stub for it will be:
126
+
127
+ require 'rbconfig'
128
+
129
+ class YourgemGenerator < RubiGen::Base
130
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
131
+ Config::CONFIG['ruby_install_name'])
132
+
133
+ default_options :shebang => DEFAULT_SHEBANG,
134
+ :an_option => 'some_default'
135
+
136
+ attr_reader :app_name, :module_name
137
+
138
+ def initialize(runtime_args, runtime_options = {})
139
+ super
140
+ usage if args.empty?
141
+ @destination_root = args.shift
142
+ @app_name = File.basename(File.expand_path(@destination_root))
143
+ @module_name = app_name.camelize
144
+ extract_options
145
+ end
146
+
147
+ def manifest
148
+ # Use /usr/bin/env if no special shebang was specified
149
+ script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
150
+ windows = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
151
+
152
+ record do |m|
153
+ # Root directory and all subdirectories.
154
+ m.directory ''
155
+ BASEDIRS.each { |path| m.directory path }
156
+
157
+ # Root
158
+ m.template_copy_each %w( Rakefile )
159
+ m.file_copy_each %w( README.txt )
160
+
161
+ # Test helper
162
+ m.template "test_helper.rb", "test/test_helper.rb"
163
+
164
+ # Scripts
165
+ %w( generate ).each do |file|
166
+ m.template "script/#{file}", "script/#{file}", script_options
167
+ m.template "script/win_script.cmd", "script/#{file}.cmd",
168
+ :assigns => { :filename => file } if windows
169
+ end
170
+
171
+ end
172
+ end
173
+
174
+ protected
175
+ def banner
176
+ <<-EOS
177
+ Create a stub for #{File.basename $0} to get started.
178
+
179
+ Usage: #{File.basename $0} /path/to/your/app [options]"
180
+ EOS
181
+ end
182
+
183
+ def add_options!(opts)
184
+ opts.separator ''
185
+ opts.separator "#{File.basename $0} options:"
186
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
187
+ end
188
+
189
+ # Installation skeleton. Intermediate directories are automatically
190
+ # created so don't sweat their absence here.
191
+ BASEDIRS = %w(
192
+ doc
193
+ lib
194
+ log
195
+ script
196
+ test
197
+ tmp
198
+ )
199
+ end
200
+
201
+ Easy peasy.
202
+
203
+ == Creating a Component Generator for your Framework
204
+
data/Rakefile ADDED
@@ -0,0 +1,142 @@
1
+ require 'rubygems'
2
+ begin
3
+ require 'rake'
4
+ rescue LoadError
5
+ puts 'This script should only be accessed via the "rake" command.'
6
+ puts 'Installation: gem install rake -y'
7
+ exit
8
+ end
9
+ require 'rake/clean'
10
+ require 'rake/testtask'
11
+ require 'rake/packagetask'
12
+ require 'rake/gempackagetask'
13
+ require 'rake/rdoctask'
14
+ require 'rake/contrib/rubyforgepublisher'
15
+ require 'fileutils'
16
+ begin
17
+ require 'hoe'
18
+ rescue LoadError
19
+ puts 'This Rakefile requires the "hoe" RubyGem.'
20
+ puts 'Installation: gem install hoe -y'
21
+ exit
22
+ end
23
+
24
+
25
+
26
+ include FileUtils
27
+ require File.join(File.dirname(__FILE__), 'lib', 'rubigen', 'version')
28
+
29
+ AUTHOR = 'Dr Nic Williams' # can also be an array of Authors
30
+ EMAIL = "drnicwilliams@gmail.com"
31
+ DESCRIPTION = "description of gem"
32
+ GEM_NAME = 'rubigen' # what ppl will type to install your gem
33
+
34
+ @config_file = "~/.rubyforge/user-config.yml"
35
+ @config = nil
36
+ def rubyforge_username
37
+ unless @config
38
+ begin
39
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
40
+ rescue
41
+ puts <<-EOS
42
+ ERROR: No rubyforge config file found: #{@config_file}"
43
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
44
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
45
+ EOS
46
+ exit
47
+ end
48
+ end
49
+ @rubyforge_username ||= @config["username"]
50
+ end
51
+
52
+ RUBYFORGE_PROJECT = 'rubigen' # The unix name for your project
53
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
54
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
55
+
56
+ NAME = "rubigen"
57
+ REV = nil
58
+ # UNCOMMENT IF REQUIRED:
59
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
60
+ VERS = Rubigen::VERSION::STRING + (REV ? ".#{REV}" : "")
61
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
62
+ # RDOC_OPTS = ['--quiet', '--title', 'rubigen documentation',
63
+ # "--opname", "index.html",
64
+ # "--line-numbers",
65
+ # "--main", "README",
66
+ # "--inline-source"]
67
+
68
+ class Hoe
69
+ def extra_deps
70
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
71
+ @extra_deps
72
+ end
73
+ end
74
+
75
+ # Generate all the Rake tasks
76
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
77
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
78
+ p.author = AUTHOR
79
+ p.description = DESCRIPTION
80
+ p.email = EMAIL
81
+ p.summary = DESCRIPTION
82
+ p.url = HOMEPATH
83
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
84
+ p.test_globs = ["test/**/test_*.rb"]
85
+ p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
86
+
87
+ # == Optional
88
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
89
+ # An array of rubygem dependencies [name, version], e.g. [ ['activesupport', '>= 1.3.1'] ]
90
+ p.extra_deps = [['activesupport', '>= 1.3.1']]
91
+
92
+ end
93
+
94
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
95
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
96
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
97
+
98
+ desc 'Generate website files'
99
+ task :website_generate do
100
+ Dir['website/**/*.txt'].each do |txt|
101
+ sh %{ ruby script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
102
+ end
103
+ end
104
+
105
+ desc 'Upload website files to rubyforge'
106
+ task :website_upload do
107
+ host = "#{rubyforge_username}@rubyforge.org"
108
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
109
+ local_dir = 'website'
110
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
111
+ end
112
+
113
+ desc 'Generate and upload website files'
114
+ task :website => [:website_generate, :website_upload, :publish_docs]
115
+
116
+ desc 'Release the website and new gem version'
117
+ task :deploy => [:check_version, :website, :release] do
118
+ puts "Remember to create SVN tag:"
119
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
120
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
121
+ puts "Suggested comment:"
122
+ puts "Tagging release #{CHANGES}"
123
+ end
124
+
125
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
126
+ task :local_deploy => [:website_generate, :install_gem]
127
+
128
+ task :check_version do
129
+ unless ENV['VERSION']
130
+ puts 'Must pass a VERSION=x.y.z release version'
131
+ exit
132
+ end
133
+ unless ENV['VERSION'] == VERS
134
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
135
+ exit
136
+ end
137
+ end
138
+
139
+ desc 'Install the package as a gem'
140
+ task :install_gem_no_doc => [:clean, :package] do
141
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
142
+ end
data/bin/ruby_app ADDED
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../lib/rubigen/version'
2
+ if %w(--version -v).include? ARGV.first
3
+ puts "Rails #{RubiGen::VERSION::STRING}"
4
+ exit(0)
5
+ end
6
+
7
+ app_path = ARGV.first
8
+
9
+ require File.dirname(__FILE__) + '/../lib/rubigen'
10
+ require 'rubigen/scripts/generate'
11
+ RubiGen::Base.use_application_sources!
12
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'ruby_app')
@@ -0,0 +1,16 @@
1
+ Description:
2
+ The 'rails' command creates a new Rails application with a default
3
+ directory structure and configuration at the path you specify.
4
+
5
+ Example:
6
+ rails ~/Code/Ruby/weblog
7
+
8
+ This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
9
+ See the README in the newly created application to get going.
10
+
11
+ WARNING:
12
+ Only specify --without-gems if you did not use gems to install Rails.
13
+ Your application will expect to find activerecord, actionpack, and
14
+ actionmailer directories in the vendor directory. A popular way to track
15
+ the bleeding edge of Rails development is to checkout from source control
16
+ directly to the vendor directory. See http://dev.rubyonrails.org/