rails_apps_composer 1.4.14 → 1.4.15

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -2,19 +2,28 @@ h1. Rails Apps Composer Gem
2
2
 
3
3
  A gem with recipes to create Rails application templates you can use to generate Rails starter apps. Creates ready-to-run Rails web applications. Makes it easy to create and maintain a starter app.
4
4
 
5
- I use the Rails Apps Composer gem to create the "Rails Example Apps":http://railsapps.github.com/ for the "RailsApps project":https://github.com/RailsApps.
5
+ We use the rails_apps_composer gem to create the "Rails Example Apps":http://railsapps.github.com/ for the "Rails Apps project":https://github.com/RailsApps.
6
+
7
+ Any issues? Please create a "GitHub issue":http://github.com/RailsApps/rails_apps_composer/issues.
6
8
 
7
9
  h4. Based on Michael Bleigh's RailsWizard Gem
8
10
 
9
- The Rails Apps Composer gem is a fork of "Michael Bleigh's RailsWizard gem":https://github.com/intridea/rails_wizard (see credits below). The purpose of the fork is to provide recipes for ready-to-run Rails starter apps. Several recipes provided by the Rails Apps Composer gem are different from those provided by the rails_wizard gem. Applications generated with the Rails Apps Composer gem are more complete; for example, they may include a home page with sign-in, sign-out navigation links.
11
+ The rails_apps_composer gem is a fork of "Michael Bleigh's RailsWizard gem":https://github.com/intridea/rails_wizard (see credits below). The purpose of the fork is to provide recipes for ready-to-run Rails starter apps. Several recipes provided by the rails_apps_composer gem are different from those provided by the rails_wizard gem. Applications generated with the rails_apps_composer gem are more complete; for example, they may include a home page with sign-in, sign-out navigation links.
10
12
 
11
- Any issues? Please create a "GitHub issue":http://github.com/RailsApps/rails_apps_composer/issues.
13
+ h4. Alternatives
14
+
15
+ See a list of "Rails Application Template Projects":http://railsapps.github.com/rails-application-templates.html, particularly a list of "Application template-generating gems."
16
+
17
+ Notable alternatives are Dr. Nic Williams's "App Scrolls":http://appscrolls.org/ and Daniel Davey's "app_drone":http://drone.bz/.
12
18
 
13
19
  h2. !http://twitter-badges.s3.amazonaws.com/t_logo-a.png(Follow on Twitter)!:http://www.twitter.com/rails_apps Follow on Twitter
14
20
 
15
21
  Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps. Tweet some praise if you like what you've found.
16
22
 
17
- h2. Suggested Use
23
+ h2. Suggested Uses
24
+
25
+ * Create a starter app.
26
+ * Make an application template that generates a new Rails app in seconds.
18
27
 
19
28
  Any developer can quickly generate a Rails web application using the @rails new@ command. In practice, experienced Rails developers typically add an assortment of useful additional packages (gems) before beginning development of any web application. A developer often uses the same set of packages to get started and may create a "starter app" that can be copied and reused for any new project.
20
29
 
@@ -22,7 +31,7 @@ It can be a hassle to integrate some of the most commonly used gems, particularl
22
31
 
23
32
  If you use this gem to create your Rails starter app, you can expect the pieces to work together. If they don't, you can report problems and look for identified "issues":http://github.com/RailsApps/rails_apps_composer/issues (and perhaps contributed fixes).
24
33
 
25
- If you use this gem to create a reusable application template (see the instructions below), you can check for changes to recipes here and reassemble your application template as packages evolve.
34
+ 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.
26
35
 
27
36
  h2. Dependencies
28
37
 
@@ -31,7 +40,7 @@ Before generating a new Rails app, you will need:
31
40
  * The Ruby language (version 1.9.3)
32
41
  * Rails 3.1 or newer
33
42
 
34
- See "Installing Rails 3.2":http://railsapps.github.com/installing-rails.html for detailed instructions and advice.
43
+ See "Installing Rails":http://railsapps.github.com/installing-rails.html for detailed instructions and advice.
35
44
 
36
45
  h2. Installation
37
46
 
