intersect_rails_composer 0.0.2

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 (43) hide show
  1. checksums.yaml +7 -0
  2. data/README.textile +433 -0
  3. data/bin/intersect_rails_composer +7 -0
  4. data/lib/rails_wizard/command.rb +204 -0
  5. data/lib/rails_wizard/config.rb +88 -0
  6. data/lib/rails_wizard/diagnostics.rb +68 -0
  7. data/lib/rails_wizard/recipe.rb +114 -0
  8. data/lib/rails_wizard/recipes.rb +56 -0
  9. data/lib/rails_wizard/template.rb +111 -0
  10. data/lib/rails_wizard.rb +7 -0
  11. data/recipes/apps4.rb +150 -0
  12. data/recipes/controllers.rb +75 -0
  13. data/recipes/core.rb +14 -0
  14. data/recipes/email.rb +110 -0
  15. data/recipes/example.rb +70 -0
  16. data/recipes/extras.rb +187 -0
  17. data/recipes/frontend.rb +45 -0
  18. data/recipes/gems.rb +277 -0
  19. data/recipes/git.rb +20 -0
  20. data/recipes/init.rb +136 -0
  21. data/recipes/models.rb +109 -0
  22. data/recipes/prelaunch.rb +119 -0
  23. data/recipes/railsapps.rb +277 -0
  24. data/recipes/readme.rb +85 -0
  25. data/recipes/routes.rb +45 -0
  26. data/recipes/saas.rb +218 -0
  27. data/recipes/setup.rb +134 -0
  28. data/recipes/testing.rb +276 -0
  29. data/recipes/views.rb +57 -0
  30. data/spec/rails_wizard/config_spec.rb +108 -0
  31. data/spec/rails_wizard/recipe_spec.rb +115 -0
  32. data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
  33. data/spec/rails_wizard/recipes_spec.rb +41 -0
  34. data/spec/rails_wizard/template_spec.rb +92 -0
  35. data/spec/spec_helper.rb +11 -0
  36. data/spec/support/rails_directory.rb +17 -0
  37. data/spec/support/template_runner.rb +28 -0
  38. data/spec/test_recipes/test_recipe_in_file.rb +9 -0
  39. data/templates/helpers.erb +135 -0
  40. data/templates/layout.erb +232 -0
  41. data/templates/recipe.erb +13 -0
  42. data/version.rb +3 -0
  43. metadata +210 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 716a15542573838254a6e1b646c1cd12ae36b5e6
