openskies 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (494) hide show
  1. data/CHANGELOG.md +87 -0
  2. data/README.rdoc +35 -0
  3. data/bin/openskies +9 -0
  4. data/guides/assets/images/belongs_to.png +0 -0
  5. data/guides/assets/images/book_icon.gif +0 -0
  6. data/guides/assets/images/bullet.gif +0 -0
  7. data/guides/assets/images/challenge.png +0 -0
  8. data/guides/assets/images/chapters_icon.gif +0 -0
  9. data/guides/assets/images/check_bullet.gif +0 -0
  10. data/guides/assets/images/credits_pic_blank.gif +0 -0
  11. data/guides/assets/images/csrf.png +0 -0
  12. data/guides/assets/images/customized_error_messages.png +0 -0
  13. data/guides/assets/images/edge_badge.png +0 -0
  14. data/guides/assets/images/error_messages.png +0 -0
  15. data/guides/assets/images/feature_tile.gif +0 -0
  16. data/guides/assets/images/footer_tile.gif +0 -0
  17. data/guides/assets/images/fxn.png +0 -0
  18. data/guides/assets/images/grey_bullet.gif +0 -0
  19. data/guides/assets/images/habtm.png +0 -0
  20. data/guides/assets/images/has_many.png +0 -0
  21. data/guides/assets/images/has_many_through.png +0 -0
  22. data/guides/assets/images/has_one.png +0 -0
  23. data/guides/assets/images/has_one_through.png +0 -0
  24. data/guides/assets/images/header_backdrop.png +0 -0
  25. data/guides/assets/images/header_tile.gif +0 -0
  26. data/guides/assets/images/i18n/demo_html_safe.png +0 -0
  27. data/guides/assets/images/i18n/demo_localized_pirate.png +0 -0
  28. data/guides/assets/images/i18n/demo_translated_en.png +0 -0
  29. data/guides/assets/images/i18n/demo_translated_pirate.png +0 -0
  30. data/guides/assets/images/i18n/demo_translation_missing.png +0 -0
  31. data/guides/assets/images/i18n/demo_untranslated.png +0 -0
  32. data/guides/assets/images/icons/README +5 -0
  33. data/guides/assets/images/icons/callouts/1.png +0 -0
  34. data/guides/assets/images/icons/callouts/10.png +0 -0
  35. data/guides/assets/images/icons/callouts/11.png +0 -0
  36. data/guides/assets/images/icons/callouts/12.png +0 -0
  37. data/guides/assets/images/icons/callouts/13.png +0 -0
  38. data/guides/assets/images/icons/callouts/14.png +0 -0
  39. data/guides/assets/images/icons/callouts/15.png +0 -0
  40. data/guides/assets/images/icons/callouts/2.png +0 -0
  41. data/guides/assets/images/icons/callouts/3.png +0 -0
  42. data/guides/assets/images/icons/callouts/4.png +0 -0
  43. data/guides/assets/images/icons/callouts/5.png +0 -0
  44. data/guides/assets/images/icons/callouts/6.png +0 -0
  45. data/guides/assets/images/icons/callouts/7.png +0 -0
  46. data/guides/assets/images/icons/callouts/8.png +0 -0
  47. data/guides/assets/images/icons/callouts/9.png +0 -0
  48. data/guides/assets/images/icons/caution.png +0 -0
  49. data/guides/assets/images/icons/example.png +0 -0
  50. data/guides/assets/images/icons/home.png +0 -0
  51. data/guides/assets/images/icons/important.png +0 -0
  52. data/guides/assets/images/icons/next.png +0 -0
  53. data/guides/assets/images/icons/note.png +0 -0
  54. data/guides/assets/images/icons/prev.png +0 -0
  55. data/guides/assets/images/icons/tip.png +0 -0
  56. data/guides/assets/images/icons/up.png +0 -0
  57. data/guides/assets/images/icons/warning.png +0 -0
  58. data/guides/assets/images/jaimeiniesta.jpg +0 -0
  59. data/guides/assets/images/nav_arrow.gif +0 -0
  60. data/guides/assets/images/polymorphic.png +0 -0
  61. data/guides/assets/images/posts_index.png +0 -0
  62. data/guides/assets/images/radar.png +0 -0
  63. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  64. data/guides/assets/images/rails_guides_logo.gif +0 -0
  65. data/guides/assets/images/rails_logo_remix.gif +0 -0
  66. data/guides/assets/images/rails_welcome.png +0 -0
  67. data/guides/assets/images/session_fixation.png +0 -0
  68. data/guides/assets/images/tab_grey.gif +0 -0
  69. data/guides/assets/images/tab_info.gif +0 -0
  70. data/guides/assets/images/tab_note.gif +0 -0
  71. data/guides/assets/images/tab_red.gif +0 -0
  72. data/guides/assets/images/tab_yellow.gif +0 -0
  73. data/guides/assets/images/tab_yellow.png +0 -0
  74. data/guides/assets/images/validation_error_messages.png +0 -0
  75. data/guides/assets/images/vijaydev.jpg +0 -0
  76. data/guides/assets/javascripts/guides.js +7 -0
  77. data/guides/assets/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
  78. data/guides/assets/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
  79. data/guides/assets/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
  80. data/guides/assets/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
  81. data/guides/assets/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
  82. data/guides/assets/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
  83. data/guides/assets/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
  84. data/guides/assets/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
  85. data/guides/assets/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
  86. data/guides/assets/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
  87. data/guides/assets/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
  88. data/guides/assets/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
  89. data/guides/assets/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
  90. data/guides/assets/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
  91. data/guides/assets/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
  92. data/guides/assets/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
  93. data/guides/assets/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
  94. data/guides/assets/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
  95. data/guides/assets/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
  96. data/guides/assets/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
  97. data/guides/assets/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
  98. data/guides/assets/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
  99. data/guides/assets/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
  100. data/guides/assets/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
  101. data/guides/assets/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
  102. data/guides/assets/javascripts/syntaxhighlighter/shCore.js +17 -0
  103. data/guides/assets/stylesheets/fixes.css +16 -0
  104. data/guides/assets/stylesheets/kindle.css +11 -0
  105. data/guides/assets/stylesheets/main.css +453 -0
  106. data/guides/assets/stylesheets/print.css +52 -0
  107. data/guides/assets/stylesheets/reset.css +43 -0
  108. data/guides/assets/stylesheets/style.css +13 -0
  109. data/guides/assets/stylesheets/syntaxhighlighter/shCore.css +226 -0
  110. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
  111. data/guides/assets/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
  112. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
  113. data/guides/assets/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
  114. data/guides/assets/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
  115. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
  116. data/guides/assets/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
  117. data/guides/assets/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
  118. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
  119. data/guides/assets/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
  120. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
  121. data/guides/assets/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
  122. data/guides/assets/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
  123. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
  124. data/guides/assets/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
  125. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
  126. data/guides/assets/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +116 -0
  127. data/guides/code/getting_started/Gemfile +38 -0
  128. data/guides/code/getting_started/README.rdoc +261 -0
  129. data/guides/code/getting_started/Rakefile +7 -0
  130. data/guides/code/getting_started/app/assets/images/rails.png +0 -0
  131. data/guides/code/getting_started/app/assets/javascripts/application.js +15 -0
  132. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +3 -0
  133. data/guides/code/getting_started/app/assets/javascripts/home.js.coffee +3 -0
  134. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +3 -0
  135. data/guides/code/getting_started/app/assets/stylesheets/application.css +13 -0
  136. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +3 -0
  137. data/guides/code/getting_started/app/assets/stylesheets/home.css.scss +3 -0
  138. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +3 -0
  139. data/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss +56 -0
  140. data/guides/code/getting_started/app/controllers/application_controller.rb +3 -0
  141. data/guides/code/getting_started/app/controllers/comments_controller.rb +16 -0
  142. data/guides/code/getting_started/app/controllers/home_controller.rb +5 -0
  143. data/guides/code/getting_started/app/controllers/posts_controller.rb +84 -0
  144. data/guides/code/getting_started/app/helpers/application_helper.rb +2 -0
  145. data/guides/code/getting_started/app/helpers/comments_helper.rb +2 -0
  146. data/guides/code/getting_started/app/helpers/home_helper.rb +2 -0
  147. data/guides/code/getting_started/app/helpers/posts_helper.rb +5 -0
  148. data/guides/code/getting_started/app/models/comment.rb +3 -0
  149. data/guides/code/getting_started/app/models/post.rb +11 -0
  150. data/guides/code/getting_started/app/models/tag.rb +3 -0
  151. data/guides/code/getting_started/app/views/comments/_comment.html.erb +15 -0
  152. data/guides/code/getting_started/app/views/comments/_form.html.erb +13 -0
  153. data/guides/code/getting_started/app/views/home/index.html.erb +2 -0
  154. data/guides/code/getting_started/app/views/layouts/application.html.erb +14 -0
  155. data/guides/code/getting_started/app/views/posts/_form.html.erb +32 -0
  156. data/guides/code/getting_started/app/views/posts/edit.html.erb +6 -0
  157. data/guides/code/getting_started/app/views/posts/index.html.erb +27 -0
  158. data/guides/code/getting_started/app/views/posts/new.html.erb +5 -0
  159. data/guides/code/getting_started/app/views/posts/show.html.erb +31 -0
  160. data/guides/code/getting_started/app/views/tags/_form.html.erb +12 -0
  161. data/guides/code/getting_started/config/application.rb +59 -0
  162. data/guides/code/getting_started/config/boot.rb +6 -0
  163. data/guides/code/getting_started/config/database.yml +25 -0
  164. data/guides/code/getting_started/config/environment.rb +5 -0
  165. data/guides/code/getting_started/config/environments/development.rb +37 -0
  166. data/guides/code/getting_started/config/environments/production.rb +67 -0
  167. data/guides/code/getting_started/config/environments/test.rb +37 -0
  168. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +7 -0
  169. data/guides/code/getting_started/config/initializers/inflections.rb +15 -0
  170. data/guides/code/getting_started/config/initializers/mime_types.rb +5 -0
  171. data/guides/code/getting_started/config/initializers/secret_token.rb +7 -0
  172. data/guides/code/getting_started/config/initializers/session_store.rb +8 -0
  173. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +14 -0
  174. data/guides/code/getting_started/config/locales/en.yml +5 -0
  175. data/guides/code/getting_started/config/routes.rb +64 -0
  176. data/guides/code/getting_started/config.ru +4 -0
  177. data/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb +11 -0
  178. data/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb +12 -0
  179. data/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb +11 -0
  180. data/guides/code/getting_started/db/schema.rb +43 -0
  181. data/guides/code/getting_started/db/seeds.rb +7 -0
  182. data/guides/code/getting_started/doc/README_FOR_APP +2 -0
  183. data/guides/code/getting_started/public/404.html +26 -0
  184. data/guides/code/getting_started/public/422.html +26 -0
  185. data/guides/code/getting_started/public/500.html +25 -0
  186. data/guides/code/getting_started/public/favicon.ico +0 -0
  187. data/guides/code/getting_started/public/robots.txt +5 -0
  188. data/guides/code/getting_started/script/rails +6 -0
  189. data/guides/code/getting_started/test/fixtures/comments.yml +11 -0
  190. data/guides/code/getting_started/test/fixtures/posts.yml +11 -0
  191. data/guides/code/getting_started/test/fixtures/tags.yml +9 -0
  192. data/guides/code/getting_started/test/functional/comments_controller_test.rb +7 -0
  193. data/guides/code/getting_started/test/functional/home_controller_test.rb +9 -0
  194. data/guides/code/getting_started/test/functional/posts_controller_test.rb +49 -0
  195. data/guides/code/getting_started/test/performance/browsing_test.rb +12 -0
  196. data/guides/code/getting_started/test/test_helper.rb +13 -0
  197. data/guides/code/getting_started/test/unit/comment_test.rb +7 -0
  198. data/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb +4 -0
  199. data/guides/code/getting_started/test/unit/helpers/home_helper_test.rb +4 -0
  200. data/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb +4 -0
  201. data/guides/code/getting_started/test/unit/post_test.rb +7 -0
  202. data/guides/code/getting_started/test/unit/tag_test.rb +7 -0
  203. data/guides/rails_guides/generator.rb +310 -0
  204. data/guides/rails_guides/helpers.rb +45 -0
  205. data/guides/rails_guides/indexer.rb +69 -0
  206. data/guides/rails_guides/levenshtein.rb +31 -0
  207. data/guides/rails_guides/textile_extensions.rb +63 -0
  208. data/guides/rails_guides.rb +50 -0
  209. data/guides/source/2_2_release_notes.textile +422 -0
  210. data/guides/source/2_3_release_notes.textile +610 -0
  211. data/guides/source/3_0_release_notes.textile +595 -0
  212. data/guides/source/3_1_release_notes.textile +553 -0
  213. data/guides/source/3_2_release_notes.textile +540 -0
  214. data/guides/source/_license.html.erb +2 -0
  215. data/guides/source/_welcome.html.erb +19 -0
  216. data/guides/source/action_controller_overview.textile +820 -0
  217. data/guides/source/action_mailer_basics.textile +516 -0
  218. data/guides/source/action_view_overview.textile +1497 -0
  219. data/guides/source/active_model_basics.textile +205 -0
  220. data/guides/source/active_record_basics.textile +218 -0
  221. data/guides/source/active_record_querying.textile +1433 -0
  222. data/guides/source/active_record_validations_callbacks.textile +1283 -0
  223. data/guides/source/active_resource_basics.textile +120 -0
  224. data/guides/source/active_support_core_extensions.textile +3713 -0
  225. data/guides/source/ajax_on_rails.textile +267 -0
  226. data/guides/source/api_documentation_guidelines.textile +185 -0
  227. data/guides/source/asset_pipeline.textile +707 -0
  228. data/guides/source/association_basics.textile +1959 -0
  229. data/guides/source/caching_with_rails.textile +437 -0
  230. data/guides/source/command_line.textile +574 -0
  231. data/guides/source/configuring.textile +641 -0
  232. data/guides/source/contributing_to_ruby_on_rails.textile +448 -0
  233. data/guides/source/credits.html.erb +72 -0
  234. data/guides/source/debugging_rails_applications.textile +714 -0
  235. data/guides/source/documents.yaml +157 -0
  236. data/guides/source/engines.textile +618 -0
  237. data/guides/source/form_helpers.textile +798 -0
  238. data/guides/source/generators.textile +621 -0
  239. data/guides/source/getting_started.textile +1929 -0
  240. data/guides/source/i18n.textile +931 -0
  241. data/guides/source/index.html.erb +30 -0
  242. data/guides/source/initialization.textile +1116 -0
  243. data/guides/source/kindle/KINDLE.md +26 -0
  244. data/guides/source/kindle/copyright.html.erb +1 -0
  245. data/guides/source/kindle/layout.html.erb +27 -0
  246. data/guides/source/kindle/rails_guides.opf.erb +52 -0
  247. data/guides/source/kindle/toc.html.erb +24 -0
  248. data/guides/source/kindle/toc.ncx.erb +64 -0
  249. data/guides/source/kindle/welcome.html.erb +5 -0
  250. data/guides/source/layout.html.erb +124 -0
  251. data/guides/source/layouts_and_rendering.textile +1237 -0
  252. data/guides/source/migrations.textile +900 -0
  253. data/guides/source/nested_model_forms.textile +222 -0
  254. data/guides/source/performance_testing.textile +597 -0
  255. data/guides/source/plugins.textile +464 -0
  256. data/guides/source/rails_application_templates.textile +240 -0
  257. data/guides/source/rails_on_rack.textile +236 -0
  258. data/guides/source/routing.textile +885 -0
  259. data/guides/source/ruby_on_rails_guides_guidelines.textile +79 -0
  260. data/guides/source/security.textile +1004 -0
  261. data/guides/source/testing.textile +947 -0
  262. data/guides/w3c_validator.rb +91 -0
  263. data/lib/rails/all.rb +15 -0
  264. data/lib/rails/application/bootstrap.rb +73 -0
  265. data/lib/rails/application/configuration.rb +151 -0
  266. data/lib/rails/application/finisher.rb +98 -0
  267. data/lib/rails/application/railties.rb +13 -0
  268. data/lib/rails/application/route_inspector.rb +84 -0
  269. data/lib/rails/application/routes_reloader.rb +56 -0
  270. data/lib/rails/application.rb +320 -0
  271. data/lib/rails/backtrace_cleaner.rb +42 -0
  272. data/lib/rails/cli.rb +16 -0
  273. data/lib/rails/code_statistics.rb +118 -0
  274. data/lib/rails/commands/application.rb +38 -0
  275. data/lib/rails/commands/benchmarker.rb +34 -0
  276. data/lib/rails/commands/console.rb +55 -0
  277. data/lib/rails/commands/dbconsole.rb +123 -0
  278. data/lib/rails/commands/destroy.rb +10 -0
  279. data/lib/rails/commands/generate.rb +12 -0
  280. data/lib/rails/commands/plugin.rb +544 -0
  281. data/lib/rails/commands/plugin_new.rb +11 -0
  282. data/lib/rails/commands/profiler.rb +32 -0
  283. data/lib/rails/commands/runner.rb +54 -0
  284. data/lib/rails/commands/server.rb +100 -0
  285. data/lib/rails/commands/update.rb +9 -0
  286. data/lib/rails/commands.rb +104 -0
  287. data/lib/rails/configuration.rb +89 -0
  288. data/lib/rails/console/app.rb +36 -0
  289. data/lib/rails/console/helpers.rb +11 -0
  290. data/lib/rails/engine/commands.rb +43 -0
  291. data/lib/rails/engine/configuration.rb +84 -0
  292. data/lib/rails/engine/railties.rb +33 -0
  293. data/lib/rails/engine.rb +657 -0
  294. data/lib/rails/generators/actions.rb +325 -0
  295. data/lib/rails/generators/active_model.rb +78 -0
  296. data/lib/rails/generators/app_base.rb +281 -0
  297. data/lib/rails/generators/base.rb +390 -0
  298. data/lib/rails/generators/css/assets/assets_generator.rb +13 -0
  299. data/lib/rails/generators/css/assets/templates/stylesheet.css +4 -0
  300. data/lib/rails/generators/css/scaffold/scaffold_generator.rb +16 -0
  301. data/lib/rails/generators/erb/controller/controller_generator.rb +20 -0
  302. data/lib/rails/generators/erb/controller/templates/view.html.erb +2 -0
  303. data/lib/rails/generators/erb/mailer/mailer_generator.rb +13 -0
  304. data/lib/rails/generators/erb/mailer/templates/view.text.erb +3 -0
  305. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +29 -0
  306. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +23 -0
  307. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +6 -0
  308. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +27 -0
  309. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +5 -0
  310. data/lib/rails/generators/erb/scaffold/templates/show.html.erb +12 -0
  311. data/lib/rails/generators/erb.rb +21 -0
  312. data/lib/rails/generators/generated_attribute.rb +107 -0
  313. data/lib/rails/generators/js/assets/assets_generator.rb +13 -0
  314. data/lib/rails/generators/js/assets/templates/javascript.js +2 -0
  315. data/lib/rails/generators/migration.rb +68 -0
  316. data/lib/rails/generators/named_base.rb +202 -0
  317. data/lib/rails/generators/rails/app/USAGE +15 -0
  318. data/lib/rails/generators/rails/app/app_generator.rb +303 -0
  319. data/lib/rails/generators/rails/app/templates/Gemfile +26 -0
  320. data/lib/rails/generators/rails/app/templates/README +261 -0
  321. data/lib/rails/generators/rails/app/templates/Rakefile +7 -0
  322. data/lib/rails/generators/rails/app/templates/app/assets/images/rails.png +0 -0
  323. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +17 -0
  324. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +13 -0
  325. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb +3 -0
  326. data/lib/rails/generators/rails/app/templates/app/helpers/application_helper.rb +2 -0
  327. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  328. data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
  329. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +14 -0
  330. data/lib/rails/generators/rails/app/templates/config/application.rb +74 -0
  331. data/lib/rails/generators/rails/app/templates/config/boot.rb +6 -0
  332. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +31 -0
  333. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +86 -0
  334. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +62 -0
  335. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +33 -0
  336. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +43 -0
  337. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +20 -0
  338. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +54 -0
  339. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +39 -0
  340. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +55 -0
  341. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +25 -0
  342. data/lib/rails/generators/rails/app/templates/config/environment.rb +5 -0
  343. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +41 -0
  344. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +73 -0
  345. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +39 -0
  346. data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb +7 -0
  347. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +15 -0
  348. data/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb +5 -0
  349. data/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt +7 -0
  350. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +8 -0
  351. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +16 -0
  352. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +5 -0
  353. data/lib/rails/generators/rails/app/templates/config/routes.rb +58 -0
  354. data/lib/rails/generators/rails/app/templates/config.ru +4 -0
  355. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +7 -0
  356. data/lib/rails/generators/rails/app/templates/doc/README_FOR_APP +2 -0
  357. data/lib/rails/generators/rails/app/templates/gitignore +15 -0
  358. data/lib/rails/generators/rails/app/templates/public/404.html +26 -0
  359. data/lib/rails/generators/rails/app/templates/public/422.html +26 -0
  360. data/lib/rails/generators/rails/app/templates/public/500.html +25 -0
  361. data/lib/rails/generators/rails/app/templates/public/favicon.ico +0 -0
  362. data/lib/rails/generators/rails/app/templates/public/index.html +241 -0
  363. data/lib/rails/generators/rails/app/templates/public/robots.txt +5 -0
  364. data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  365. data/lib/rails/generators/rails/app/templates/script/rails +5 -0
  366. data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  367. data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  368. data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  369. data/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb +12 -0
  370. data/lib/rails/generators/rails/app/templates/test/test_helper.rb +15 -0
  371. data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  372. data/lib/rails/generators/rails/assets/USAGE +20 -0
  373. data/lib/rails/generators/rails/assets/assets_generator.rb +25 -0
  374. data/lib/rails/generators/rails/assets/templates/javascript.js +2 -0
  375. data/lib/rails/generators/rails/assets/templates/stylesheet.css +4 -0
  376. data/lib/rails/generators/rails/controller/USAGE +18 -0
  377. data/lib/rails/generators/rails/controller/controller_generator.rb +20 -0
  378. data/lib/rails/generators/rails/controller/templates/controller.rb +13 -0
  379. data/lib/rails/generators/rails/generator/USAGE +12 -0
  380. data/lib/rails/generators/rails/generator/generator_generator.rb +25 -0
  381. data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +3 -0
  382. data/lib/rails/generators/rails/generator/templates/USAGE.tt +8 -0
  383. data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
  384. data/lib/rails/generators/rails/helper/USAGE +17 -0
  385. data/lib/rails/generators/rails/helper/helper_generator.rb +13 -0
  386. data/lib/rails/generators/rails/helper/templates/helper.rb +4 -0
  387. data/lib/rails/generators/rails/integration_test/USAGE +10 -0
  388. data/lib/rails/generators/rails/integration_test/integration_test_generator.rb +7 -0
  389. data/lib/rails/generators/rails/migration/USAGE +29 -0
  390. data/lib/rails/generators/rails/migration/migration_generator.rb +8 -0
  391. data/lib/rails/generators/rails/model/USAGE +45 -0
  392. data/lib/rails/generators/rails/model/model_generator.rb +8 -0
  393. data/lib/rails/generators/rails/observer/USAGE +12 -0
  394. data/lib/rails/generators/rails/observer/observer_generator.rb +7 -0
  395. data/lib/rails/generators/rails/performance_test/USAGE +10 -0
  396. data/lib/rails/generators/rails/performance_test/performance_test_generator.rb +7 -0
  397. data/lib/rails/generators/rails/plugin_new/USAGE +10 -0
  398. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +318 -0
  399. data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +29 -0
  400. data/lib/rails/generators/rails/plugin_new/templates/Gemfile +23 -0
  401. data/lib/rails/generators/rails/plugin_new/templates/MIT-LICENSE +20 -0
  402. data/lib/rails/generators/rails/plugin_new/templates/README.rdoc +3 -0
  403. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +31 -0
  404. data/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt +4 -0
  405. data/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt +4 -0
  406. data/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory +0 -0
  407. data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
  408. data/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt +14 -0
  409. data/lib/rails/generators/rails/plugin_new/templates/config/routes.rb +6 -0
  410. data/lib/rails/generators/rails/plugin_new/templates/gitignore +7 -0
  411. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +7 -0
  412. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/version.rb +3 -0
  413. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb +6 -0
  414. data/lib/rails/generators/rails/plugin_new/templates/lib/tasks/%name%_tasks.rake +4 -0
  415. data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +18 -0
  416. data/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb +10 -0
  417. data/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb +4 -0
  418. data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +7 -0
  419. data/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb +7 -0
  420. data/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb +12 -0
  421. data/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb +15 -0
  422. data/lib/rails/generators/rails/resource/USAGE +23 -0
  423. data/lib/rails/generators/rails/resource/resource_generator.rb +20 -0
  424. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +50 -0
  425. data/lib/rails/generators/rails/scaffold/USAGE +35 -0
  426. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +23 -0
  427. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +56 -0
  428. data/lib/rails/generators/rails/scaffold_controller/USAGE +19 -0
  429. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +25 -0
  430. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +89 -0
  431. data/lib/rails/generators/rails/session_migration/USAGE +8 -0
  432. data/lib/rails/generators/rails/session_migration/session_migration_generator.rb +8 -0
  433. data/lib/rails/generators/rails/task/USAGE +9 -0
  434. data/lib/rails/generators/rails/task/task_generator.rb +12 -0
  435. data/lib/rails/generators/rails/task/templates/task.rb +8 -0
  436. data/lib/rails/generators/resource_helpers.rb +80 -0
  437. data/lib/rails/generators/test_case.rb +247 -0
  438. data/lib/rails/generators/test_unit/controller/controller_generator.rb +15 -0
  439. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +19 -0
  440. data/lib/rails/generators/test_unit/helper/helper_generator.rb +13 -0
  441. data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +6 -0
  442. data/lib/rails/generators/test_unit/integration/integration_generator.rb +13 -0
  443. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +7 -0
  444. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +14 -0
  445. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +21 -0
  446. data/lib/rails/generators/test_unit/model/model_generator.rb +24 -0
  447. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +23 -0
  448. data/lib/rails/generators/test_unit/model/templates/unit_test.rb +9 -0
  449. data/lib/rails/generators/test_unit/observer/observer_generator.rb +13 -0
  450. data/lib/rails/generators/test_unit/observer/templates/unit_test.rb +9 -0
  451. data/lib/rails/generators/test_unit/performance/performance_generator.rb +13 -0
  452. data/lib/rails/generators/test_unit/performance/templates/performance_test.rb +12 -0
  453. data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +13 -0
  454. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +7 -0
  455. data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +3 -0
  456. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +38 -0
  457. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +51 -0
  458. data/lib/rails/generators/test_unit.rb +8 -0
  459. data/lib/rails/generators.rb +339 -0
  460. data/lib/rails/info.rb +116 -0
  461. data/lib/rails/info_controller.rb +15 -0
  462. data/lib/rails/initializable.rb +89 -0
  463. data/lib/rails/paths.rb +211 -0
  464. data/lib/rails/performance_test_help.rb +3 -0
  465. data/lib/rails/plugin.rb +92 -0
  466. data/lib/rails/rack/debugger.rb +24 -0
  467. data/lib/rails/rack/log_tailer.rb +34 -0
  468. data/lib/rails/rack/logger.rb +60 -0
  469. data/lib/rails/rack.rb +7 -0
  470. data/lib/rails/railtie/configurable.rb +35 -0
  471. data/lib/rails/railtie/configuration.rb +90 -0
  472. data/lib/rails/railtie.rb +202 -0
  473. data/lib/rails/ruby_version_check.rb +23 -0
  474. data/lib/rails/rubyprof_ext.rb +35 -0
  475. data/lib/rails/script_rails_loader.rb +29 -0
  476. data/lib/rails/source_annotation_extractor.rb +104 -0
  477. data/lib/rails/tasks/annotations.rake +20 -0
  478. data/lib/rails/tasks/documentation.rake +155 -0
  479. data/lib/rails/tasks/engine.rake +72 -0
  480. data/lib/rails/tasks/framework.rake +76 -0
  481. data/lib/rails/tasks/log.rake +9 -0
  482. data/lib/rails/tasks/middleware.rake +7 -0
  483. data/lib/rails/tasks/misc.rake +67 -0
  484. data/lib/rails/tasks/routes.rake +9 -0
  485. data/lib/rails/tasks/statistics.rake +16 -0
  486. data/lib/rails/tasks/tmp.rake +37 -0
  487. data/lib/rails/tasks.rb +16 -0
  488. data/lib/rails/test_help.rb +56 -0
  489. data/lib/rails/test_unit/railtie.rb +15 -0
  490. data/lib/rails/test_unit/sub_test_task.rb +8 -0
  491. data/lib/rails/test_unit/testing.rake +146 -0
  492. data/lib/rails/version.rb +10 -0
  493. data/lib/rails.rb +126 -0
  494. metadata +609 -0
