rubigen 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,352 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ rubigen
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+ </style>
13
+ <script type="text/javascript">
14
+ window.onload = function() {
15
+ settings = {
16
+ tl: { radius: 10 },
17
+ tr: { radius: 10 },
18
+ bl: { radius: 10 },
19
+ br: { radius: 10 },
20
+ antiAlias: true,
21
+ autoPad: true,
22
+ validTags: ["div"]
23
+ }
24
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
25
+ versionBox.applyCornersToAll();
26
+ }
27
+ </script>
28
+ </head>
29
+ <body>
30
+ <div id="main">
31
+ <h1>rubigen</h1>
32
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/rubigen"; return false'>
33
+ <p>Get Version</p>
34
+ <a href="http://rubyforge.org/projects/rubigen" class="numbers">1.0.0</a>
35
+ </div>
36
+ <h1>Ruby Generator Framework</h1>
37
+
38
+
39
+ <h2>What</h2>
40
+
41
+
42
+ <p>A framework to allow Ruby applications to generate file/folder stubs
43
+ (like the <code>rails</code> command does for Ruby on Rails, and the &#8216;script/generate&#8217;
44
+ command within a Rails application during development).</p>
45
+
46
+
47
+ <h2>Background</h2>
48
+
49
+
50
+ <p>RubiGen is originally extracted from Ruby on Rails (specifically the rails_generator
51
+ from its railties gem).</p>
52
+
53
+
54
+ <p>The rails_generator was hardcoded with Rails-specific dependencies (<code>RAILS_ROOT</code>),
55
+ Rails generators (&#8216;app&#8217; = Rails application; &#8216;model&#8217; = Rails model+tests+migration),
56
+ and generally assumed it was the only generator framework within the Ruby world (it was).
57
+ So, any RubyGem whose name ended with &#8216;_generator&#8217; was assumed to be a generator for
58
+ a Rails application.</p>
59
+
60
+
61
+ <p>But if you are developing a Merb application, then you may want a different set of generators.
62
+ If you are developing a RubyGem, then you will want a different set of generators.</p>
63
+
64
+
65
+ <p>RubiGen exists to give different development environments their own generator framework.</p>
66
+
67
+
68
+ <h2>Installing</h2>
69
+
70
+
71
+ <p>RubiGen is only required at development time, and normally isn&#8217;t required at deployment time
72
+ (unless your application uses it to generate files etc for its users).</p>
73
+
74
+
75
+ <p>On your development machine:</p>
76
+
77
+
78
+ <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">rubigen</span></pre></p>
79
+
80
+
81
+ <h2>Usage</h2>
82
+
83
+
84
+ <p>RubiGen will be normally integrated into another RubyGem, such as <code>newgem</code> or <code>merb</code> or <code>camping</code>,
85
+ rather than be used on its own.</p>
86
+
87
+
88
+ <p>These frameworks might use RubiGen for two reasons:</p>
89
+
90
+
91
+ <ol>
92
+ <li>To generate an initial stub for developers, e.g. <code>rails</code> generated a stub to write a Rails application. <code>newgem</code> generates a stub to write a RubyGem. <br/>
93
+ <span class="caps">BTW</span> &#8211; RubiGen has a builtin application <code>ruby_app</code> which generates a bare-bones Ruby application stub (lib, test, and script folders, plus a Rakefile, and a script/generate script)</li>
94
+ <li>To generate components within their development areas, e.g. Rails had its <code>script/generate</code> script within each Rails application, which hooked back into the rails_generator to lookup and execute generators.</li>
95
+ </ol>
96
+
97
+
98
+ <p>So, there are two steps to integrating RubiGen into your framework:</p>
99
+
100
+
101
+ <ol>
102
+ <li>Use it to generate an initial stub for the developers of your framework. This would create the folders
103
+ (<code>lib/app</code>, <code>test</code>, <code>script</code>, <code>doc</code>, <code>log</code>, etc) and starting files (<code>Rakefile</code>,
104
+ <code>README.txt</code>, <code>test/test_helper.rb</code> etc). Importantly, it would generate a <code>script/generate</code> file.
105
+ The <code>script/generate</code> file (example below) will allow developers of your framework to
106
+ generate components/extensions within the framework. <br />
107
+ RubiGen allows you to restrict which generators are available. For example, within
108
+ RubyGem development environment (as generated by <code>newgem</code>), the <code>script/generator</code>
109
+ only shows <code>rubygem</code>-related generators. Merb could restrict <code>script/generator</code>
110
+ to only show Merb related generators (or perhaps Merb and/or Rails generators)</li>
111
+ <li>Your framework RubyGem (e.g. <code>newgem</code> or <code>merb</code> RubyGems) needs to add <code>rubigen</code> as a
112
+ dependency, so that users of your RubyGem can access the generator framework.</li>
113
+ </ol>
114
+
115
+
116
+ <h1>Creating generators</h1>
117
+
118
+
119
+ <p>There are two types of generators:</p>
120
+
121
+
122
+ <ol>
123
+ <li>Application Generators &#8211; used by developers of your framework to get started.
124
+ Generally, you will create one Application Generator for your framework.
125
+ It generates a base stub (such as the <code>rails</code> stub for new Rails applications)
126
+ for your framework users.</li>
127
+ <li>Component Generators &#8211; used by developers to extend their application.
128
+ You may include 1+ built-in generators with your framework.
129
+ Developers can also write generators for your framework, and like Rails&#8217; generator
130
+ install them in various places and have access to their via RubiGen.</li>
131
+ </ol>
132
+
133
+
134
+ <h2>Creating an Application Generator for your Framework</h2>
135
+
136
+
137
+ <h3>Easy way</h3>
138
+
139
+
140
+ <p><a href="http://newgem.rubyforge.org/">newgem</a> (v0.13.0+) can generate an Application Generator
141
+ for a RubyGem.</p>
142
+
143
+
144
+ <ol>
145
+ <li>Create new RubyGem: <code>newgem foobar</code></li>
146
+ <li>Create generator: <code>script/generator application_generator foobar</code></li>
147
+ <li>Update tests + generator</li>
148
+ <li>Install</li>
149
+ <li>Run with: foobar</li>
150
+ </ol>
151
+
152
+
153
+ <p>For more documentation, run <code>script/generator application_generator</code></p>
154
+
155
+
156
+ <h3><span class="caps">DIY</span></h3>
157
+
158
+
159
+ <p>Without RubiGen, to give your users a head start and create a stub for them, you will
160
+ copiously use <code>mkdir_p</code> and <code>File.open</code>. Your script will either be primitive (only
161
+ create the bare folders and very few files) or it will be very long and unreadable
162
+ (ok, perhaps I&#8217;m just talking about the <code>newgem</code> script, which I am dubiously responsible
163
+ for&#8230; :P).</p>
164
+
165
+
166
+ <p>With RubiGen, you can create stubs using powerful, yet simple, syntax. Templates are
167
+ extracted into a <code>templates</code> folder, and activating the generator from a script requires
168
+ only a few lines of code.</p>
169
+
170
+
171
+ <p>These are the <code>newgem</code> files related to its Application Generator.</p>
172
+
173
+
174
+ <pre><code>bin/
175
+ bin/newgem # Appliction Generator script; Usage: newgem gemname [options]
176
+ app_generators/
177
+ app_generators/newgem/
178
+ app_generators/newgem/newgem_generator.rb
179
+ app_generators/newgem/USAGE
180
+ app_generators/newgem/templates/
181
+ app_generators/newgem/templates/app.rb
182
+ app_generators/newgem/templates/History.txt
183
+ app_generators/newgem/templates/... lots and lots of templates</code></pre>
184
+
185
+
186
+ <p>The <code>bin/newgem</code> script is very simple, and looks like:</p>
187
+
188
+
189
+ <p><pre class='syntax'>
190
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">rubygems</span><span class="punct">'</span>
191
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">rubigen</span><span class="punct">'</span>
192
+
193
+ <span class="keyword">if</span> <span class="punct">%w(</span><span class="string">-v --version</span><span class="punct">).</span><span class="ident">include?</span> <span class="constant">ARGV</span><span class="punct">.</span><span class="ident">first</span>
194
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">newgem/version</span><span class="punct">'</span>
195
+ <span class="ident">puts</span> <span class="punct">&quot;</span><span class="string"><span class="expr">#{File.basename($0)}</span> <span class="expr">#{Newgem::VERSION::STRING}</span></span><span class="punct">&quot;</span>
196
+ <span class="ident">exit</span><span class="punct">(</span><span class="number">0</span><span class="punct">)</span>
197
+ <span class="keyword">end</span>
198
+
199
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">rubigen/scripts/generate</span><span class="punct">'</span>
200
+ <span class="constant">RubiGen</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">.</span><span class="ident">use_application_sources!</span>
201
+ <span class="constant">RubiGen</span><span class="punct">::</span><span class="constant">Scripts</span><span class="punct">::</span><span class="constant">Generate</span><span class="punct">.</span><span class="ident">new</span><span class="punct">.</span><span class="ident">run</span><span class="punct">(</span><span class="constant">ARGV</span><span class="punct">,</span> <span class="symbol">:generator</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">newgem</span><span class="punct">')</span>
202
+ </pre></p>
203
+
204
+
205
+ <p>You can copy and paste this for your own generator script, and place it in your RubyGem&#8217;s <code>bin</code> folder.
206
+ Change <code>newgem</code> to your RubyGem&#8217;s name in the script above (and in all the folders listed above too)</p>
207
+
208
+
209
+ <p><span class="caps">NOTE</span>: If you leave <code>newgem</code> there, then it will execute the <code>newgem_generator.rb</code> generator;
210
+ as the generators are loaded from all RubyGem&#8217;s having <code>/app_generators</code> folders.</p>
211
+
212
+
213
+ <p>So, for your RubyGem, you need to keep the <code>/app_generators</code> folder (as you are creating an
214
+ Application Generator, not a Component Generator), but change <code>newgem</code> to <code>your gem name</code> in
215
+ all the subfolders and files. <span class="caps">ESPECIALLY</span> <code>newgem_generator.rb</code> -&gt; <code>yourgem_generator.rb</code>,
216
+ as this is how the generator is discovered (via <code>RubiGen::Base.use_application_sources!</code>).</p>
217
+
218
+
219
+ <p>All the generator work is performed within <code>yourgem_generator.rb</code>. A stub for it will be:</p>
220
+
221
+
222
+ <p><pre class='syntax'>
223
+ <span class="ident">require</span> <span class="punct">'</span><span class="string">rbconfig</span><span class="punct">'</span>
224
+
225
+ <span class="keyword">class </span><span class="class">YourgemGenerator</span> <span class="punct">&lt;</span> <span class="constant">RubiGen</span><span class="punct">::</span><span class="constant">Base</span>
226
+ <span class="constant">DEFAULT_SHEBANG</span> <span class="punct">=</span> <span class="constant">File</span><span class="punct">.</span><span class="ident">join</span><span class="punct">(</span><span class="constant">Config</span><span class="punct">::</span><span class="constant">CONFIG</span><span class="punct">['</span><span class="string">bindir</span><span class="punct">'],</span>
227
+ <span class="constant">Config</span><span class="punct">::</span><span class="constant">CONFIG</span><span class="punct">['</span><span class="string">ruby_install_name</span><span class="punct">'])</span>
228
+
229
+ <span class="ident">default_options</span> <span class="symbol">:shebang</span> <span class="punct">=&gt;</span> <span class="constant">DEFAULT_SHEBANG</span><span class="punct">,</span>
230
+ <span class="symbol">:an_option</span> <span class="punct">=&gt;</span> <span class="punct">'</span><span class="string">some_default</span><span class="punct">'</span>
231
+
232
+ <span class="ident">attr_reader</span> <span class="symbol">:app_name</span><span class="punct">,</span> <span class="symbol">:module_name</span>
233
+
234
+ <span class="keyword">def </span><span class="method">initialize</span><span class="punct">(</span><span class="ident">runtime_args</span><span class="punct">,</span> <span class="ident">runtime_options</span> <span class="punct">=</span> <span class="punct">{})</span>
235
+ <span class="keyword">super</span>
236
+ <span class="ident">usage</span> <span class="keyword">if</span> <span class="ident">args</span><span class="punct">.</span><span class="ident">empty?</span>
237
+ <span class="attribute">@destination_root</span> <span class="punct">=</span> <span class="ident">args</span><span class="punct">.</span><span class="ident">shift</span>
238
+ <span class="attribute">@app_name</span> <span class="punct">=</span> <span class="constant">File</span><span class="punct">.</span><span class="ident">basename</span><span class="punct">(</span><span class="constant">File</span><span class="punct">.</span><span class="ident">expand_path</span><span class="punct">(</span><span class="attribute">@destination_root</span><span class="punct">))</span>
239
+ <span class="attribute">@module_name</span> <span class="punct">=</span> <span class="ident">app_name</span><span class="punct">.</span><span class="ident">camelize</span>
240
+ <span class="ident">extract_options</span>
241
+ <span class="keyword">end</span>
242
+
243
+ <span class="keyword">def </span><span class="method">manifest</span>
244
+ <span class="comment"># Use /usr/bin/env if no special shebang was specified</span>
245
+ <span class="ident">script_options</span> <span class="punct">=</span> <span class="punct">{</span> <span class="symbol">:chmod</span> <span class="punct">=&gt;</span> <span class="number">0755</span><span class="punct">,</span> <span class="symbol">:shebang</span> <span class="punct">=&gt;</span> <span class="ident">options</span><span class="punct">[</span><span class="symbol">:shebang</span><span class="punct">]</span> <span class="punct">==</span> <span class="constant">DEFAULT_SHEBANG</span> <span class="punct">?</span> <span class="constant">nil</span> <span class="punct">:</span> <span class="ident">options</span><span class="punct">[</span><span class="symbol">:shebang</span><span class="punct">]</span> <span class="punct">}</span>
246
+ <span class="ident">windows</span> <span class="punct">=</span> <span class="punct">(</span><span class="constant">RUBY_PLATFORM</span> <span class="punct">=~</span> <span class="punct">/</span><span class="regex">dos|win32|cygwin</span><span class="punct">/</span><span class="ident">i</span><span class="punct">)</span> <span class="punct">||</span> <span class="punct">(</span><span class="constant">RUBY_PLATFORM</span> <span class="punct">=~</span> <span class="punct">/</span><span class="regex">(:?mswin|mingw)</span><span class="punct">/)</span>
247
+
248
+ <span class="ident">record</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">m</span><span class="punct">|</span>
249
+ <span class="comment"># Root directory and all subdirectories.</span>
250
+ <span class="ident">m</span><span class="punct">.</span><span class="ident">directory</span> <span class="punct">'</span><span class="string"></span><span class="punct">'</span>
251
+ <span class="constant">BASEDIRS</span><span class="punct">.</span><span class="ident">each</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">path</span><span class="punct">|</span> <span class="ident">m</span><span class="punct">.</span><span class="ident">directory</span> <span class="ident">path</span> <span class="punct">}</span>
252
+
253
+ <span class="comment"># Root</span>
254
+ <span class="ident">m</span><span class="punct">.</span><span class="ident">template_copy_each</span> <span class="punct">%w(</span><span class="string"> Rakefile </span><span class="punct">)</span>
255
+ <span class="ident">m</span><span class="punct">.</span><span class="ident">file_copy_each</span> <span class="punct">%w(</span><span class="string"> README.txt </span><span class="punct">)</span>
256
+
257
+ <span class="comment"># Test helper</span>
258
+ <span class="ident">m</span><span class="punct">.</span><span class="ident">template</span> <span class="punct">&quot;</span><span class="string">test_helper.rb</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">test/test_helper.rb</span><span class="punct">&quot;</span>
259
+
260
+ <span class="comment"># Scripts</span>
261
+ <span class="punct">%w(</span><span class="string"> generate </span><span class="punct">).</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">file</span><span class="punct">|</span>
262
+ <span class="ident">m</span><span class="punct">.</span><span class="ident">template</span> <span class="punct">&quot;</span><span class="string">script/<span class="expr">#{file}</span></span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">script/<span class="expr">#{file}</span></span><span class="punct">&quot;,</span> <span class="ident">script_options</span>
263
+ <span class="ident">m</span><span class="punct">.</span><span class="ident">template</span> <span class="punct">&quot;</span><span class="string">script/win_script.cmd</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">script/<span class="expr">#{file}</span>.cmd</span><span class="punct">&quot;,</span>
264
+ <span class="symbol">:assigns</span> <span class="punct">=&gt;</span> <span class="punct">{</span> <span class="symbol">:filename</span> <span class="punct">=&gt;</span> <span class="ident">file</span> <span class="punct">}</span> <span class="keyword">if</span> <span class="ident">windows</span>
265
+ <span class="keyword">end</span>
266
+
267
+ <span class="keyword">end</span>
268
+ <span class="keyword">end</span>
269
+
270
+ <span class="ident">protected</span>
271
+ <span class="keyword">def </span><span class="method">banner</span>
272
+ <span class="punct">&lt;&lt;-</span><span class="constant">EOS</span><span class="string">
273
+ Create a stub for <span class="expr">#{File.basename $0}</span> to get started.
274
+
275
+ Usage: <span class="expr">#{File.basename $0}</span> /path/to/your/app [options]&quot;
276
+ </span><span class="constant">EOS</span>
277
+ <span class="keyword">end</span>
278
+
279
+ <span class="keyword">def </span><span class="method">add_options!</span><span class="punct">(</span><span class="ident">opts</span><span class="punct">)</span>
280
+ <span class="ident">opts</span><span class="punct">.</span><span class="ident">separator</span> <span class="punct">'</span><span class="string"></span><span class="punct">'</span>
281
+ <span class="ident">opts</span><span class="punct">.</span><span class="ident">separator</span> <span class="punct">&quot;</span><span class="string"><span class="expr">#{File.basename $0}</span> options:</span><span class="punct">&quot;</span>
282
+ <span class="ident">opts</span><span class="punct">.</span><span class="ident">on</span><span class="punct">(&quot;</span><span class="string">-v</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">--version</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">Show the <span class="expr">#{File.basename($0)}</span> version number and quit.</span><span class="punct">&quot;)</span>
283
+ <span class="keyword">end</span>
284
+
285
+ <span class="comment"># Installation skeleton. Intermediate directories are automatically</span>
286
+ <span class="comment"># created so don't sweat their absence here.</span>
287
+ <span class="constant">BASEDIRS</span> <span class="punct">=</span> <span class="punct">%w(</span><span class="string">
288
+ doc
289
+ lib
290
+ log
291
+ script
292
+ test
293
+ tmp
294
+ </span><span class="punct">)</span>
295
+ <span class="keyword">end</span>
296
+ </pre></p>
297
+
298
+
299
+ <p>Easy peasy.</p>
300
+
301
+
302
+ <h2>Creating a Component Generator for your Framework</h2>
303
+
304
+
305
+ <p>You can include Component Generators in RubyGems, and they will be automatially picked up
306
+ by your framework&#8217;s <code>script/generate</code> script.</p>
307
+
308
+
309
+ <h3>Easy way</h3>
310
+
311
+
312
+ <p>Use <a href="http://newgem.rubyforge.org/">newgem</a>, (v0.13.0+), and run:</p>
313
+
314
+
315
+ <pre>
316
+ script/generate component_generator
317
+ </pre>
318
+
319
+ <p>and follow the instructions.</p>
320
+
321
+
322
+ <h2>Forum</h2>
323
+
324
+
325
+ <p><a href="http://groups.google.com/group/rubigen">http://groups.google.com/group/rubigen</a></p>
326
+
327
+
328
+ <h2>How to submit patches</h2>
329
+
330
+
331
+ <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.
332
+ The trunk repository is <code>svn://rubyforge.org/var/svn/rubigen/trunk</code> for anonymous access.</p>
333
+
334
+
335
+ <h2>License</h2>
336
+
337
+
338
+ <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
339
+
340
+
341
+ <h2>Contact</h2>
342
+
343
+
344
+ <p>Comments are welcome. Send an email to <a href="mailto:drnicwilliams@gmail.com">Dr Nic Williams</a> via the <a href="http://groups.google.com/group/rubigen">forum</a></p>
345
+ <p class="coda">
346
+ <a href="drnicwilliams@gmail.com">Dr Nic Williams</a>, 20th August 2007<br>
347
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
348
+ </p>
349
+ </div>
350
+ <!-- insert site tracking codes here, like Google Urchin -->
351
+ </body>
352
+ </html>
data/website/index.txt ADDED
@@ -0,0 +1,252 @@
1
+ h1. rubigen
2
+
3
+ h1. Ruby Generator Framework
4
+
5
+ h2. What
6
+
7
+ A framework to allow Ruby applications to generate file/folder stubs
8
+ (like the <code>rails</code> command does for Ruby on Rails, and the 'script/generate'
9
+ command within a Rails application during development).
10
+
11
+ h2. Background
12
+
13
+ RubiGen is originally extracted from Ruby on Rails (specifically the rails_generator
14
+ from its railties gem).
15
+
16
+ The rails_generator was hardcoded with Rails-specific dependencies (<code>RAILS_ROOT</code>),
17
+ Rails generators ('app' = Rails application; 'model' = Rails model+tests+migration),
18
+ and generally assumed it was the only generator framework within the Ruby world (it was).
19
+ So, any RubyGem whose name ended with '_generator' was assumed to be a generator for
20
+ a Rails application.
21
+
22
+ But if you are developing a Merb application, then you may want a different set of generators.
23
+ If you are developing a RubyGem, then you will want a different set of generators.
24
+
25
+ RubiGen exists to give different development environments their own generator framework.
26
+
27
+ h2. Installing
28
+
29
+ RubiGen is only required at development time, and normally isn't required at deployment time
30
+ (unless your application uses it to generate files etc for its users).
31
+
32
+ On your development machine:
33
+
34
+ <pre syntax="ruby">sudo gem install rubigen</pre>
35
+
36
+ h2. Usage
37
+
38
+ RubiGen will be normally integrated into another RubyGem, such as <code>newgem</code> or <code>merb</code> or <code>camping</code>,
39
+ rather than be used on its own.
40
+
41
+ These frameworks might use RubiGen for two reasons:
42
+
43
+ # To generate an initial stub for developers, e.g. <code>rails</code> generated a stub to write a Rails application. <code>newgem</code> generates a stub to write a RubyGem. <br/>
44
+ BTW - RubiGen has a builtin application <code>ruby_app</code> which generates a bare-bones Ruby application stub (lib, test, and script folders, plus a Rakefile, and a script/generate script)
45
+ # To generate components within their development areas, e.g. Rails had its <code>script/generate</code> script within each Rails application, which hooked back into the rails_generator to lookup and execute generators.
46
+
47
+ So, there are two steps to integrating RubiGen into your framework:
48
+
49
+ # Use it to generate an initial stub for the developers of your framework. This would create the folders
50
+ (<code>lib/app</code>, <code>test</code>, <code>script</code>, <code>doc</code>, <code>log</code>, etc) and starting files (<code>Rakefile</code>,
51
+ <code>README.txt</code>, <code>test/test_helper.rb</code> etc). Importantly, it would generate a <code>script/generate</code> file.
52
+ The <code>script/generate</code> file (example below) will allow developers of your framework to
53
+ generate components/extensions within the framework. <br />
54
+ RubiGen allows you to restrict which generators are available. For example, within
55
+ RubyGem development environment (as generated by <code>newgem</code>), the <code>script/generator</code>
56
+ only shows <code>rubygem</code>-related generators. Merb could restrict <code>script/generator</code>
57
+ to only show Merb related generators (or perhaps Merb and/or Rails generators)
58
+ # Your framework RubyGem (e.g. <code>newgem</code> or <code>merb</code> RubyGems) needs to add <code>rubigen</code> as a
59
+ dependency, so that users of your RubyGem can access the generator framework.
60
+
61
+ h1. Creating generators
62
+
63
+ There are two types of generators:
64
+
65
+ # 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 <code>rails</code> stub for new Rails applications)
68
+ for your framework users.
69
+ # 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
+ h2. Creating an Application Generator for your Framework
75
+
76
+ h3. Easy way
77
+
78
+ "newgem":http://newgem.rubyforge.org/ (v0.13.0+) can generate an Application Generator
79
+ for a RubyGem.
80
+
81
+ # Create new RubyGem: <code>newgem foobar</code>
82
+ # Create generator: <code>script/generator application_generator foobar</code>
83
+ # Update tests + generator
84
+ # Install
85
+ # Run with: foobar
86
+
87
+ For more documentation, run <code>script/generator application_generator</code>
88
+
89
+ h3. DIY
90
+
91
+ Without RubiGen, to give your users a head start and create a stub for them, you will
92
+ copiously use <code>mkdir_p</code> and <code>File.open</code>. Your script will either be primitive (only
93
+ create the bare folders and very few files) or it will be very long and unreadable
94
+ (ok, perhaps I'm just talking about the <code>newgem</code> script, which I am dubiously responsible
95
+ for... :P).
96
+
97
+ With RubiGen, you can create stubs using powerful, yet simple, syntax. Templates are
98
+ extracted into a <code>templates</code> folder, and activating the generator from a script requires
99
+ only a few lines of code.
100
+
101
+ These are the <code>newgem</code> files related to its Application Generator.
102
+
103
+ bin/
104
+ bin/newgem # Appliction Generator script; Usage: newgem gemname [options]
105
+ app_generators/
106
+ app_generators/newgem/
107
+ app_generators/newgem/newgem_generator.rb
108
+ app_generators/newgem/USAGE
109
+ app_generators/newgem/templates/
110
+ app_generators/newgem/templates/app.rb
111
+ app_generators/newgem/templates/History.txt
112
+ app_generators/newgem/templates/... lots and lots of templates
113
+
114
+ The <code>bin/newgem</code> script is very simple, and looks like:
115
+
116
+ <pre syntax="ruby">
117
+ require 'rubygems'
118
+ require 'rubigen'
119
+
120
+ if %w(-v --version).include? ARGV.first
121
+ require 'newgem/version'
122
+ puts "#{File.basename($0)} #{Newgem::VERSION::STRING}"
123
+ exit(0)
124
+ end
125
+
126
+ require 'rubigen/scripts/generate'
127
+ RubiGen::Base.use_application_sources!
128
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'newgem')
129
+ </pre>
130
+
131
+ You can copy and paste this for your own generator script, and place it in your RubyGem's <code>bin</code> folder.
132
+ Change <code>newgem</code> to your RubyGem's name in the script above (and in all the folders listed above too)
133
+
134
+ NOTE: If you leave <code>newgem</code> there, then it will execute the <code>newgem_generator.rb</code> generator;
135
+ as the generators are loaded from all RubyGem's having <code>/app_generators</code> folders.
136
+
137
+ So, for your RubyGem, you need to keep the <code>/app_generators</code> folder (as you are creating an
138
+ Application Generator, not a Component Generator), but change <code>newgem</code> to <code>your gem name</code> in
139
+ all the subfolders and files. ESPECIALLY <code>newgem_generator.rb</code> -> <code>yourgem_generator.rb</code>,
140
+ as this is how the generator is discovered (via <code>RubiGen::Base.use_application_sources!</code>).
141
+
142
+ All the generator work is performed within <code>yourgem_generator.rb</code>. A stub for it will be:
143
+
144
+ <pre syntax="ruby">
145
+ require 'rbconfig'
146
+
147
+ class YourgemGenerator < RubiGen::Base
148
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
149
+ Config::CONFIG['ruby_install_name'])
150
+
151
+ default_options :shebang => DEFAULT_SHEBANG,
152
+ :an_option => 'some_default'
153
+
154
+ attr_reader :app_name, :module_name
155
+
156
+ def initialize(runtime_args, runtime_options = {})
157
+ super
158
+ usage if args.empty?
159
+ @destination_root = args.shift
160
+ @app_name = File.basename(File.expand_path(@destination_root))
161
+ @module_name = app_name.camelize
162
+ extract_options
163
+ end
164
+
165
+ def manifest
166
+ # Use /usr/bin/env if no special shebang was specified
167
+ script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
168
+ windows = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
169
+
170
+ record do |m|
171
+ # Root directory and all subdirectories.
172
+ m.directory ''
173
+ BASEDIRS.each { |path| m.directory path }
174
+
175
+ # Root
176
+ m.template_copy_each %w( Rakefile )
177
+ m.file_copy_each %w( README.txt )
178
+
179
+ # Test helper
180
+ m.template "test_helper.rb", "test/test_helper.rb"
181
+
182
+ # Scripts
183
+ %w( generate ).each do |file|
184
+ m.template "script/#{file}", "script/#{file}", script_options
185
+ m.template "script/win_script.cmd", "script/#{file}.cmd",
186
+ :assigns => { :filename => file } if windows
187
+ end
188
+
189
+ end
190
+ end
191
+
192
+ protected
193
+ def banner
194
+ <<-EOS
195
+ Create a stub for #{File.basename $0} to get started.
196
+
197
+ Usage: #{File.basename $0} /path/to/your/app [options]"
198
+ EOS
199
+ end
200
+
201
+ def add_options!(opts)
202
+ opts.separator ''
203
+ opts.separator "#{File.basename $0} options:"
204
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
205
+ end
206
+
207
+ # Installation skeleton. Intermediate directories are automatically
208
+ # created so don't sweat their absence here.
209
+ BASEDIRS = %w(
210
+ doc
211
+ lib
212
+ log
213
+ script
214
+ test
215
+ tmp
216
+ )
217
+ end
218
+ </pre>
219
+
220
+ Easy peasy.
221
+
222
+ h2. Creating a Component Generator for your Framework
223
+
224
+ You can include Component Generators in RubyGems, and they will be automatially picked up
225
+ by your framework's <code>script/generate</code> script.
226
+
227
+ h3. Easy way
228
+
229
+ Use "newgem":http://newgem.rubyforge.org/, (v0.13.0+), and run:
230
+
231
+ <pre>
232
+ script/generate component_generator
233
+ </pre>
234
+
235
+ and follow the instructions.
236
+
237
+ h2. Forum
238
+
239
+ "http://groups.google.com/group/rubigen":http://groups.google.com/group/rubigen
240
+
241
+ h2. How to submit patches
242
+
243
+ Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
244
+ The trunk repository is <code>svn://rubyforge.org/var/svn/rubigen/trunk</code> for anonymous access.
245
+
246
+ h2. License
247
+
248
+ This code is free to use under the terms of the MIT license.
249
+
250
+ h2. Contact
251
+
252
+ Comments are welcome. Send an email to "Dr Nic Williams":mailto:drnicwilliams@gmail.com via the "forum":http://groups.google.com/group/rubigen