@@ -43,27 +52,49 @@ h2. Usage
43
52
 
44
53
  h4. List Recipes
45
54
 
46
- You can display a list of recipes:
55
+ <pre>
56
+ $ rails_apps_composer list
57
+ </pre>
47
58
 
48
- @$ rails_apps_composer list@
59
+ You can learn more about the available recipes by browsing the repository "recipes directory":https://github.com/RailsApps/rails_apps_composer/tree/master/recipes.
49
60
 
50
- You'll find more details about the available recipes by browsing the repository "recipes directory":https://github.com/RailsApps/rails_apps_composer/tree/master/recipes.
61
+ h4. Generate an App
51
62
 
52
- h4. Generate a Starter App
63
+ <pre>
64
+ $ rails_apps_composer new myapp -r haml home_page html5
65
+ </pre>
53
66
 
54
- There are two ways to use the Rails Apps Composer gem to generate a starter app.
67
+ The command with the @-r@ flag followed by a list of recipes generates an app.
55
68
 
56
- If you want to build a starter app for one-time use, you can build an application by providing a list of recipes with the @-r@ option. This will automatically generate an application using the specified recipes.
69
+ h4. Generate an App from Defaults
57
70
 
58
- If you want to create and save an application template that you can reuse as needed to "clone" identical starter apps, you can download the Rails Apps Composer project, customize recipes as needed, and use a @rake@ task to save a reusable application template file.
71
+ <pre>
72
+ $ rails_apps_composer --defaults=~/.rac
73
+ </pre>
59
74
 
60
- Each of these approaches is described below.
75
+ Use the @~/.rac@ file to specify a list of recipes and recipe preferences. See details below concerning the format of the defaults file.
61
76
 
62
- h2. Make Your Own Starter App for One-Time Use
77
+ h4. Generate a Template
63
78
 
64
- h4. Select Recipes
79
+ You may want a template to customize or share with others. See various "application templates":https://github.com/RailsApps/rails3-application-templates from the "Rails Apps project":https://github.com/RailsApps.
65
80
 
66
- You can mix and match recipes to create your own customized starter app. See an annotated list of available "recipes for the Rails Apps Composer gem":http://railsapps.github.com/rails-apps-recipes.html. For an up-to-date list, browse the repository "recipes directory":https://github.com/RailsApps/rails_apps_composer/tree/master/recipes to see what is available. Then provide your list of recipes to the Rails Apps Composer gem using the @-r@ option and generate an app as needed. Here's an example that creates a simple app using haml:
81
+ <pre>
82
+ $ rails_apps_composer template ~/Desktop/template.txt -r haml home_page html5
83
+ </pre>
84
+
85
+ The command with the @template@ argument followed by a filename and a list of recipes generates an application template.
86
+
87
+ Generate an app from the template at any time:
88
+
89
+ <pre>
90
+ $ rails new myapp -m ~/Desktop/template.txt
91
+ </pre>
92
+
93
+ Here is more information about usage of the gem.
94
+
95
+ h2. Generate an App
96
+
97
+ Mix and match recipes to create your own customized starter app. See an annotated list of available "recipes for the rails_apps_composer gem":http://railsapps.github.com/rails-apps-recipes.html. For an up-to-date list, browse the repository "recipes directory":https://github.com/RailsApps/rails_apps_composer/tree/master/recipes to see what is available. Then provide your list of recipes to the rails_apps_composer gem using the @-r@ option and generate an app as needed. Here's an example that creates a simple app using haml:
67
98
 
68
99
  <pre>
69
100
  $ rails_apps_composer new myapp -r haml home_page html5
@@ -71,41 +102,104 @@ $ rails_apps_composer new myapp -r haml home_page html5
71
102
 
72
103
  Replace @myapp@ with the name you want for your application.
73
104
 
74
- h2. Make Your Own Starter App with a Reusable Application Template
105
+ h2. Generate an App from Defaults
75
106
 
76
- You can modify the recipes and save an application template that creates your own customized starter app.
107
+ If you frequently generate an app and always use the same recipes and preferences, create a defaults file and produce the same app every time. A big thank you to Bryan Stearns for contributing this feature!
77
108
 