4
+ data.tar.gz: 92e99cff606ac60e9254ad5e16e198bf05dfcb56
5
+ SHA512:
6
+ metadata.gz: d3c28a00b525ecc89ad651fd1c041b1131a7a5a7a069a0640d70b34e04b77e56d45a80dbcc80fda57c3b1ead9abce6f523630077c19855b18b48b44b0a66d055
7
+ data.tar.gz: 217467ebdd6e92c252af593be2b971707de37e42d88350bde208fbb10dde117548b1d7b4bd3e776ed5641f911f69404eef34a7461bf248fc964b05a749e56e34
data/README.textile ADDED
@@ -0,0 +1,433 @@
1
+ h1. !http://railsapps.github.io/images/rails-36x36.jpg(Rails Apps Composer Gem)! Rails Apps Composer
2
+ !https://badge.fury.io/rb/rails_apps_composer.png!:http://badge.fury.io/rb/rails_apps_composer !https://travis-ci.org/RailsApps/rails_apps_composer.png!:https://travis-ci.org/RailsApps/rails_apps_composer
3
+
4
+ The Rails Apps Composer gem installs a command line tool to assemble a Rails application from a collection of "recipes."
5
+
6
+ What you can do with the rails_apps_composer gem:
7
+
8
+ * create a starter app from the command line
9
+ * make a reusable application template
10
+
11
+ You can use local recipes as well as recipes supplied with the gem.
12
+
13
+ The "Rails Composer":http://railsapps.github.io/rails-composer/ tool is built with the rails_apps_composer gem. The Rails Composer tool creates the "example applications":http://railsapps.github.io/ for the "RailsApps":http://railsapps.github.io/ project.
14
+
15
+ The "Guide to the Rails Apps Composer Gem":http://railsapps.github.io/tutorial-rails-apps-composer.html provides complete documentation:
16
+
17
+ * "Overview":http://railsapps.github.io/tutorial-rails-apps-composer.html#Overview
18
+ * "Recipes":http://railsapps.github.io/tutorial-rails-apps-composer.html#Recipes
19
+ * "Usage":http://railsapps.github.io/tutorial-rails-apps-composer.html#Usage
20
+ * "Diagnostics":http://railsapps.github.io/tutorial-rails-apps-composer.html#Diagnostics
21
+ * "Hacking the Gem":http://railsapps.github.io/tutorial-rails-apps-composer.html#Hacking
22
+ * "Anatomy of a Recipe":http://railsapps.github.io/tutorial-rails-apps-composer.html#Anatomy
23
+ * "Architecture":http://railsapps.github.io/tutorial-rails-apps-composer.html#Architecture
24
+ * "Defaults File":http://railsapps.github.io/tutorial-rails-apps-composer.html#Defaults
25
+
26
+ Any issues? Please create a "GitHub issue":http://github.com/RailsApps/rails_apps_composer/issues.
27
+
28
+ h3. From the RailsApps Project
29
+
30
+ The "RailsApps project":http://railsapps.github.io/ provides example applications that developers use as starter apps. Hundreds of developers use the apps, report problems as they arise, and propose solutions. Rails changes frequently; each application is known to work and serves as your personal "reference implementation" so you can stay up to date. Each is accompanied by a tutorial so there is no mystery code. Maintenance and development of the RailsApps applications is supported by subscriptions to the "RailsApps tutorials":https://tutorials.railsapps.org.
31
+
32
+ h2. !http://twitter-badges.s3.amazonaws.com/t_logo-a.png(Follow on Twitter)!:http://www.twitter.com/rails_apps Follow on Twitter
33
+
34
+ Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps. Tweet some praise if you like what you've found.
35
+
36
+ h2. What's New
37
+
38
+ See the "CHANGELOG":https://github.com/RailsApps/rails_apps_composer/blob/master/CHANGELOG.textile for details.
39
+
40
+ If your favorite recipe is missing, please fork the repo, add the recipe and test it, then submit a pull request. I'm happy to add new recipes.
41
+
42
+ h2. Who This Is For
43
+
44
+ This gem is for experienced Rails developers who need a tool to create and maintain a Rails starter app or Rails application template. If you're regularly building Rails applications that use certain popular gems or rely on common functionality such as authentication, you can benefit from the rails_apps_composer gem.
45
+
46
+ If you are new to Rails, try the "Rails Composer":http://railsapps.github.io/rails-composer/ tool instead. It provides an application template that is generated from the rails_apps_composer gem's core recipes. The Rails Composer tool is easier to use. Use the rails_apps_composer gem if you want a custom application template, a custom combination of recipes, or the convenience of setting a defaults file.
47
+
48
+ See the "CONTRIBUTING":https://github.com/RailsApps/rails_apps_composer/blob/master/CONTRIBUTING.textile file for details about how you can contribute fixes or new features.
49
+
50
+ h2. Alternatives
51
+
52
+ The rails_apps_composer gem is derived from Michael Bleigh's "RailsWizard":https://github.com/intridea/rails_wizard gem. Early versions of the rails_apps_composer gem were a close fork of Michael Bleigh's gem; rails_apps_composer 2.0 differs substantially. Other notable alternatives are Dr. Nic Williams's "App Scrolls":http://appscrolls.org/ and Daniel Davey's "app_drone":http://drone.bz/. See a list of "Rails Application Template Projects":http://railsapps.github.io/rails-application-templates.html, particularly a list of "Application template-generating gems" for similar projects.
53
+
54
+ h2. Dependencies
55
+
56
+ Before using the rails_apps_composer gem, you will need:
57
+
58
+ * The Ruby language (version 2.0.0)
59
+ * Rails 3.2 or Rails 4.0
60
+
61
+ The rails_apps_composer program uses the version of Rails that is currently installed when you launch the program. If you want to use the newest Rails version, upgrade before running rails_apps_composer.
62
+
63
+ See the article "Installing Rails":http://railsapps.github.io/installing-rails.html for advice about updating Rails and your development environment. You'll avoid many potential headaches if you review the article step by step before beginning development.
64
+
65
+ h4. Database
66
+
67
+ Unless you use SQLite, which runs by default on Mac OS X, you'll need to have a database server running before you run rails_apps_composer. This is true if you want to use PostgreSQL, MySQL, or MongoDB. I recommend using SQLite if you don't want to set up a database server.
68
+
69
+ h2. Installation and Usage
70
+
71
+ I recommend installing and using RVM, the "Ruby Version Manager":https://rvm.io/, to create a new gemset for rails_apps_composer. Using an RVM gemset will make it easier to identify and isolate incompatibilities among gems. RVM will install Ruby and set up a global gemset with a minimal set of gems.
72
+
73
+ Here's how to generate a new Rails application using rails_apps_composer and RVM:
74
+
75
+ <pre>
76
+ $ mkdir myapp
77
+ $ cd myapp
78
+ $ rvm use ruby-2.0.0@myapp --ruby-version --create
79
+ $ gem install rails
80
+ $ gem install rails_apps_composer
81
+ $ rails_apps_composer new . -r core
82
+ </pre>
83
+
84
+ This approach avoids conflicts with outdated gem versions that may be active in your shell environment.
85
+
86
+ h3. Troubleshooting
87
+
88
+ You may have trouble if you install the rails_apps_composer gem by including it in a Gemfile and running Bundler (reported in "issue 114":https://github.com/RailsApps/rails_apps_composer/issues/114).
89
+
90
+ h2. Usage Options
91
+
92
+ These commands are summarized here for your reference. See the "Guide to the Rails Apps Composer Gem":http://railsapps.github.io/tutorial-rails-apps-composer.html for details.
93
+
94
+ h3. List Recipes
95
+
96
+ You can list recipes with short descriptions:
97
+
98
+ <pre>
99
+ $ rails_apps_composer list
100
+
101
+ controllers # Add controllers needed for starter apps.
102
+ core # Select all core recipes.
103
+ email # Configure email accounts.
104
+ example # Example of a recipe.
105
+ extras # Various extras.
106
+ frontend # Install a front-end framework for HTML5 and CSS.
107
+ gems # Add the gems your application needs.
108
+ git # Initialize git for your application.
109
+ init # Set up and initialize database.
110
+ models # Add models needed for starter apps.
111
+ railsapps # Install RailsApps example applications.
112
+ readme # Build a README file for your application.
113
+ routes # Add routes needed for starter apps.
114
+ setup # Make choices for your application.
115
+ testing # Add testing framework.
116
+ views # Add views needed for starter apps.
117
+ </pre>
118
+
119
+ The above list is current for rails_apps_composer 2.1; later releases will contain more recipes.
120
+
121
+ See the Guide for more "detailed descriptions of recipes":http://railsapps.github.io/tutorial-rails-apps-composer.html#Recipes. You can find all available recipes in the repository "recipes directory":https://github.com/RailsApps/rails_apps_composer/tree/master/recipes. Examining the recipe source code is the very best way to learn what a recipe will do.
122
+
123
+ h3. Recommended Recipes
124
+
125
+ I recommend selecting the _core_ recipe if you are just getting started. The _core_ recipe installs a collection of the most useful recipes.
126
+
127
+ h3. Recipe Order and Interdependency
128
+
129
+ The order in which you input a list or recipes determines the order of execution unless a recipe contains a @requires@ or @run_after@ directive.
130
+
131
+ A recipe may contain a @requires@ directive which specifies other recipes which must be present before a recipe can run. The @requires@ constraint will force the rails_apps_composer program to load any required recipes, even if you don't add them explicitly.
132
+
133
+ Recipes may also contain a @run_after@ directive. The rails_apps_composer program will organize the order of execution so that any recipes in the @run_after@ list will execute earlier. That is, the recipe will run after everything else in the list.
134
+
135
+ In general, it's best to add (or list) recipes in the order they should execute as some recipes may not contain a necessary @requires@ or @run_after@ directive.
136
+
137
+ See the "Anatomy of a Recipe":http://railsapps.github.io/tutorial-rails-apps-composer.html#Anatomy section in the Guide to learn about the format of a recipe.
138
+
139
+ h3. Skipping Test::Unit or Active Record
140
+
141
+ If you plan to use RSpec instead of Test::Unit, or use an ORM such as Mongoid instead of Active Record, you must pass the @-T@ or @-O@ flags to the program so it will skip Test::Unit or Active Record.
142
+
143
+ The rails_apps_composer program will ask if you want to skip Test::Unit or Active Record when you generate an application interactively.
144
+
145
+ Any recipe can set the @-T@ or @-O@ arguments using the @args@ directive.
146
+
147
+ Also, you can set @-T@ or @-O@ arguments in the defaults file.
148
+
149
+ Setting @-T@ or @-O@ arguments has no affect on application templates. An application template runs after the @rails new@ command so it cannot set the @-T@ or @-O@ arguments. When you generate an application template, the program will not ask if you want to skip Test::Unit or Active Record.
150
+
151
+ h3. Using Local Recipes
152
+
153
+ You can use local recipes you've created yourself by using the @-l@ flag and supplying the name of a directory that contains local recipes. The @-l@ flag can be combined with any other command so you can create applications or application templates, interactively or from a defaults file.
154
+
155
+ For example, generate an application interactively using local recipes:
156
+
157
+ <pre>
158
+ $ rails_apps_composer new myapp -l ~/recipes/
159
+ </pre>
160
+
161
+ If you create local recipes, please consider contributing them to the project.
162
+
163
+ If you want to only use your local recipes, and not include the default recipes, use the @-L@ flag.
164
+
165
+ h3. Generate an Application Interactively
166
+
167
+ You'll be prompted for recipes and gems:
168
+
169
+ <pre>
170
+ $ rails_apps_composer new myapp
171
+
172
+ Would you like to skip Test::Unit? (yes for RSpec) (y/n)
173
+ Would you like to skip Active Record? (yes for MongoDB) (y/n)
174
+
175
+ Available Recipes:
176
+ collections: core
177
+ configuration: email, gems, git, railsapps, readme, setup
178
+ example: example
179
+ frontend: frontend
180
+ initialize: init
181
+ mvc: controllers, models, routes, views
182
+ other: extras
183
+ testing: testing
184
+
185
+ Which recipe would you like to add? (blank to finish)
186
+ What gem would you like to add? (blank to finish)
187
+
188
+ Generating basic application, using:
189
+ "rails new myapp -m <temp_file>"
190
+ </pre>
191
+
192
+ If you want to skip the prompts asking about Test::Unit and Active Record, you can set these arguments in a defaults file.
193
+
194
+ You will be able to choose recipes that are contained in the rails_apps_composer gem plus any local recipes you've added with the @-l@ argument.
195
+
196
+ Choose the _core_ recipe if you are not sure which recipes to select.
197
+
198
+ You can specify any gem. Any string you enter will be added as a gem in the starter app Gemfile.
199
+
200
+ If you want to skip the prompts asking which recipe or gem you'd like to add, use the "quiet flag" parameter on the command line by adding @-q@.
201
+
202
+ h3. Generate an Application from a List of Recipes
203
+
204
+ Provide a list of recipes using the @-r@ flag. In this example, the _core_ recipe selects all available core recipes:
205
+
206
+ <pre>
207
+ $ rails_apps_composer new myapp -r core
208
+
209
+ Would you like to skip Test::Unit? (yes for RSpec) (y/n)
210
+ Would you like to skip Active Record? (yes for MongoDB) (y/n)
211
+ What gem would you like to add? (blank to finish)
212
+
213
+ Generating basic application, using:
214
+ "rails new myapp -m <temp_file>"
215
+ </pre>
216
+
217
+ The program will prompt you for your preferences before generating an application (unless you set the "quiet flag" @-q@).
218
+
219
+ h3. Generate an Application from Defaults
220
+
221
+ Use a defaults file for recipes, preferences, and extra gems so you don't have to provide them interactively. Then generate an application using the @-d@ flag:
222
+
223
+ <pre>
224
+ $ rails_apps_composer new myapp -d my_defaults.yaml
225
+ </pre>
226
+
227
+ Use the @my_defaults.yaml@ file to specify a list of recipes, preferences, and extra gems. You can use any name (and file extension) for the file. See the "Defaults File":http://railsapps.github.io/tutorial-rails-apps-composer.html#Defaults section in the Guide concerning the format of the defaults file.
228
+
229
+ Use the "quiet flag" @-q@ if you want to skip all prompts:
230
+
231
+ <pre>
232
+ $ rails_apps_composer new myapp -q -d my_defaults.yaml
233
+ </pre>
234
+
235
+ h3. Generate an Application Template Interactively
236
+
237
+ You may want an application template to share with others. For an example, see the "Rails Composer":http://railsapps.github.io/rails-composer/ project which is an application template generated from the rails_apps_composer core recipes.
238
+
239
+ Specify a filename for the template:
240
+
241
+ <pre>
242
+ $ rails_apps_composer template ~/Desktop/template.rb
243
+
244
+ Available Recipes:
245
+ collections: core
246
+ configuration: email, gems, git, railsapps, readme, setup
247
+ example: example
248
+ frontend: frontend
249
+ initialize: init
250
+ mvc: controllers, models, routes, views
251
+ other: extras
252
+ testing: testing
253
+
254
+ Which recipe would you like to add? (blank to finish)
255
+ What gem would you like to add? (blank to finish)
256
+ Generating and saving application template...
257
+ Done.
258
+ </pre>
259
+
260
+ The command with the @template@ argument followed by a filename generates an application template. You can add additional recipes or gems when prompted.
261
+
262
+ h3. Generate an Application Template from a List of Recipes
263
+
264
+ Specify a filename for the template and provide a list of recipes:
265
+
266
+ <pre>
267
+ $ rails_apps_composer template ~/Desktop/template.rb -r core
268
+
269
+ What gem would you like to add? (blank to finish)
270
+ Generating and saving application template...
271
+ Done.
272
+ </pre>
273
+
274
+ The command with the @template@ argument followed by a filename and a list of recipes generates an application template. Use the "quiet flag" @-q@ if you want to skip all prompts.
275
+
276
+ h3. Generate an Application Template from Defaults
277
+
278
+ Generate an application template using a defaults file and the @-d@ flag:
279
+
280
+ <pre>
281
+ $ rails_apps_composer template ~/Desktop/template.rb -d my_defaults.yaml
282
+ </pre>
283
+
284
+ Use the @my_defaults.yaml@ file to specify a list of recipes, preferences, and extra gems. You can use any name (and file extension) for the file. See the "Defaults File":http://railsapps.github.io/tutorial-rails-apps-composer.html#Defaults section in the Guide concerning the format of the defaults file. Use the "quiet flag" @-q@ if you want to skip all prompts.
285
+
286
+ h3. Generate an Application Template With Your Own Layout
287
+
288
+ If you want to generate an application template, but use your own layout to do so, you can use the @-t@ flag to set the directory where your templates are. Look at the @templates/@ directory in this gem to see how your templates should look.
289
+
290
+ <pre>
291
+ $ rails_apps_composer template ~/Desktop/template.rb -t ~/Desktop/my_templates
292
+ </pre>
293
+
294
+ h3. Generate an Application from a Template
295
+
296
+ After you've created a template file, you can generate an application from a template at any time using the @rails new@ command with the @-m@ option:
297
+
298
+ <pre>
299
+ $ rails new myapp -m ~/Desktop/template.rb
300
+ </pre>
301
+
302
+ The application template will prompt you for any configuration preferences requested by the recipes.
303
+
304
+ The @rails new@ command allows you to specify the @-T -O@ flags to skip Test::Unit files and Active Record files when you use an application template.
305
+
306
+ <pre>
307
+ $ rails new myapp -m ~/Desktop/template.rb -T -O
308
+ </pre>
309
+
310
+ The @rails new@ command with the @-m@ option also allows you to specify an application template that can be downloaded via HTTP. This makes it possible to host a template on GitHub (for example) and allow anyone to generate an application from the hosted template. For example:
311
+
312
+ <pre>
313
+ $ rails new myapp -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
314
+ </pre>
315
+
316
+ h2. Diagnostics
317
+
318
+ The rails_apps_composer program runs diagnostics to reveal whether you've picked recipes and preferences that are known to work together.
319
+
320
+ Hundreds of developers are using this gem to build starter apps. As you can see from the commit log, the gem is actively maintained and the collection of recipes is growing. There is a drawback to all this activity, however. No developer who uses the rails_apps_composer gem uses all the recipes. And it would be very difficult to test a recipe in every possible combination. Consequently, combining some recipes or preferences may not work.
321
+
322
+ The rails_apps_composer gem contains an internal database of combinations of recipes and preferences that are known to work together. If you've picked recipes and preferences that are known to work together, you'll get a confirmation:
323
+
324
+ <pre>
325
+ WOOT! The recipes you've selected are known to work together.
326
+ If they don't, open an issue for rails_apps_composer on GitHub.
327
+ WOOT! The preferences you've selected are known to work together.
328
+ If they don't, open an issue for rails_apps_composer on GitHub.
329
+ </pre>
330
+
331
+ You'll get a warning if you've picked a combination we don't know about:
332
+
333
+ <pre>
334
+ WARNING! The recipes you've selected might not work together.
335
+ Help us out by reporting whether this combination works or fails.
336
+ WARNING! The preferences you've selected might not work together.
337
+ Help us out by reporting whether this combination works or fails.
338
+ </pre>
339
+
340
+ Go to the GitHub repository to create an "issue":http://github.com/RailsApps/rails_apps_composer/issues and let us know if you've found a combination of recipes or preferences that work together. If you've found a combination that works together, we'll update the gem's internal database for the next public release.
341
+
342
+ It's a good idea to include the "readme" recipe when you run rails_apps_composer. If you do, the application's *README* file will contain a diagnostics report. Here's an example of the diagnostics report:
343
+
344
+ <pre>
345
+ Recipes:
346
+ ["gems", "readme", "setup"]
347
+
348
+ Preferences:
349
+ {:database=>"sqlite", :templates=>"erb", :email=>"none"}
350
+ </pre>
351
+
352
+ Please include the diagnostics report when you create an issue on GitHub.
353
+
354
+ h2. Troubleshooting
355
+
356
+ Problems? You should review the article "Installing Rails":http://railsapps.github.io/installing-rails.html to make sure you've updated all the components that are required to run Rails successfully.
357
+
358
+ h4. Problems with "Could not be loaded... You have already activated..."
359
+
360
+ If you get an error like this:
361
+
362
+ <pre>
363
+ Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
364
+ composer Running 'after bundler' callbacks.
365
+ The template [...] could not be loaded.
366
+ Error: You have already activated ..., but your Gemfile requires ....
367
+ Using bundle exec may solve this.
368
+ </pre>
369
+
370
+ It's due to conflicting gem versions. See the article "Rails Error: “You have already activated (…)”":http://railsapps.github.io/rails-error-you-have-already-activated.html.
371
+
372
+ h4. Problems with "Certificate Verify Failed"
373
+
374
+ Are you getting an error "OpenSSL certificate verify failed" when you try to generate a new Rails app from an application template? See suggestions to resolve the error "Certificate Verify Failed":http://railsapps.github.io/openssl-certificate-verify-failed.html.
375
+
376
+ h4. Problems with "Segmentation Fault"
377
+
378
+ If you get a "segfault" when you try @rails new@, try removing and reinstalling RVM.
379
+
380
+ h2. Application Template Default
381
+
382
+ The @rails new@ command creates a new Rails application. If you want to use an application template for every Rails application you build, you can set options for the @rails new@ command in a *.railsrc* file in your home directory. Here's how to set up a *.railsrc* file to use the Rails Composer template when you create a new Rails application:
383
+
384
+ <pre>
385
+ # ~/.railsrc
386
+ -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
387
+ </pre>
388
+
389
+ h2. Hacking the Gem
390
+
391
+ See the "Guide to the Rails Apps Composer Gem":http://railsapps.github.io/tutorial-rails-apps-composer.html to learn how to customize the gem either for your own use or to share with others.
392
+
393
+ See the "CONTRIBUTING":https://github.com/RailsApps/rails_apps_composer/blob/master/CONTRIBUTING.textile file for details about how you can contribute fixes or new features.
394
+
395
+ h2. Issues
396
+
397
+ Any issues? Please create an "issue":http://github.com/RailsApps/rails_apps_composer/issues on GitHub. Reporting issues (and patching!) helps everyone.
398
+
399
+ If you include the _readme_ recipe when you generate an application, the generated *README* file will contain a diagnostics report (unless the program aborts before the _readme_ recipe runs). Please include the diagnostics report when you create an issue on GitHub.
400
+
401
+ h2. Credits
402
+
403
+ Daniel Kehoe maintains this gem as part of the "RailsApps project":http://railsapps.github.io/.
404
+
405
+ This gem is derived from "Michael Bleigh's RailsWizard gem":https://github.com/intridea/rails_wizard. The original idea and the innovative implementation is the work of Michael Bleigh.
406
+
407
+ Please see the "CHANGELOG":https://github.com/RailsApps/rails_apps_composer/blob/master/CHANGELOG.textile for a list of contributors.
408
+
409
+ Is the gem useful to you? Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps. I'd love to know you were helped out by the gem.
410
+
411
+ h2. MIT License
412
+
413
+ "MIT License":http://www.opensource.org/licenses/mit-license
414
+
415
+ Copyright © 2012-2013 Daniel Kehoe
416
+
417
+ h2. Useful Links
418
+
419
+ |_. Getting Started |_. Articles |_. Tutorials |
420
+ | "Learn Rails":http://learn-rails.com/ | "Twitter Bootstrap and Rails":http://railsapps.github.io/twitter-bootstrap-rails.html | "Rails and Bootstrap":http://railsapps.github.io/rails-bootstrap/ |
421
+ | "Ruby and Rails":http://railsapps.github.io/ruby-and-rails.html | "Analytics for Rails":http://railsapps.github.io/rails-google-analytics.html | |
422
+ | "What is Ruby on Rails?":http://railsapps.github.io/what-is-ruby-rails.html | "Heroku and Rails":http://railsapps.github.io/rails-heroku-tutorial.html | "Devise with CanCan and Twitter Bootstrap":https://tutorials.railsapps.org/rails3-bootstrap-devise-cancan |
423
+ | "Rails Tutorial":https://tutorials.railsapps.org/rails-tutorial | "JavaScript and Rails":http://railsapps.github.io/rails-javascript-include-external.html | "Rails Membership Site with Stripe":https://tutorials.railsapps.org/rails-stripe-membership-saas |
424
+ | "Installing Rails":http://railsapps.github.io/installing-rails.html | "Rails Environment Variables":http://railsapps.github.io/rails-environment-variables.html | "Rails Subscription Site with Recurly":https://tutorials.railsapps.org/rails-recurly-subscription-saas |
425
+ | "Updating Rails":http://railsapps.github.io/updating-rails.html | "Git and Rails":http://railsapps.github.io/rails-git.html | "Startup Prelaunch Signup Application":http://railsapps.github.io/tutorial-rails-prelaunch-signup.html |
426
+ | "Rails Composer":http://railsapps.github.io/rails-composer/ | "Email and Rails":http://railsapps.github.io/rails-send-email.html | "Devise with RSpec and Cucumber":http://railsapps.github.io/tutorial-rails-devise-rspec-cucumber.html |
427
+ | "Rails Examples":http://railsapps.github.io/ | "Haml and Rails":http://railsapps.github.io/rails-haml.html | "Devise with Mongoid":http://railsapps.github.io/tutorial-rails-mongoid-devise.html |
428
+ | "Rails Starter Apps":http://railsapps.github.io/rails-examples-tutorials.html | "Rails Application Layout":http://railsapps.github.io/rails-default-application-layout.html | "OmniAuth with Mongoid":http://railsapps.github.io/tutorial-rails-mongoid-omniauth.html |
429
+ | | "HTML5 Boilerplate for Rails":http://railsapps.github.io/rails-html5-boilerplate.html | "Subdomains with Devise":http://railsapps.github.io/tutorial-rails-subdomains.html |
430
+ | | "Example Gemfiles for Rails":http://railsapps.github.io/rails-3-2-example-gemfile.html | |
431
+ | | "Rails Application Templates":http://railsapps.github.io/rails-application-templates.html | |
432
+
433
+ !https://cruel-carlota.pagodabox.com/1f4f51c551cd90489a558e5fe4d91fff(githalytics.com alpha)!
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push File.dirname(__FILE__) + '/../lib'
3
+
4
+ require 'rubygems'
5
+ require 'rails_wizard/command'
6
+
7
+ RailsWizard::Command.start
@@ -0,0 +1,204 @@
1
+ require 'rails_wizard'
2
+ require 'thor'
3
+
4
+ module RailsWizard
5
+ class Command < Thor
6
+ include Thor::Actions
7
+ desc "new APP_NAME", "create a new Rails app"
8
+ method_option :recipes, :type => :array, :aliases => "-r"
9
+ method_option :defaults, :type => :string, :aliases => "-d"
10
+ method_option :recipe_dirs, :type => :array, :aliases => "-l"
11
+ method_option :no_default_recipes, :type => :boolean, :aliases => "-L"
12
+ method_option :template_root, :type => :string, :aliases => '-t'
13
+ method_option :quiet, :type => :boolean, :aliases => "-q", :default => false
14
+ method_option :verbose, :type => :boolean, :aliases => "-V", :default => false
15
+ def new(name)
16
+ add_recipes
17
+ recipes, defaults = load_defaults
18
+ (print "\ndefaults: "; p defaults) if options[:verbose]
19
+ args = ask_for_args(defaults)
20
+ (print "\nargs: "; p args) if options[:verbose]
21
+ recipes = ask_for_recipes(recipes)
22
+ (print "\nrecipes: "; p recipes) if options[:verbose]
23
+ gems = ask_for_gems(defaults)
24
+ (print "\ngems: "; p gems) if options[:verbose]
25
+ run_template(name, recipes, gems, args, defaults, nil)
26
+ end
27
+
28
+ desc "template TEMPLATE_FILE", "create a new Rails template"
29
+ method_option :recipes, :type => :array, :aliases => "-r"
30
+ method_option :defaults, :type => :string, :aliases => "-d"
31
+ method_option :recipe_dirs, :type => :array, :aliases => "-l"
32
+ method_option :no_default_recipes, :type => :boolean, :aliases => "-L"
33
+ method_option :template_root, :type => :string, :aliases => '-t'
34
+ method_option :quiet, :type => :boolean, :aliases => "-q", :default => false
35
+ method_option :verbose, :type => :boolean, :aliases => "-V", :default => false
36
+ def template(template_name)
37
+ add_recipes
38
+ recipes, defaults = load_defaults
39
+ recipes = ask_for_recipes(recipes)
40
+ gems = ask_for_gems(defaults)
41
+ run_template(nil, recipes, gems, nil, defaults, template_name)
42
+ end
43
+
44
+ desc "list [CATEGORY]", "list available recipes (optionally by category)"
45
+ def list(category = nil)
46
+ recipes = if category
47
+ RailsWizard::Recipes.for(category).map{|e| RailsWizard::Recipe.from_mongo e}
48
+ else
49
+ RailsWizard::Recipes.list_classes
50
+ end
51
+ address = 'http://railsapps.github.io/tutorial-rails-apps-composer.html#Recipes'
52
+ say("To learn more about recipes, see:\n#{address}", [:bold, :cyan])
53
+ # https://github.com/wycats/thor/blob/master/lib/thor/shell/basic.rb
54
+ recipes.each{|e| say("#{e.key.ljust 15}# #{e.description}")}
55
+ end
56
+
57
+ no_tasks do
58
+
59
+ def add_recipes
60
+ Recipes.clear if options[:no_default_recipes]
61
+ if dirs = options[:recipe_dirs]
62
+ dirs.each {|d| Recipes.add_from_directory d}
63
+ end
64
+ end
65
+
66
+ def load_defaults
67
+ # Load defaults from a file; if a file specifies recipes, they'll be run *before*
68
+ # any on the command line (or prompted for)..
69
+ return [[], {}] unless options[:defaults]
70
+ defaults = File.open(options[:defaults]) {|f| YAML.load(f) }
71
+ recipes = defaults.delete('recipes') { [] }
72
+ [recipes, defaults]
73
+ end
74
+
75
+ def print_recipes(recipes)
76
+ say("\nAvailable Recipes:", [:bold, :cyan])
77
+ RailsWizard::Recipes.categories.each do |category|
78
+ say("#{category} ", [:bold, :cyan])
79
+ a = RailsWizard::Recipes.for(category)
80
+ a.each_with_index do |e,i|
81
+ s = (a.length - 1 == i) ? "#{e}" : "#{e}, "
82
+ if recipes.include?(e)
83
+ say(s, [:bold, :green])
84
+ else
85
+ say(s)
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ def ask_for_recipes(recipes)
92
+ return recipes + options[:recipes] if options[:recipes]
93
+ return recipes if options[:quiet]
94
+ loop do
95
+ recipe = prompt_for_recipes(recipes)
96
+ break if '' == recipe
97
+ case
98
+ when recipes.include?(recipe)
99
+ recipes -= [recipe]
100
+ when RailsWizard::Recipes.list.include?(recipe)
101
+ recipes << recipe
102
+ else
103
+ say("\n> Invalid recipe, please try again.", :red)
104
+ end
105
+ end
106
+ recipes
107
+ end
108
+
109
+ def prompt_for_recipes(recipes)
110
+ print_recipes(recipes)
111
+ say("\nWhich recipe would you like to add? ", :bold)
112
+ ask('(blank to finish)', :yellow)
113
+ end
114
+
115
+ def ask_for_gems(defaults)
116
+ gems = defaults["gems"] || []
117
+ return gems if options[:quiet]
118
+ loop do
119
+ getgem = prompt_for_gems
120
+ break if '' == getgem
121
+ gems << getgem.downcase
122
+ end
123
+ gems
124
+ end
125
+
126
+ def prompt_for_gems
127
+ say('What gem would you like to add? ', :bold)
128
+ ask('(blank to finish)', :yellow)
129
+ end
130
+
131
+ def ask_for_arg(question, default = nil)
132
+ return default unless default.nil?
133
+ say("#{question} ", :bold)
134
+ result = nil
135
+ loop do
136
+ answer = ask('(y/n)', :yellow)
137
+ case answer.downcase
138
+ when "yes", "y"
139
+ result = true
140
+ break
141
+ when "no", "n"
142
+ result = false
143
+ break
144
+ end
145
+ end
146
+ result
147
+ end
148
+
149
+ def ask_for_args(defaults)
150
+ args = []
151
+ default_args = defaults["args"] || {}
152
+ s = 'Would you like to skip'
153
+
154
+ question = "#{s} Test::Unit? (yes for RSpec)"
155
+ args << "-T" if ask_for_arg(question, default_args[:skip_test_unit])
156
+
157
+ question = "#{s} Active Record? (yes for MongoDB)"
158
+ args << "-O" if ask_for_arg(question, default_args[:skip_active_record])
159
+
160
+ args
161
+ end
162
+
163
+ def make_red(s)
164
+ # http://en.wikipedia.org/wiki/ANSI_escape_code
165
+ # http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#Backslash_Notation
166
+ "\e[31m#{s}\e[0m"
167
+ end
168
+
169
+ #pass in name if you want to create a rails app
170
+ #pass in file_name if you want to create a template
171
+ def run_template(name, recipes, gems, args, defaults, file_name=nil)
172
+ if opt = options[:template_root]
173
+ RailsWizard::Template.template_root = opt
174
+ end
175
+
176
+ file = if file_name
177
+ File.new(file_name,'w')
178
+ else
179
+ Tempfile.new('template')
180
+ end
181
+ begin
182
+ template = RailsWizard::Template.new(recipes, gems, args, defaults)
183
+ file.write template.compile
184
+ file.close
185
+ if name
186
+ args_list = (args | template.args).join(' ')
187
+ say('Generating basic application, using: ')
188
+ say("\"rails new #{name} -m <temp_file> #{args_list}\"")
189
+ system "rails new #{name} -m #{file.path} #{args_list}"
190
+ else
191
+ say('Generating and saving application template... ')
192
+ say('Done. ')
193
+ say('Generate a new application with the command: ')
194
+ say("\"rails new <APP_NAME> -m #{file.path} #{template.args.join ' '}\"")
195
+ end
196
+ rescue RailsWizard::UnknownRecipeError
197
+ raise Thor::Error.new(make_red("> #{$!.message}."))
198
+ ensure
199
+ file.unlink unless file_name
200
+ end
201
+ end
202
+ end
203
+ end
204
+ end