@@ -0,0 +1,621 @@
1
+ h2. Creating and Customizing Rails Generators & Templates
2
+
3
+ Rails generators are an essential tool if you plan to improve your workflow. With this guide you will learn how to create generators and customize existing ones.
4
+
5
+ In this guide you will:
6
+
7
+ * Learn how to see which generators are available in your application
8
+ * Create a generator using templates
9
+ * Learn how Rails searches for generators before invoking them
10
+ * Customize your scaffold by creating new generators
11
+ * Customize your scaffold by changing generator templates
12
+ * Learn how to use fallbacks to avoid overwriting a huge set of generators
13
+ * Learn how to create an application template
14
+
15
+ endprologue.
16
+
17
+ NOTE: This guide is about generators in Rails 3, previous versions are not covered.
18
+
19
+ h3. First Contact
20
+
21
+ When you create an application using the +rails+ command, you are in fact using a Rails generator. After that, you can get a list of all available generators by just invoking +rails generate+:
22
+
23
+ <shell>
24
+ $ rails new myapp
25
+ $ cd myapp
26
+ $ rails generate
27
+ </shell>
28
+
29
+ You will get a list of all generators that comes with Rails. If you need a detailed description of the helper generator, for example, you can simply do:
30
+
31
+ <shell>
32
+ $ rails generate helper --help
33
+ </shell>
34
+
35
+ h3. Creating Your First Generator
36
+
37
+ Since Rails 3.0, generators are built on top of "Thor":https://github.com/wycats/thor. Thor provides powerful options parsing and a great API for manipulating files. For instance, let's build a generator that creates an initializer file named +initializer.rb+ inside +config/initializers+.
38
+
39
+ The first step is to create a file at +lib/generators/initializer_generator.rb+ with the following content:
40
+
41
+ <ruby>
42
+ class InitializerGenerator < Rails::Generators::Base
43
+ def create_initializer_file
44
+ create_file "config/initializers/initializer.rb", "# Add initialization content here"
45
+ end
46
+ end
47
+ </ruby>
48
+
49
+ NOTE: +create_file+ is a method provided by +Thor::Actions+. Documentation for +create_file+ and other Thor methods can be found in "Thor's documentation":http://rdoc.info/github/wycats/thor/master/Thor/Actions.html
50
+
51
+ Our new generator is quite simple: it inherits from +Rails::Generators::Base+ and has one method definition. Each public method in the generator is executed when a generator is invoked. Finally, we invoke the +create_file+ method that will create a file at the given destination with the given content. If you are familiar with the Rails Application Templates API, you'll feel right at home with the new generators API.
52
+
53
+ To invoke our new generator, we just need to do:
54
+
55
+ <shell>
56
+ $ rails generate initializer
57
+ </shell>
58
+
59
+ Before we go on, let's see our brand new generator description:
60
+
61
+ <shell>
62
+ $ rails generate initializer --help
63
+ </shell>
64
+
65
+ Rails is usually able to generate good descriptions if a generator is namespaced, as +ActiveRecord::Generators::ModelGenerator+, but not in this particular case. We can solve this problem in two ways. The first one is calling +desc+ inside our generator:
66
+
67
+ <ruby>
68
+ class InitializerGenerator < Rails::Generators::Base
69
+ desc "This generator creates an initializer file at config/initializers"
70
+ def create_initializer_file
71
+ create_file "config/initializers/initializer.rb", "# Add initialization content here"
72
+ end
73
+ end
74
+ </ruby>
75
+
76
+ Now we can see the new description by invoking +--help+ on the new generator. The second way to add a description is by creating a file named +USAGE+ in the same directory as our generator. We are going to do that in the next step.
77
+
78
+ h3. Creating Generators with Generators
79
+
80
+ Generators themselves have a generator:
81
+
82
+ <shell>
83
+ $ rails generate generator initializer
84
+ create lib/generators/initializer
85
+ create lib/generators/initializer/initializer_generator.rb
86
+ create lib/generators/initializer/USAGE
87
+ create lib/generators/initializer/templates
88
+ </shell>
89
+
90
+ This is the generator just created:
91
+
92
+ <ruby>
93
+ class InitializerGenerator < Rails::Generators::NamedBase
94
+ source_root File.expand_path("../templates", __FILE__)
95
+ end
96
+ </ruby>
97
+
98
+ First, notice that we are inheriting from +Rails::Generators::NamedBase+ instead of +Rails::Generators::Base+. This means that our generator expects at least one argument, which will be the name of the initializer, and will be available in our code in the variable +name+.
99
+
100
+ We can see that by invoking the description of this new generator (don't forget to delete the old generator file):
101
+
102
+ <shell>
103
+ $ rails generate initializer --help
104
+ Usage:
105
+ rails generate initializer NAME [options]
106
+ </shell>
107
+
108
+ We can also see that our new generator has a class method called +source_root+. This method points to where our generator templates will be placed, if any, and by default it points to the created directory +lib/generators/initializer/templates+.
109
+
110
+ In order to understand what a generator template means, let's create the file +lib/generators/initializer/templates/initializer.rb+ with the following content:
111
+
112
+ <ruby>
113
+ # Add initialization content here
114
+ </ruby>
115
+
116
+ And now let's change the generator to copy this template when invoked:
117
+
118
+ <ruby>
119
+ class InitializerGenerator < Rails::Generators::NamedBase
120
+ source_root File.expand_path("../templates", __FILE__)
121
+
122
+ def copy_initializer_file
123
+ copy_file "initializer.rb", "config/initializers/#{file_name}.rb"
124
+ end
125
+ end
126
+ </ruby>
127
+
128
+ And let's execute our generator:
129
+
130
+ <shell>
131
+ $ rails generate initializer core_extensions
132
+ </shell>
133
+
134
+ We can see that now an initializer named core_extensions was created at +config/initializers/core_extensions.rb+ with the contents of our template. That means that +copy_file+ copied a file in our source root to the destination path we gave. The method +file_name+ is automatically created when we inherit from +Rails::Generators::NamedBase+.
135
+
136
+ The methods that are available for generators are covered in the "final section":#generator-methods of this guide.
137
+
138
+ h3. Generators Lookup
139
+
140
+ When you run +rails generate initializer core_extensions+ Rails requires these files in turn until one is found:
141
+
142
+ <shell>
143
+ rails/generators/initializer/initializer_generator.rb
144
+ generators/initializer/initializer_generator.rb
145
+ rails/generators/initializer_generator.rb
146
+ generators/initializer_generator.rb
147
+ </shell>
148
+
149
+ If none is found you get an error message.
150
+
151
+ INFO: The examples above put files under the application's +lib+ because said directory belongs to +$LOAD_PATH+.
152
+
153
+ h3. Customizing Your Workflow
154
+
155
+ Rails own generators are flexible enough to let you customize scaffolding. They can be configured in +config/application.rb+, these are some defaults:
156
+
157
+ <ruby>
158
+ config.generators do |g|
159
+ g.orm :active_record
160
+ g.template_engine :erb
161
+ g.test_framework :test_unit, :fixture => true
162
+ end
163
+ </ruby>
164
+
165
+ Before we customize our workflow, let's first see what our scaffold looks like:
166
+
167
+ <shell>
168
+ $ rails generate scaffold User name:string
169
+ invoke active_record
170
+ create db/migrate/20091120125558_create_users.rb
171
+ create app/models/user.rb
172
+ invoke test_unit
173
+ create test/unit/user_test.rb
174
+ create test/fixtures/users.yml
175
+ route resources :users
176
+ invoke scaffold_controller
177
+ create app/controllers/users_controller.rb
178
+ invoke erb
179
+ create app/views/users
180
+ create app/views/users/index.html.erb
181
+ create app/views/users/edit.html.erb
182
+ create app/views/users/show.html.erb
183
+ create app/views/users/new.html.erb
184
+ create app/views/users/_form.html.erb
185
+ invoke test_unit
186
+ create test/functional/users_controller_test.rb
187
+ invoke helper
188
+ create app/helpers/users_helper.rb
189
+ invoke test_unit
190
+ create test/unit/helpers/users_helper_test.rb
191
+ invoke stylesheets
192
+ create app/assets/stylesheets/scaffold.css
193
+ </shell>
194
+
195
+ Looking at this output, it's easy to understand how generators work in Rails 3.0 and above. The scaffold generator doesn't actually generate anything, it just invokes others to do the work. This allows us to add/replace/remove any of those invocations. For instance, the scaffold generator invokes the scaffold_controller generator, which invokes erb, test_unit and helper generators. Since each generator has a single responsibility, they are easy to reuse, avoiding code duplication.
196
+
197
+ Our first customization on the workflow will be to stop generating stylesheets and test fixtures for scaffolds. We can achieve that by changing our configuration to the following:
198
+
199
+ <ruby>
200
+ config.generators do |g|
201
+ g.orm :active_record
202
+ g.template_engine :erb
203
+ g.test_framework :test_unit, :fixture => false
204
+ g.stylesheets false
205
+ end
206
+ </ruby>
207
+
208
+ If we generate another resource with the scaffold generator, we can see that neither stylesheets nor fixtures are created anymore. If you want to customize it further, for example to use DataMapper and RSpec instead of Active Record and TestUnit, it's just a matter of adding their gems to your application and configuring your generators.
209
+
210
+ To demonstrate this, we are going to create a new helper generator that simply adds some instance variable readers. First, we create a generator within the rails namespace, as this is where rails searches for generators used as hooks:
211
+
212
+ <shell>
213
+ $ rails generate generator rails/my_helper
214
+ </shell>
215
+
216
+ After that, we can delete both the +templates+ directory and the +source_root+ class method from our new generators, because we are not going to need them. So our new generator looks like the following:
217
+
218
+ <ruby>
219
+ class Rails::MyHelperGenerator < Rails::Generators::NamedBase
220
+ def create_helper_file
221
+ create_file "app/helpers/#{file_name}_helper.rb", <<-FILE
222
+ module #{class_name}Helper
223
+ attr_reader :#{plural_name}, :#{plural_name.singularize}
224
+ end
225
+ FILE
226
+ end
227
+ end
228
+ </ruby>
229
+
230
+ We can try out our new generator by creating a helper for users:
231
+
232
+ <shell>
233
+ $ rails generate my_helper products
234
+ </shell>
235
+
236
+ And it will generate the following helper file in +app/helpers+:
237
+
238
+ <ruby>
239
+ module ProductsHelper
240
+ attr_reader :products, :product
241
+ end
242
+ </ruby>
243
+
244
+ Which is what we expected. We can now tell scaffold to use our new helper generator by editing +config/application.rb+ once again:
245
+
246
+ <ruby>
247
+ config.generators do |g|
248
+ g.orm :active_record
249
+ g.template_engine :erb
250
+ g.test_framework :test_unit, :fixture => false
251
+ g.stylesheets false
252
+ g.helper :my_helper
253
+ end
254
+ </ruby>
255
+
256
+ and see it in action when invoking the generator:
257
+
258
+ <shell>
259
+ $ rails generate scaffold Post body:text
260
+ [...]
261
+ invoke my_helper
262
+ create app/helpers/posts_helper.rb
263
+ </shell>
264
+
265
+ We can notice on the output that our new helper was invoked instead of the Rails default. However one thing is missing, which is tests for our new generator and to do that, we are going to reuse old helpers test generators.
266
+
267
+ Since Rails 3.0, this is easy to do due to the hooks concept. Our new helper does not need to be focused in one specific test framework, it can simply provide a hook and a test framework just needs to implement this hook in order to be compatible.
268
+
269
+ To do that, we can change the generator this way:
270
+
271
+ <ruby>
272
+ class Rails::MyHelperGenerator < Rails::Generators::NamedBase
273
+ def create_helper_file
274
+ create_file "app/helpers/#{file_name}_helper.rb", <<-FILE
275
+ module #{class_name}Helper
276
+ attr_reader :#{plural_name}, :#{plural_name.singularize}
277
+ end
278
+ FILE
279
+ end
280
+
281
+ hook_for :test_framework
282
+ end
283
+ </ruby>
284
+
285
+ Now, when the helper generator is invoked and TestUnit is configured as the test framework, it will try to invoke both +Rails::TestUnitGenerator+ and +TestUnit::MyHelperGenerator+. Since none of those are defined, we can tell our generator to invoke +TestUnit::Generators::HelperGenerator+ instead, which is defined since it's a Rails generator. To do that, we just need to add:
286
+
287
+ <ruby>
288
+ # Search for :helper instead of :my_helper
289
+ hook_for :test_framework, :as => :helper
290
+ </ruby>
291
+
292
+ And now you can re-run scaffold for another resource and see it generating tests as well!
293
+
294
+ h3. Customizing Your Workflow by Changing Generators Templates
295
+
296
+ In the step above we simply wanted to add a line to the generated helper, without adding any extra functionality. There is a simpler way to do that, and it's by replacing the templates of already existing generators, in that case +Rails::Generators::HelperGenerator+.
297
+
298
+ In Rails 3.0 and above, generators don't just look in the source root for templates, they also search for templates in other paths. And one of them is +lib/templates+. Since we want to customize +Rails::Generators::HelperGenerator+, we can do that by simply making a template copy inside +lib/templates/rails/helper+ with the name +helper.rb+. So let's create that file with the following content:
299
+
300
+ <erb>
301
+ module <%= class_name %>Helper
302
+ attr_reader :<%= plural_name %>, <%= plural_name.singularize %>
303
+ end
304
+ </erb>
305
+
306
+ and revert the last change in +config/application.rb+:
307
+
308
+ <ruby>
309
+ config.generators do |g|
310
+ g.orm :active_record
311
+ g.template_engine :erb
312
+ g.test_framework :test_unit, :fixture => false
313
+ g.stylesheets false
314
+ end
315
+ </ruby>
316
+
317
+ If you generate another resource, you can see that we get exactly the same result! This is useful if you want to customize your scaffold templates and/or layout by just creating +edit.html.erb+, +index.html.erb+ and so on inside +lib/templates/erb/scaffold+.
318
+
319
+ h3. Adding Generators Fallbacks
320
+
321
+ One last feature about generators which is quite useful for plugin generators is fallbacks. For example, imagine that you want to add a feature on top of TestUnit like "shoulda":https://github.com/thoughtbot/shoulda does. Since TestUnit already implements all generators required by Rails and shoulda just wants to overwrite part of it, there is no need for shoulda to reimplement some generators again, it can simply tell Rails to use a +TestUnit+ generator if none was found under the +Shoulda+ namespace.
322
+
323
+ We can easily simulate this behavior by changing our +config/application.rb+ once again:
324
+
325
+ <ruby>
326
+ config.generators do |g|
327
+ g.orm :active_record
328
+ g.template_engine :erb
329
+ g.test_framework :shoulda, :fixture => false
330
+ g.stylesheets false
331
+
332
+ # Add a fallback!
333
+ g.fallbacks[:shoulda] = :test_unit
334
+ end
335
+ </ruby>
336
+
337
+ Now, if you create a Comment scaffold, you will see that the shoulda generators are being invoked, and at the end, they are just falling back to TestUnit generators:
338
+
339
+ <shell>
340
+ $ rails generate scaffold Comment body:text
341
+ invoke active_record
342
+ create db/migrate/20091120151323_create_comments.rb
343
+ create app/models/comment.rb
344
+ invoke shoulda
345
+ create test/unit/comment_test.rb
346
+ create test/fixtures/comments.yml
347
+ route resources :comments
348
+ invoke scaffold_controller
349
+ create app/controllers/comments_controller.rb
350
+ invoke erb
351
+ create app/views/comments
352
+ create app/views/comments/index.html.erb
353
+ create app/views/comments/edit.html.erb
354
+ create app/views/comments/show.html.erb
355
+ create app/views/comments/new.html.erb
356
+ create app/views/comments/_form.html.erb
357
+ create app/views/layouts/comments.html.erb
358
+ invoke shoulda
359
+ create test/functional/comments_controller_test.rb
360
+ invoke my_helper
361
+ create app/helpers/comments_helper.rb
362
+ invoke shoulda
363
+ create test/unit/helpers/comments_helper_test.rb
364
+ </shell>
365
+
366
+ Fallbacks allow your generators to have a single responsibility, increasing code reuse and reducing the amount of duplication.
367
+
368
+ h3. Application Templates
369
+
370
+ Now that you've seen how generators can be used _inside_ an application, did you know they can also be used to _generate_ applications too? This kind of generator is referred as a "template".
371
+
372
+ <ruby>
373
+ gem("rspec-rails", :group => "test")
374
+ gem("cucumber-rails", :group => "test")
375
+
376
+ if yes?("Would you like to install Devise?")
377
+ gem("devise")
378
+ generate("devise:install")
379
+ model_name = ask("What would you like the user model to be called? [user]")
380
+ model_name = "user" if model_name.blank?
381
+ generate("devise", model_name)
382
+ end
383
+ </ruby>
384
+
385
+ In the above template we specify that the application relies on the +rspec-rails+ and +cucumber-rails+ gem so these two will be added to the +test+ group in the +Gemfile+. Then we pose a question to the user about whether or not they would like to install Devise. If the user replies "y" or "yes" to this question, then the template will add Devise to the +Gemfile+ outside of any group and then runs the +devise:install+ generator. This template then takes the users input and runs the +devise+ generator, with the user's answer from the last question being passed to this generator.
386
+
387
+ Imagine that this template was in a file called +template.rb+. We can use it to modify the outcome of the +rails new+ command by using the +-m+ option and passing in the filename:
388
+
389
+ <shell>
390
+ $ rails new thud -m template.rb
391
+ </shell>
392
+
393
+ This command will generate the +Thud+ application, and then apply the template to the generated output.
394
+
395
+ Templates don't have to be stored on the local system, the +-m+ option also supports online templates:
396
+
397
+ <shell>
398
+ $ rails new thud -m https://gist.github.com/722911.txt
399
+ </shell>
400
+
401
+ Whilst the final section of this guide doesn't cover how to generate the most awesome template known to man, it will take you through the methods available at your disposal so that you can develop it yourself. These same methods are also available for generators.
402
+
403
+ h3. Generator methods
404
+
405
+ The following are methods available for both generators and templates for Rails.
406
+
407
+ NOTE: Methods provided by Thor are not covered this guide and can be found in "Thor's documentation":http://rdoc.info/github/wycats/thor/master/Thor/Actions.html
408
+
409
+ h4. +plugin+
410
+
411
+ +plugin+ will install a plugin into the current application.
412
+
413
+ <ruby>
414
+ plugin("dynamic-form", :git => "git://github.com/rails/dynamic-form.git")
415
+ </ruby>
416
+
417
+ Available options are:
418
+
419
+ * +:git+ - Takes the path to the git repository where this plugin can be found.
420
+ * +:branch+ - The name of the branch of the git repository where the plugin is found.
421
+ * +:submodule+ - Set to +true+ for the plugin to be installed as a submodule. Defaults to +false+.
422
+ * +:svn+ - Takes the path to the svn repository where this plugin can be found.
423
+ * +:revision+ - The revision of the plugin in an SVN repository.
424
+
425
+ h4. +gem+
426
+
427
+ Specifies a gem dependency of the application.
428
+
429
+ <ruby>
430
+ gem("rspec", :group => "test", :version => "2.1.0")
431
+ gem("devise", "1.1.5")
432
+ </ruby>
433
+
434
+ Available options are:
435
+
436
+ * +:group+ - The group in the +Gemfile+ where this gem should go.
437
+ * +:version+ - The version string of the gem you want to use. Can also be specified as the second argument to the method.
438
+ * +:git+ - The URL to the git repository for this gem.
439
+
440
+ Any additional options passed to this method are put on the end of the line:
441
+
442
+ <ruby>
443
+ gem("devise", :git => "git://github.com/plataformatec/devise", :branch => "master")
444
+ </ruby>
445
+
446
+ The above code will put the following line into +Gemfile+:
447
+
448
+ <ruby>
449
+ gem "devise", :git => "git://github.com/plataformatec/devise", :branch => "master"
450
+ </ruby>
451
+
452
+ h4. +gem_group+
453
+
454
+ Wraps gem entries inside a group:
455
+
456
+ <ruby>
457
+ gem_group :development, :test do
458
+ gem "rspec-rails"
459
+ end
460
+ </ruby>
461
+
462
+ h4. +add_source+
463
+
464
+ Adds a specified source to +Gemfile+:
465
+
466
+ <ruby>
467
+ add_source "http://gems.github.com"
468
+ </ruby>
469
+
470
+ h4. +application+
471
+
472
+ Adds a line to +config/application.rb+ directly after the application class definition.
473
+
474
+ <ruby>
475
+ application "config.asset_host = 'http://example.com'"
476
+ </ruby>
477
+
478
+ This method can also take a block:
479
+
480
+ <ruby>
481
+ application do
482
+ "config.asset_host = 'http://example.com'"
483
+ end
484
+ </ruby>
485
+
486
+ Available options are:
487
+
488
+ * +:env+ - Specify an environment for this configuration option. If you wish to use this option with the block syntax the recommended syntax is as follows:
489
+
490
+ <ruby>
491
+ application(nil, :env => "development") do
492
+ "config.asset_host = 'http://localhost:3000'"
493
+ end
494
+ </ruby>
495
+
496
+ h4. +git+
497
+
498
+ Runs the specified git command:
499
+
500
+ <ruby>
501
+ git :init
502
+ git :add => "."
503
+ git :commit => "-m First commit!"
504
+ git :add => "onefile.rb", :rm => "badfile.cxx"
505
+ </ruby>
506
+
507
+ The values of the hash here being the arguments or options passed to the specific git command. As per the final example shown here, multiple git commands can be specified at a time, but the order of their running is not guaranteed to be the same as the order that they were specified in.
508
+
509
+ h4. +vendor+
510
+
511
+ Places a file into +vendor+ which contains the specified code.
512
+
513
+ <ruby>
514
+ vendor("sekrit.rb", '#top secret stuff')
515
+ </ruby>
516
+
517
+ This method also takes a block:
518
+
519
+ <ruby>
520
+ vendor("seeds.rb") do
521
+ "puts 'in ur app, seeding ur database'"
522
+ end
523
+ </ruby>
524
+
525
+ h4. +lib+
526
+
527
+ Places a file into +lib+ which contains the specified code.
528
+
529
+ <ruby>
530
+ lib("special.rb", 'p Rails.root')
531
+ </ruby>
532
+
533
+ This method also takes a block:
534
+
535
+ <ruby>
536
+ lib("super_special.rb") do
537
+ puts "Super special!"
538
+ end
539
+ </ruby>
540
+
541
+ h4. +rakefile+
542
+
543
+ Creates a Rake file in the +lib/tasks+ directory of the application.
544
+
545
+ <ruby>
546
+ rakefile("test.rake", 'hello there')
547
+ </ruby>
548
+
549
+ This method also takes a block:
550
+
551
+ <ruby>
552
+ rakefile("test.rake") do
553
+ %Q{
554
+ task :rock => :environment do
555
+ puts "Rockin'"
556
+ end
557
+ }
558
+ end
559
+ </ruby>
560
+
561
+ h4. +initializer+
562
+
563
+ Creates an initializer in the +config/initializers+ directory of the application:
564
+
565
+ <ruby>
566
+ initializer("begin.rb", "puts 'this is the beginning'")
567
+ </ruby>
568
+
569
+ This method also takes a block:
570
+
571
+ <ruby>
572
+ initializer("begin.rb") do
573
+ puts "Almost done!"
574
+ end
575
+ </ruby>
576
+
577
+ h4. +generate+
578
+
579
+ Runs the specified generator where the first argument is the generator name and the remaining arguments are passed directly to the generator.
580
+
581
+ <ruby>
582
+ generate("scaffold", "forums title:string description:text")
583
+ </ruby>
584
+
585
+
586
+ h4. +rake+
587
+
588
+ Runs the specified Rake task.
589
+
590
+ <ruby>
591
+ rake("db:migrate")
592
+ </ruby>
593
+
594
+ Available options are:
595
+
596
+ * +:env+ - Specifies the environment in which to run this rake task.
597
+ * +:sudo+ - Whether or not to run this task using +sudo+. Defaults to +false+.
598
+
599
+ h4. +capify!+
600
+
601
+ Runs the +capify+ command from Capistrano at the root of the application which generates Capistrano configuration.
602
+
603
+ <ruby>
604
+ capify!
605
+ </ruby>
606
+
607
+ h4. +route+
608
+
609
+ Adds text to the +config/routes.rb+ file:
610
+
611
+ <ruby>
612
+ route("resources :people")
613
+ </ruby>
614
+
615
+ h4. +readme+
616
+
617
+ Output the contents of a file in the template's +source_path+, usually a README.
618
+
619
+ <ruby>
620
+ readme("README")
621
+ </ruby>