78
- First, you'll need to make your own copy of the Rails Apps Composer gem.
109
+ <pre>
110
+ $ rails_apps_composer --defaults=~/.rac
111
+ </pre>
112
+
113
+ If you create a shell alias such as @builditnow@ for the command, you'll have even less to remember.
79
114
 
80
- @$ git clone git://github.com/RailsApps/rails_apps_composer.git@
115
+ Here's the format of a typical defaults file:
81
116
 
82
- @$ cd rails_apps_composer@
117
+ <pre>
118
+ recipes:
119
+ - activerecord
120
+ - home_page
121
+ - html5
122
+ - sass
123
+ - rspec
124
+ - capybara
125
+ - guard
126
+ - extras
127
+ - git
128
+
129
+ activerecord:
130
+ database: sqlite3
131
+ auto_create: true
132
+
133
+ devise:
134
+ devise: standard
135
+ authorization: false
136
+
137
+ extras:
138
+ footnotes: false
139
+ ban_spiders: true
140
+ paginate: false
141
+ jsruntime: false
142
+
143
+ guard:
144
+ guard: standard
145
+
146
+ html5:
147
+ css_option: bootstrap_sass
148
+
149
+ rspec:
150
+ rspec: true
151
+ factory_girl: true
152
+ machinist: false
153
+
154
+ sass:
155
+ sass: true
156
+ </pre>
83
157
 
84
- The "mg":https://github.com/sr/mg "minimal gem" is required for development of the Rails Apps Composer gem. Several other gems are needed as well:
158
+ You'll have to look in the recipe files to determine the attribute (such as @css_option@) used to specify preferences.
85
159
 
86
- @$ gem install i18n activesupport thor rspec mg@
160
+ The list of recipes at the top will be included whenever you generate an app. The remaining hashes will be used to respond to prompts (questions) that recipes display. If there is no preference specified in the defaults file, rails_apps_composer will ask you to respond with a preference. That way, you can give yourself flexibility if you don't always have the same preference.
87
161
 
88
- h4. Customize the Recipes
162
+ When you run the command with the @--defaults@ option and no recipes specified on the command line, you'll see the prompt, "Which recipe would you like to add? (blank to finish)". If you want to use only your default recipes, just hit return. If you want to add a recipe for the app you are generating, just type the recipe name at the prompt. If you've provided your preferences for the recipe in your defaults file, you won't be prompted for preferences. If you haven't provided default preferences for the additional recipe, you'll be prompted normally.
89
163
 
90
- Modify or write new recipes as you wish (see below for details about writing recipes). You can run @rake spec@ to make sure your recipes conform to the required syntax.
164
+ h2. Generate a Template
91
165
 
92
- h4. Save the Application Template
166
+ The rails_apps_composer gem creates an application template as an intermediate step before generating an application. You can generate and save the application template. You may want a template to customize or share with others.
93
167
 
94
- The Rails Apps Composer gem creates an application template as an intermediate step before generating an application. You can generate and save the application template. Here's an example of generating an application template and saving the template to a file:
168
+ Here's an example of generating an application template and saving the template to a file:
95
169
 
96
170
  <pre>
97
- $ rails_apps_composer template ~/Desktop/template.txt -r recipe1 recipe2
171
+ $ rails_apps_composer template ~/Desktop/template.txt -r haml home_page html5
98
172
  </pre>
99
173
 
100
- The Rails Apps Composer gem creates an application template that can be used by the @rails new@ command with the @-m@ option. For example:
174
+ The command with the @template@ argument followed by a filename and a list of recipes generates an application template.
175
+
176
+ The rails_apps_composer gem creates an application template that can be used by the @rails new@ command with the @-m@ option. You can specify a local file as a template. For example:
101
177
 
102
178
  <pre>
103
179
  $ rails new myapp -m ~/Desktop/template.txt
104
180
  </pre>
105
181
 
106
- You can specify the @-T -O@ flags as needed to skip Test::Unit files and Active Record files.
182
+ The @raisl new@ command allows you to specify the @-T -O@ flags as needed to skip Test::Unit files and Active Record files.
183
+
184
+ The @-m@ option also allows you to specify a file 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:
185
+
186
+ <pre>
187
+ $ rails new myapp -m https://raw.github.com/RailsApps/rails3-application-templates/master/rails3-haml-html5-template.rb
188
+ </pre>
189
+
190
+ That's all it takes. You'll have a ready-to-use Rails web application in seconds.
191
+
192
+ h2. Recipe Compatibility
193
+
194
+ Our goal is to offer a collection of recipes that are known to work well together. The most commonly used recipes will likely work together because many developers have used the recipes and resolved any integration issues.
107
195
 
108
- That's all it takes. You'll have a ready-to-customize Rails web application in minutes.
196
+ Some of the recipes in the repository are contributed by developers who use only a few of the recipes. For example, the repository has recipes for Mongoid and OmniAuth that are known to work together. However, we don't know (for example) if the Mongoid and RailsAdmin recipes work together.
197
+
198
+ The maintainers and contributors to the project can't test every combination of recipes. We rely on contributors to alert us to issues and contribute patches as needed. If you find recipes that don't combine properly, please alert us with a "GitHub issue":http://github.com/RailsApps/rails_apps_composer/issues and contribute a fix if you can.
199
+
200
+ h2. Examples
201
+
202
+ We use the rails_apps_composer gem to create the "Rails Example Apps":http://railsapps.github.com/ for the "Rails Apps project":https://github.com/RailsApps. These example apps have been used by thousands of Rails developers. The recipes used for the Rails Apps examples are well-integrated and known to work in the specific combinations listed below.
109
203
 
110
204
  h4. Template for Rails 3 + Haml + HTML5
111
205
 
@@ -123,7 +217,7 @@ $ rails new myapp -m ~/Desktop/template.txt
123
217
 
124
218
  h4. Template for Rails 3 + Devise + RSpec + Cucumber
125
219
 
126
- To build a reusable application template for the "rails3-devise-rspec-cucumber":http://github.com/RailsApps/rails3-devise-rspec-cucumber/ example application, run the command:
220
+ To build an application template for the "rails3-devise-rspec-cucumber":http://github.com/RailsApps/rails3-devise-rspec-cucumber/ example application, run the command:
127
221
 
128
222
  <pre>
129
223
  $ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber guard action_mailer devise add_user home_page home_page_users seed_database users_page html5 simple_form cleanup extras git
@@ -132,12 +226,12 @@ $ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber gua
132
226
  Then generate the application using the @-T@ flag.
133
227
 
134
228
  <pre>
135
- $ rails new myapp -m ~/Desktop/template.txt -T
229
+ $ rails new rails3-devise-rspec-cucumber -m ~/Desktop/template.txt -T
136
230
  </pre>
137
231
 
138
232
  h4. Template for Rails 3 + Mongoid + Devise
139
233
 
140
- To build a reusable application template for the "rails3-mongoid-devise":http://github.com/RailsApps/rails3-mongoid-devise/ example application, run the command:
234
+ To build an application template for the "rails3-mongoid-devise":http://github.com/RailsApps/rails3-mongoid-devise/ example application, run the command:
141
235
 
142
236
  <pre>
143
237
  $ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber guard mongoid action_mailer devise add_user home_page home_page_users seed_database users_page html5 simple_form cleanup extras git
@@ -146,12 +240,12 @@ $ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber gua
146
240
  Then generate the application using the @-T -O@ flags.
147
241
 
148
242
  <pre>
149
- $ rails new myapp -m ~/Desktop/template.txt -T -O
243
+ $ rails new rails3-mongoid-devise -m ~/Desktop/template.txt -T -O
150
244
  </pre>
151
245
 
152
246
  h4. Template for Rails 3 + Mongoid + OmniAuth
153
247
 
154
- To build a reusable application template for the "rails3-mongoid-omniauth":http://github.com/RailsApps/rails3-mongoid-omniauth/ example application, run the command:
248
+ To build an application template for the "rails3-mongoid-omniauth":http://github.com/RailsApps/rails3-mongoid-omniauth/ example application, run the command:
155
249
 
156
250
  <pre>
157
251
  $ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber guard mongoid seed_database omniauth home_page home_page_users html5 simple_form users_page omniauth_email cleanup extras git
@@ -160,12 +254,12 @@ $ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber gua
160
254
  Then generate the application using the @-T -O@ flags.
161
255
 
162
256
  <pre>
163
- $ rails new myapp -m ~/Desktop/template.txt -T -O
257
+ $ rails new rails3-mongoid-omniauth -m ~/Desktop/template.txt -T -O
164
258
  </pre>
165
259
 
166
260
  h4. Template for Rails 3 + Subdomains
167
261
 
168
- To build a reusable application template for the "rails3-subdomains":https://github.com/RailsApps/rails3-subdomains example application, run the command:
262
+ To build an application template for the "rails3-subdomains":https://github.com/RailsApps/rails3-subdomains example application, run the command:
169
263
 
170
264
  <pre>
171
265
  $ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber guard mongoid action_mailer devise add_user home_page home_page_users seed_database users_page subdomains html5 simple_form cleanup extras git
@@ -174,20 +268,22 @@ $ rails_apps_composer template ~/Desktop/template.txt -r haml rspec cucumber gua
174
268
  Then generate the application using the @-T -O@ flags.
175
269
 
176
270
  <pre>
177
- $ rails new myapp -m ~/Desktop/template.txt -T -O
271
+ $ rails new rails3-subdomains -m ~/Desktop/template.txt -T -O
178
272
  </pre>
179
273
 
180
- h2. The Recipes
274
+ h2. Writing New Recipes
181
275
 
182
- For your reference, here’s an annotated list of available "recipes for the Rails Apps Composer gem":http://railsapps.github.com/rails-apps-recipes.html. For an up-to-date list, browse the repository "recipes directory":https://github.com/RailsApps/rails_apps_composer/tree/master/recipes.
276
+ You can find the rails_apps_composer recipe collection in the GitHub repository's "recipes directory":https://github.com/RailsApps/rails_apps_composer/tree/master/recipes. If you find errors or improve a recipe you can contribute to the project by submitting a pull request or creating a "Github issue":http://github.com/RailsApps/rails_apps_composer/issues.
183
277
 
184
- h2. Writing New Recipes
278
+ h4. Warning: Gnarly Code Ahead!
279
+
280
+ The best (and only) way to create a new recipe (or customize an existing one) is to examine several recipes to learn how they work. The "extras":https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/extras.rb recipe is a good place to start. Some recipes, such as the "add_user":https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/add_user.rb recipe, are very complex with multiple preferences and dependencies on other recipes.
185
281
 
186
- You can find the Rails Apps Composer recipe collection in the GitHub repository's "recipes directory":https://github.com/RailsApps/rails_apps_composer/tree/master/recipes. If you find errors or improve a recipe you can contribute to the project by submitting a pull request or creating a "Github issue":http://github.com/RailsApps/rails_apps_composer/issues.
282
+ Frankly, the recipe code (and the resulting application template) can be ugly. The code is not much more than a long procedural script with conditional statements to resolve dependencies or enable preferences, interspersed with snippets of template code that is injected into files. The inline template code (for example, code that sets up a Rails "view" file) is particularly ugly because it has to be indented to conform to its destination file, often making the recipe difficult to read. Nevertheless, the project has value and many developers have contributed recipes and added features.
187
283
 
188
284
  h4. Rails Wizard Basics
189
285
 
190
- For more information on all available options for authoring recipes that can be read by the rails_wizard or Rails Apps Composer gems, please see the "wiki for Michael Bleigh's RailsWizard gem":https://github.com/intridea/rails_wizard/wiki.
286
+ For more information on all available options for authoring recipes that can be read by the rails_wizard or rails_apps_composer gems, please see the "wiki for Michael Bleigh's RailsWizard gem":https://github.com/intridea/rails_wizard/wiki.
191
287
 
192
288
  Recipes are made of up *template code* and *YAML back-matter* stored in a ruby file. The @__END__@ parsing convention is used so that each recipe is actually a valid, parseable Ruby file. The structure of a recipe looks something like this:
193
289
 
@@ -206,9 +302,9 @@ description: Installs SuperGem which is useful for things
206
302
  author: mbleigh
207
303
  </pre>
208
304
 
209
- h4. Rails Apps Composer Differences
305
+ h4. Rails_apps_composer Differences
210
306
 
211
- The Rails Apps Composer gem is very similar to the rails_wizard gem, with one significant difference. The rails_wizard gem allows specification of execution order for recipes with @run_before@ and @run_after@ configuration flags. The Rails Apps Composer gem supports only the @run_after@ flag; additionally, the order in which you provide the recipes sets the execution order. This makes it easier to chain a series of recipes in the order you prefer. For example,
307
+ The rails_apps_composer gem is very similar to the rails_wizard gem, with one significant difference. The rails_wizard gem is supposed to allow specification of execution order for recipes with @run_before@ and @run_after@ configuration flags (though the "rails_wizard implentation has been reported as buggy":https://github.com/intridea/rails_wizard/issues/30). The rails_apps_composer gem supports only the @run_after@ flag; additionally, the order in which you provide the recipes sets the execution order. This makes it easier to chain a series of recipes in the order you prefer. For example,
212
308
 
213
309
  <pre>
214
310
  $ rails_apps_composer new myapp -r git haml
@@ -216,10 +312,6 @@ $ rails_apps_composer new myapp -r git haml
216
312
 
217
313
  installs git before haml.
218
314
 
219
- h4. Recipe Differences
220
-
221
- Several recipes provided by the Rails Apps Composer gem are different from those provided by the rails_wizard gem.
222
-
223
315
  h4. Rails Wizard RSpec Tests
224
316
 
225
317
  The gem has RSpec tests that automatically validate each recipe in the repository, so you should run @rake spec@ as a basic syntax check. Note that these don't verify that your recipe code itself works, just that the gem could properly parse and understand your recipe file.
@@ -250,28 +342,13 @@ Any issues? Please create a "GitHub issue":http://github.com/RailsApps/rails_app
250
342
 
251
343
  h2. Credits
252
344
 
253
- Daniel Kehoe maintains this gem as part of the "RailsApps Project":http://railsapps.github.com/.
345
+ Daniel Kehoe maintains this gem as part of the "Rails Apps Project":http://railsapps.github.com/.
254
346
 
255
347
  This gem is based on "Michael Bleigh's RailsWizard gem":https://github.com/intridea/rails_wizard. The original idea for a RailsWizard and the innovative implementation is the work of Michael Bleigh.
256
348
 
257
- "Fletcher Nichol's":http://silversky.ca/ project "fnichol/rails-template-recipes":https://github.com/fnichol/rails-template-recipes provides the basis for several recipes.
258
-
259
- h4. Contributors
260
-
261
- Recipes:
262
-
263
- * 'compass_960', 'redis' and 'resque' recipes contributed by Julián Porta
264
- * 'datamapper' recipe contributed by Peter Fern
265
- * 'active_admin' recipe contributed by Philippe Van Eerdenbrugghe
266
- * 'inherited_resources' and 'simple_form' recipes contributed by gmgp
267
- * Slim recipe contributed by "Claudio B.":https://github.com/claudiob
268
- * MongoLab recipe contributed by "Leo Lou":https://github.com/l4u
269
- * RSpec, Cucumber, and Yard recipes contributed by "Ramon Brooker":http://cogniton-mind.tumblr.com/
270
- * Compass, Backbone, and Guard recipes contributed by "Ashley Woodard":https://github.com/ashley-woodard
271
-
272
- plus many patches and improvements contributed by many valued contributors (see CHANGELOG).
349
+ Please see the "CHANGELOG":https://github.com/RailsApps/rails_apps_composer/blob/master/CHANGELOG.textile for a list of contributors.
273
350
 
274
- h4. What You Can Do
351
+ h2. What You Can Do
275
352
 
276
353
  Is the gem useful to you? Follow the project on Twitter:
277
354
  "@rails_apps":http://twitter.com/rails_apps
@@ -281,4 +358,4 @@ h2. License
281
358
 
282
359
  h4. MIT License
283
360
 
284
- The Rails Apps Composer gem and its recipes are distributed under the MIT License.
361
+ The rails_apps_composer gem and its recipes are distributed under the MIT License.
@@ -6,14 +6,20 @@ module RailsWizard
6
6
  include Thor::Actions
7
7
  desc "new APP_NAME", "create a new Rails app"
8
8
  method_option :recipes, :type => :array, :aliases => "-r"
9
+ method_option :defaults, :type => :string, :aliases => "-d"
9
10
  def new(name)
10
- run_template(name, ask_for_recipes, nil)
11
+ recipes, defaults = load_defaults
12
+ recipes = ask_for_recipes(recipes)
13
+ run_template(name, recipes, defaults, nil)
11
14
  end
12
15
 
13
16
  desc "template TEMPLATE_FILE", "create a new Rails template"
14
17
  method_option :recipes, :type => :array, :aliases => "-r"
18
+ method_option :defaults, :type => :string, :aliases => "-d"
15
19
  def template(template_name)
16
- run_template(nil, ask_for_recipes, template_name)
20
+ recipes, defaults = load_defaults
21
+ recipes = ask_for_recipes(recipes)
22
+ run_template(nil, recipes, defaults, template_name)
17
23
  end
18
24
 
19
25
  desc "list [CATEGORY]", "list available recipes (optionally by category)"
@@ -37,6 +43,18 @@ module RailsWizard
37
43
  def green; "\033[32m" end
38
44
  def yellow; "\033[33m" end
39
45
 
46
+ def load_defaults
47
+ # Load defaults from a file; if a file specifies recipes, they'll be run *before*
48
+ # any on the command line (or prompted for)..
49
+ defaults = if options[:defaults]
50
+ File.open(options[:defaults]) {|f| YAML.load(f) }
51
+ else
52
+ {}
53
+ end
54
+ recipes = defaults.delete('recipes') { [] }
55
+ [recipes, defaults]
56
+ end
57
+
40
58
  def print_recipes(recipes)
41
59
  puts
42
60
  puts "#{bold}#{cyan}Available Recipes#{clear}:"
@@ -48,11 +66,10 @@ module RailsWizard
48
66
  puts
49
67
  end
50
68
 
51
- def ask_for_recipes
69
+ def ask_for_recipes(recipes)
52
70
  if options[:recipes]
53
- return options[:recipes]
71
+ return recipes + options[:recipes]
54
72
  end
55
- recipes=[]
56
73
  while recipe = ask("#{print_recipes(recipes)}#{bold}Which recipe would you like to add? #{clear}#{yellow}(blank to finish)#{clear}")
57
74
  if recipe == ''
58
75
  break
@@ -70,17 +87,18 @@ module RailsWizard
70
87
 
71
88
  #pass in name if you want to create a rails app
72
89
  #pass in file_name if you want to create a template
73
- def run_template(name, recipes, file_name=nil)
90
+ def run_template(name, recipes, defaults, file_name=nil)
74
91
  puts
75
92
  puts
76
93
  puts "#{bold}Generating#{name ? " and Running" : ''} Template..."
77
94
  puts
95
+
78
96
  if file_name
79
97
  file = File.new(file_name,'w')
80
98
  else
81
99
  file = Tempfile.new('template')
82
100
  end
83
- template = RailsWizard::Template.new(recipes)
101
+ template = RailsWizard::Template.new(recipes, defaults)
84
102
  file.write template.compile
85
103
  file.close
86
104
  if name
@@ -2,10 +2,11 @@ require 'active_support/ordered_hash'
2
2
 
3
3
  module RailsWizard
4
4
  class Config
5
- attr_reader :questions
5
+ attr_reader :questions, :defaults
6
6
 
7
- def initialize(schema)
7
+ def initialize(schema, defaults=nil)
8
8
  @questions = ActiveSupport::OrderedHash.new
9
+ @defaults = defaults
9
10
  schema.each do |hash|
10
11
  key = hash.keys.first
11
12
  details = hash.values.first
@@ -18,6 +19,7 @@ module RailsWizard
18
19
 
19
20
  def compile(values = {})
20
21
  result = []
22
+ values.merge!(defaults) if defaults
21
23
  result << "config = #{values.inspect}"
22
24
  @questions.each_pair do |key, question|
23
25
  result << "config['#{key}'] = #{question.compile} unless config.key?('#{key}')"
@@ -14,7 +14,7 @@ module RailsWizard
14
14
  self.key <=> another.key
15
15
  end
16
16
 
17
- ATTRIBUTES = %w(key args category name description template config exclusive tags run_before run_after requires)
17
+ ATTRIBUTES = %w(key args category name description template config exclusive tags run_before run_after requires defaults)
18
18
  DEFAULT_ATTRIBUTES = {
19
19
  :category => 'other',
20
20
  :args => [],
@@ -73,7 +73,7 @@ module RailsWizard
73
73
 
74
74
  def self.config
75
75
  return nil unless attributes[:config]
76
- RailsWizard::Config.new(attributes[:config])
76
+ RailsWizard::Config.new(attributes[:config], attributes[:defaults])
77
77
  end
78
78
 
79
79
  def attributes
@@ -1,9 +1,10 @@
1
1
  module RailsWizard
2
2
  class Template
3
- attr_reader :recipes
3
+ attr_reader :recipes, :defaults
4
4
 
5
- def initialize(recipes)
5
+ def initialize(recipes, defaults={})
6
6
  @recipes = recipes.map{|r| RailsWizard::Recipe.from_mongo(r)}
7
+ @defaults = defaults
7
8
  end
8
9
 
9
10
  def self.template_root
@@ -31,6 +32,7 @@ module RailsWizard
31
32
  end
32
33
  end
33
34
 
35
+ list.each {|recipe| recipe.defaults = defaults[recipe.key] }
34
36
  list
35
37
  end
36
38
  end
@@ -2,7 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe RailsWizard::Config do
4
4
  describe '#initialize' do
5
- subject{ RailsWizard::Config.new(YAML.load(@schema)) }
5
+ let(:defaults) { nil }
6
+ subject{ RailsWizard::Config.new(YAML.load(@schema), defaults) }
6
7
  it 'should add a question key for each key of the schema' do
7
8
  @schema = <<-YAML
8
9
  - test:
@@ -72,6 +73,14 @@ describe RailsWizard::Config do
72
73
  it 'should handle "unelss_recipe"' do
73
74
  lines[3].should be_include("!recipe?('awesome')")
74
75
  end
76
+
77
+ describe 'with defaults' do
78
+ let(:defaults) { { 'multiple_choice' => 'def' }}
79
+
80
+ it 'should process defaults' do
81
+ lines[0].should == 'config = {"multiple_choice"=>"def"}'
82
+ end
83
+ end
75
84
  end
76
85
 
77
86
  describe RailsWizard::Config::Prompt do
@@ -3,11 +3,16 @@ require 'spec_helper'
3
3
  describe RailsWizard::Template do
4
4
  subject{ RailsWizard::Template }
5
5
  let(:recipe){ RailsWizard::Recipe.generate('name','# test') }
6
+ let(:defaults){ { "some_option" => "value" } }
6
7
 
7
8
  describe '#initialize' do
8
9
  it 'should work with classes' do
9
10
  subject.new([recipe]).recipes.should == [recipe]
10
11
  end
12
+
13
+ it 'should accept optional defaults' do
14
+ subject.new([recipe], defaults).defaults.should == defaults
15
+ end
11
16
  end
12
17
 
13
18
  describe '#resolve_dependencies' do
data/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RailsWizard
2
- VERSION = "1.4.14"
2
+ VERSION = "1.4.15"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_apps_composer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.14
4
+ version: 1.4.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-20 00:00:00.000000000 Z
12
+ date: 2012-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
@@ -225,7 +225,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
225
  version: '0'
226
226
  segments:
227
227
  - 0
228
- hash: 2423708040536291564
228
+ hash: -1679240606259362355
229
229
  required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  none: false
231
231
  requirements:
@@ -234,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  version: '0'
235
235
  segments:
236
236
  - 0
237
- hash: 2423708040536291564
237
+ hash: -1679240606259362355
238
238
  requirements: []
239
239
  rubyforge_project: rails_apps_composer
240
240
  rubygems_version: 1.8.23