rails_csi 2.3.5.p6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (320) hide show
  1. data/CHANGELOG +2172 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +243 -0
  4. data/Rakefile +368 -0
  5. data/bin/about +4 -0
  6. data/bin/console +3 -0
  7. data/bin/dbconsole +3 -0
  8. data/bin/destroy +3 -0
  9. data/bin/generate +3 -0
  10. data/bin/performance/benchmarker +3 -0
  11. data/bin/performance/profiler +3 -0
  12. data/bin/plugin +3 -0
  13. data/bin/rails +20 -0
  14. data/bin/runner +3 -0
  15. data/bin/server +3 -0
  16. data/builtin/rails_info/rails/info.rb +131 -0
  17. data/builtin/rails_info/rails/info_controller.rb +9 -0
  18. data/builtin/rails_info/rails/info_helper.rb +2 -0
  19. data/builtin/rails_info/rails_info_controller.rb +2 -0
  20. data/configs/databases/frontbase.yml +28 -0
  21. data/configs/databases/ibm_db.yml +62 -0
  22. data/configs/databases/mysql.yml +60 -0
  23. data/configs/databases/oracle.yml +39 -0
  24. data/configs/databases/postgresql.yml +51 -0
  25. data/configs/databases/sqlite2.yml +19 -0
  26. data/configs/databases/sqlite3.yml +22 -0
  27. data/configs/empty.log +0 -0
  28. data/configs/initializers/backtrace_silencers.rb +7 -0
  29. data/configs/initializers/inflections.rb +10 -0
  30. data/configs/initializers/mime_types.rb +5 -0
  31. data/configs/initializers/new_rails_defaults.rb +21 -0
  32. data/configs/initializers/session_store.rb +15 -0
  33. data/configs/locales/en.yml +5 -0
  34. data/configs/routes.rb +43 -0
  35. data/configs/seeds.rb +7 -0
  36. data/dispatches/config.ru +7 -0
  37. data/dispatches/dispatch.fcgi +24 -0
  38. data/dispatches/dispatch.rb +10 -0
  39. data/dispatches/gateway.cgi +97 -0
  40. data/doc/README_FOR_APP +2 -0
  41. data/environments/boot.rb +110 -0
  42. data/environments/development.rb +17 -0
  43. data/environments/environment.rb +41 -0
  44. data/environments/production.rb +28 -0
  45. data/environments/test.rb +28 -0
  46. data/fresh_rakefile +10 -0
  47. data/guides/files/javascripts/code_highlighter.js +188 -0
  48. data/guides/files/javascripts/guides.js +8 -0
  49. data/guides/files/javascripts/highlighters.js +90 -0
  50. data/guides/files/stylesheets/main.css +441 -0
  51. data/guides/files/stylesheets/print.css +52 -0
  52. data/guides/files/stylesheets/reset.css +43 -0
  53. data/guides/files/stylesheets/style.css +13 -0
  54. data/guides/files/stylesheets/syntax.css +31 -0
  55. data/guides/images/belongs_to.png +0 -0
  56. data/guides/images/book_icon.gif +0 -0
  57. data/guides/images/bullet.gif +0 -0
  58. data/guides/images/chapters_icon.gif +0 -0
  59. data/guides/images/check_bullet.gif +0 -0
  60. data/guides/images/credits_pic_blank.gif +0 -0
  61. data/guides/images/csrf.png +0 -0
  62. data/guides/images/customized_error_messages.png +0 -0
  63. data/guides/images/error_messages.png +0 -0
  64. data/guides/images/feature_tile.gif +0 -0
  65. data/guides/images/footer_tile.gif +0 -0
  66. data/guides/images/fxn.jpg +0 -0
  67. data/guides/images/grey_bullet.gif +0 -0
  68. data/guides/images/habtm.png +0 -0
  69. data/guides/images/has_many.png +0 -0
  70. data/guides/images/has_many_through.png +0 -0
  71. data/guides/images/has_one.png +0 -0
  72. data/guides/images/has_one_through.png +0 -0
  73. data/guides/images/header_backdrop.png +0 -0
  74. data/guides/images/header_tile.gif +0 -0
  75. data/guides/images/i18n/demo_localized_pirate.png +0 -0
  76. data/guides/images/i18n/demo_translated_en.png +0 -0
  77. data/guides/images/i18n/demo_translated_pirate.png +0 -0
  78. data/guides/images/i18n/demo_translation_missing.png +0 -0
  79. data/guides/images/i18n/demo_untranslated.png +0 -0
  80. data/guides/images/icons/README +5 -0
  81. data/guides/images/icons/callouts/1.png +0 -0
  82. data/guides/images/icons/callouts/10.png +0 -0
  83. data/guides/images/icons/callouts/11.png +0 -0
  84. data/guides/images/icons/callouts/12.png +0 -0
  85. data/guides/images/icons/callouts/13.png +0 -0
  86. data/guides/images/icons/callouts/14.png +0 -0
  87. data/guides/images/icons/callouts/15.png +0 -0
  88. data/guides/images/icons/callouts/2.png +0 -0
  89. data/guides/images/icons/callouts/3.png +0 -0
  90. data/guides/images/icons/callouts/4.png +0 -0
  91. data/guides/images/icons/callouts/5.png +0 -0
  92. data/guides/images/icons/callouts/6.png +0 -0
  93. data/guides/images/icons/callouts/7.png +0 -0
  94. data/guides/images/icons/callouts/8.png +0 -0
  95. data/guides/images/icons/callouts/9.png +0 -0
  96. data/guides/images/icons/caution.png +0 -0
  97. data/guides/images/icons/example.png +0 -0
  98. data/guides/images/icons/home.png +0 -0
  99. data/guides/images/icons/important.png +0 -0
  100. data/guides/images/icons/next.png +0 -0
  101. data/guides/images/icons/note.png +0 -0
  102. data/guides/images/icons/prev.png +0 -0
  103. data/guides/images/icons/tip.png +0 -0
  104. data/guides/images/icons/up.png +0 -0
  105. data/guides/images/icons/warning.png +0 -0
  106. data/guides/images/nav_arrow.gif +0 -0
  107. data/guides/images/polymorphic.png +0 -0
  108. data/guides/images/posts_index.png +0 -0
  109. data/guides/images/rails_guides_logo.gif +0 -0
  110. data/guides/images/rails_logo_remix.gif +0 -0
  111. data/guides/images/rails_welcome.png +0 -0
  112. data/guides/images/session_fixation.png +0 -0
  113. data/guides/images/tab_grey.gif +0 -0
  114. data/guides/images/tab_info.gif +0 -0
  115. data/guides/images/tab_note.gif +0 -0
  116. data/guides/images/tab_red.gif +0 -0
  117. data/guides/images/tab_yellow.gif +0 -0
  118. data/guides/images/tab_yellow.png +0 -0
  119. data/guides/images/validation_error_messages.png +0 -0
  120. data/guides/rails_guides.rb +42 -0
  121. data/guides/rails_guides/generator.rb +138 -0
  122. data/guides/rails_guides/helpers.rb +34 -0
  123. data/guides/rails_guides/indexer.rb +55 -0
  124. data/guides/rails_guides/textile_extensions.rb +41 -0
  125. data/guides/source/2_2_release_notes.textile +422 -0
  126. data/guides/source/2_3_release_notes.textile +610 -0
  127. data/guides/source/action_controller_overview.textile +776 -0
  128. data/guides/source/action_mailer_basics.textile +424 -0
  129. data/guides/source/active_record_basics.textile +135 -0
  130. data/guides/source/active_record_querying.textile +969 -0
  131. data/guides/source/activerecord_validations_callbacks.textile +1086 -0
  132. data/guides/source/association_basics.textile +1781 -0
  133. data/guides/source/caching_with_rails.textile +524 -0
  134. data/guides/source/command_line.textile +589 -0
  135. data/guides/source/configuring.textile +234 -0
  136. data/guides/source/contribute.textile +71 -0
  137. data/guides/source/contributing_to_rails.textile +239 -0
  138. data/guides/source/credits.erb.textile +52 -0
  139. data/guides/source/debugging_rails_applications.textile +709 -0
  140. data/guides/source/form_helpers.textile +766 -0
  141. data/guides/source/getting_started.textile +1297 -0
  142. data/guides/source/i18n.textile +912 -0
  143. data/guides/source/index.erb.textile +124 -0
  144. data/guides/source/layout.html.erb +103 -0
  145. data/guides/source/layouts_and_rendering.textile +979 -0
  146. data/guides/source/migrations.textile +591 -0
  147. data/guides/source/nested_model_forms.textile +222 -0
  148. data/guides/source/performance_testing.textile +531 -0
  149. data/guides/source/plugins.textile +1512 -0
  150. data/guides/source/rails_on_rack.textile +309 -0
  151. data/guides/source/routing.textile +903 -0
  152. data/guides/source/security.textile +986 -0
  153. data/guides/source/testing.textile +951 -0
  154. data/helpers/application_controller.rb +10 -0
  155. data/helpers/application_helper.rb +3 -0
  156. data/helpers/performance_test.rb +9 -0
  157. data/helpers/test_helper.rb +38 -0
  158. data/html/404.html +30 -0
  159. data/html/422.html +30 -0
  160. data/html/500.html +30 -0
  161. data/html/favicon.ico +0 -0
  162. data/html/images/rails.png +0 -0
  163. data/html/index.html +275 -0
  164. data/html/javascripts/application.js +2 -0
  165. data/html/javascripts/controls.js +963 -0
  166. data/html/javascripts/dragdrop.js +973 -0
  167. data/html/javascripts/effects.js +1128 -0
  168. data/html/javascripts/prototype.js +4320 -0
  169. data/html/robots.txt +5 -0
  170. data/lib/code_statistics.rb +107 -0
  171. data/lib/commands.rb +17 -0
  172. data/lib/commands/about.rb +3 -0
  173. data/lib/commands/console.rb +45 -0
  174. data/lib/commands/dbconsole.rb +87 -0
  175. data/lib/commands/destroy.rb +6 -0
  176. data/lib/commands/generate.rb +6 -0
  177. data/lib/commands/ncgi/listener +86 -0
  178. data/lib/commands/ncgi/tracker +69 -0
  179. data/lib/commands/performance/benchmarker.rb +24 -0
  180. data/lib/commands/performance/profiler.rb +50 -0
  181. data/lib/commands/plugin.rb +968 -0
  182. data/lib/commands/runner.rb +54 -0
  183. data/lib/commands/server.rb +114 -0
  184. data/lib/commands/update.rb +4 -0
  185. data/lib/console_app.rb +30 -0
  186. data/lib/console_sandbox.rb +6 -0
  187. data/lib/console_with_helpers.rb +5 -0
  188. data/lib/dispatcher.rb +24 -0
  189. data/lib/fcgi_handler.rb +239 -0
  190. data/lib/initializer.rb +1128 -0
  191. data/lib/performance_test_help.rb +5 -0
  192. data/lib/rails/backtrace_cleaner.rb +54 -0
  193. data/lib/rails/gem_builder.rb +21 -0
  194. data/lib/rails/gem_dependency.rb +311 -0
  195. data/lib/rails/plugin.rb +179 -0
  196. data/lib/rails/plugin/loader.rb +198 -0
  197. data/lib/rails/plugin/locator.rb +100 -0
  198. data/lib/rails/rack.rb +8 -0
  199. data/lib/rails/rack/debugger.rb +23 -0
  200. data/lib/rails/rack/log_tailer.rb +35 -0
  201. data/lib/rails/rack/metal.rb +51 -0
  202. data/lib/rails/rack/static.rb +46 -0
  203. data/lib/rails/vendor_gem_source_index.rb +140 -0
  204. data/lib/rails/version.rb +9 -0
  205. data/lib/rails_generator.rb +43 -0
  206. data/lib/rails_generator/base.rb +266 -0
  207. data/lib/rails_generator/commands.rb +621 -0
  208. data/lib/rails_generator/generated_attribute.rb +46 -0
  209. data/lib/rails_generator/generators/applications/app/USAGE +9 -0
  210. data/lib/rails_generator/generators/applications/app/app_generator.rb +263 -0
  211. data/lib/rails_generator/generators/applications/app/scm/git.rb +18 -0
  212. data/lib/rails_generator/generators/applications/app/scm/scm.rb +8 -0
  213. data/lib/rails_generator/generators/applications/app/scm/svn.rb +7 -0
  214. data/lib/rails_generator/generators/applications/app/template_runner.rb +401 -0
  215. data/lib/rails_generator/generators/components/controller/USAGE +30 -0
  216. data/lib/rails_generator/generators/components/controller/controller_generator.rb +43 -0
  217. data/lib/rails_generator/generators/components/controller/templates/controller.rb +7 -0
  218. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +8 -0
  219. data/lib/rails_generator/generators/components/controller/templates/helper.rb +2 -0
  220. data/lib/rails_generator/generators/components/controller/templates/helper_test.rb +4 -0
  221. data/lib/rails_generator/generators/components/controller/templates/view.html.erb +2 -0
  222. data/lib/rails_generator/generators/components/helper/USAGE +24 -0
  223. data/lib/rails_generator/generators/components/helper/helper_generator.rb +25 -0
  224. data/lib/rails_generator/generators/components/helper/templates/helper.rb +2 -0
  225. data/lib/rails_generator/generators/components/helper/templates/helper_test.rb +4 -0
  226. data/lib/rails_generator/generators/components/integration_test/USAGE +8 -0
  227. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +16 -0
  228. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +10 -0
  229. data/lib/rails_generator/generators/components/mailer/USAGE +16 -0
  230. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +30 -0
  231. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
  232. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -0
  233. data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +15 -0
  234. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +20 -0
  235. data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
  236. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -0
  237. data/lib/rails_generator/generators/components/metal/USAGE +8 -0
  238. data/lib/rails_generator/generators/components/metal/metal_generator.rb +8 -0
  239. data/lib/rails_generator/generators/components/metal/templates/metal.rb +12 -0
  240. data/lib/rails_generator/generators/components/migration/USAGE +29 -0
  241. data/lib/rails_generator/generators/components/migration/migration_generator.rb +20 -0
  242. data/lib/rails_generator/generators/components/migration/templates/migration.rb +11 -0
  243. data/lib/rails_generator/generators/components/model/USAGE +27 -0
  244. data/lib/rails_generator/generators/components/model/model_generator.rb +52 -0
  245. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +19 -0
  246. data/lib/rails_generator/generators/components/model/templates/migration.rb +16 -0
  247. data/lib/rails_generator/generators/components/model/templates/model.rb +5 -0
  248. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +8 -0
  249. data/lib/rails_generator/generators/components/observer/USAGE +13 -0
  250. data/lib/rails_generator/generators/components/observer/observer_generator.rb +16 -0
  251. data/lib/rails_generator/generators/components/observer/templates/observer.rb +2 -0
  252. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +8 -0
  253. data/lib/rails_generator/generators/components/performance_test/USAGE +8 -0
  254. data/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +16 -0
  255. data/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +9 -0
  256. data/lib/rails_generator/generators/components/plugin/USAGE +25 -0
  257. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +39 -0
  258. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
  259. data/lib/rails_generator/generators/components/plugin/templates/README +13 -0
  260. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +23 -0
  261. data/lib/rails_generator/generators/components/plugin/templates/USAGE +8 -0
  262. data/lib/rails_generator/generators/components/plugin/templates/generator.rb +8 -0
  263. data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -0
  264. data/lib/rails_generator/generators/components/plugin/templates/install.rb +1 -0
  265. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -0
  266. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +4 -0
  267. data/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +3 -0
  268. data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +1 -0
  269. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +8 -0
  270. data/lib/rails_generator/generators/components/resource/USAGE +23 -0
  271. data/lib/rails_generator/generators/components/resource/resource_generator.rb +76 -0
  272. data/lib/rails_generator/generators/components/resource/templates/controller.rb +2 -0
  273. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +8 -0
  274. data/lib/rails_generator/generators/components/resource/templates/helper.rb +2 -0
  275. data/lib/rails_generator/generators/components/resource/templates/helper_test.rb +4 -0
  276. data/lib/rails_generator/generators/components/scaffold/USAGE +29 -0
  277. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +103 -0
  278. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +85 -0
  279. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +45 -0
  280. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +2 -0
  281. data/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb +4 -0
  282. data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +17 -0
  283. data/lib/rails_generator/generators/components/scaffold/templates/style.css +54 -0
  284. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +18 -0
  285. data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +24 -0
  286. data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +17 -0
  287. data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +10 -0
  288. data/lib/rails_generator/generators/components/session_migration/USAGE +10 -0
  289. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +18 -0
  290. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +16 -0
  291. data/lib/rails_generator/lookup.rb +249 -0
  292. data/lib/rails_generator/manifest.rb +53 -0
  293. data/lib/rails_generator/options.rb +150 -0
  294. data/lib/rails_generator/scripts.rb +89 -0
  295. data/lib/rails_generator/scripts/destroy.rb +29 -0
  296. data/lib/rails_generator/scripts/generate.rb +7 -0
  297. data/lib/rails_generator/scripts/update.rb +12 -0
  298. data/lib/rails_generator/secret_key_generator.rb +24 -0
  299. data/lib/rails_generator/simple_logger.rb +46 -0
  300. data/lib/rails_generator/spec.rb +44 -0
  301. data/lib/railties_path.rb +1 -0
  302. data/lib/ruby_version_check.rb +17 -0
  303. data/lib/rubyprof_ext.rb +35 -0
  304. data/lib/source_annotation_extractor.rb +102 -0
  305. data/lib/tasks/annotations.rake +20 -0
  306. data/lib/tasks/databases.rake +436 -0
  307. data/lib/tasks/documentation.rake +88 -0
  308. data/lib/tasks/framework.rake +143 -0
  309. data/lib/tasks/gems.rake +78 -0
  310. data/lib/tasks/log.rake +9 -0
  311. data/lib/tasks/middleware.rake +7 -0
  312. data/lib/tasks/misc.rake +63 -0
  313. data/lib/tasks/rails.rb +9 -0
  314. data/lib/tasks/routes.rake +18 -0
  315. data/lib/tasks/statistics.rake +17 -0
  316. data/lib/tasks/testing.rake +139 -0
  317. data/lib/tasks/tmp.rake +37 -0
  318. data/lib/test_help.rb +38 -0
  319. data/lib/webrick_server.rb +156 -0
  320. metadata +495 -0
@@ -0,0 +1,46 @@
1
+ require 'optparse'
2
+
3
+ module Rails
4
+ module Generator
5
+ class GeneratedAttribute
6
+ attr_accessor :name, :type, :column
7
+
8
+ def initialize(name, type)
9
+ @name, @type = name, type.to_sym
10
+ @column = ActiveRecord::ConnectionAdapters::Column.new(name, nil, @type)
11
+ end
12
+
13
+ def field_type
14
+ @field_type ||= case type
15
+ when :integer, :float, :decimal then :text_field
16
+ when :datetime, :timestamp, :time then :datetime_select
17
+ when :date then :date_select
18
+ when :string then :text_field
19
+ when :text then :text_area
20
+ when :boolean then :check_box
21
+ else
22
+ :text_field
23
+ end
24
+ end
25
+
26
+ def default
27
+ @default ||= case type
28
+ when :integer then 1
29
+ when :float then 1.5
30
+ when :decimal then "9.99"
31
+ when :datetime, :timestamp, :time then Time.now.to_s(:db)
32
+ when :date then Date.today.to_s(:db)
33
+ when :string then "MyString"
34
+ when :text then "MyText"
35
+ when :boolean then false
36
+ else
37
+ ""
38
+ end
39
+ end
40
+
41
+ def reference?
42
+ [ :references, :belongs_to ].include?(self.type)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ Description:
2
+ The 'rails' command creates a new Rails application with a default
3
+ directory structure and configuration at the path you specify.
4
+
5
+ Example:
6
+ rails ~/Code/Ruby/weblog
7
+
8
+ This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
9
+ See the README in the newly created application to get going.
@@ -0,0 +1,263 @@
1
+ require 'rbconfig'
2
+ require File.dirname(__FILE__) + '/template_runner'
3
+ require 'digest/md5'
4
+ require 'active_support/secure_random'
5
+
6
+ class AppGenerator < Rails::Generator::Base
7
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
8
+
9
+ DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db )
10
+ DEFAULT_DATABASE = 'sqlite3'
11
+
12
+ mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.."
13
+ default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE),
14
+ :shebang => DEFAULT_SHEBANG, :with_dispatchers => false, :freeze => false
15
+
16
+
17
+ def initialize(runtime_args, runtime_options = {})
18
+ super
19
+
20
+ usage if args.empty?
21
+ usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db]))
22
+
23
+ @destination_root = args.shift
24
+ @app_name = File.basename(File.expand_path(@destination_root))
25
+ end
26
+
27
+ def manifest
28
+ record do |m|
29
+ create_directories(m)
30
+ create_root_files(m)
31
+ create_app_files(m)
32
+ create_config_files(m)
33
+ create_script_files(m)
34
+ create_test_files(m)
35
+ create_public_files(m)
36
+ create_documentation_file(m)
37
+ create_log_files(m)
38
+ end
39
+ end
40
+
41
+ def after_generate
42
+ if options[:template]
43
+ Rails::TemplateRunner.new(options[:template], @destination_root)
44
+ end
45
+ end
46
+
47
+ protected
48
+ def banner
49
+ "Usage: #{$0} /path/to/your/app [options]"
50
+ end
51
+
52
+ def add_options!(opt)
53
+ opt.separator ''
54
+ opt.separator 'Options:'
55
+ opt.on("-r", "--ruby=path", String,
56
+ "Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
57
+ "Default: #{DEFAULT_SHEBANG}") { |v| options[:shebang] = v }
58
+
59
+ opt.on("-d", "--database=name", String,
60
+ "Preconfigure for selected database (options: #{DATABASES.join('/')}).",
61
+ "Default: #{DEFAULT_DATABASE}") { |v| options[:db] = v }
62
+
63
+ opt.on("-D", "--with-dispatchers",
64
+ "Add CGI/FastCGI/mod_ruby dispatches code to generated application skeleton",
65
+ "Default: false") { |v| options[:with_dispatchers] = v }
66
+
67
+ opt.on("-f", "--freeze",
68
+ "Freeze Rails in vendor/rails from the gems generating the skeleton",
69
+ "Default: false") { |v| options[:freeze] = v }
70
+
71
+ opt.on("-m", "--template=path", String,
72
+ "Use an application template that lives at path (can be a filesystem path or URL).",
73
+ "Default: (none)") { |v| options[:template] = v }
74
+
75
+ end
76
+
77
+
78
+ private
79
+ def create_directories(m)
80
+ m.directory ''
81
+
82
+ # Intermediate directories are automatically created so don't sweat their absence here.
83
+ %w(
84
+ app/controllers
85
+ app/helpers
86
+ app/models
87
+ app/views/layouts
88
+ config/environments
89
+ config/initializers
90
+ config/locales
91
+ db
92
+ doc
93
+ lib
94
+ lib/tasks
95
+ log
96
+ public/images
97
+ public/javascripts
98
+ public/stylesheets
99
+ script/performance
100
+ test/fixtures
101
+ test/functional
102
+ test/integration
103
+ test/performance
104
+ test/unit
105
+ vendor
106
+ vendor/plugins
107
+ tmp/sessions
108
+ tmp/sockets
109
+ tmp/cache
110
+ tmp/pids
111
+ ).each { |path| m.directory(path) }
112
+ end
113
+
114
+ def create_root_files(m)
115
+ m.file "fresh_rakefile", "Rakefile"
116
+ m.file "README", "README"
117
+ end
118
+
119
+ def create_app_files(m)
120
+ m.file "helpers/application_controller.rb", "app/controllers/application_controller.rb"
121
+ m.file "helpers/application_helper.rb", "app/helpers/application_helper.rb"
122
+ end
123
+
124
+ def create_config_files(m)
125
+ create_database_configuration_file(m)
126
+ create_routes_file(m)
127
+ create_locale_file(m)
128
+ create_seeds_file(m)
129
+ create_initializer_files(m)
130
+ create_environment_files(m)
131
+ end
132
+
133
+ def create_documentation_file(m)
134
+ m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
135
+ end
136
+
137
+ def create_log_files(m)
138
+ %w( server production development test ).each do |file|
139
+ m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666
140
+ end
141
+ end
142
+
143
+ def create_public_files(m)
144
+ create_dispatch_files(m)
145
+ create_error_files(m)
146
+ create_welcome_file(m)
147
+ create_browser_convention_files(m)
148
+ create_rails_image(m)
149
+ create_javascript_files(m)
150
+ end
151
+
152
+ def create_script_files(m)
153
+ %w(
154
+ about console dbconsole destroy generate runner server plugin
155
+ performance/benchmarker performance/profiler
156
+ ).each do |file|
157
+ m.file "bin/#{file}", "script/#{file}", {
158
+ :chmod => 0755,
159
+ :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
160
+ }
161
+ end
162
+ end
163
+
164
+ def create_test_files(m)
165
+ m.file "helpers/test_helper.rb", "test/test_helper.rb"
166
+ m.file "helpers/performance_test.rb", "test/performance/browsing_test.rb"
167
+ end
168
+
169
+
170
+ def create_database_configuration_file(m)
171
+ m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => {
172
+ :app_name => @app_name,
173
+ :socket => options[:db] == "mysql" ? mysql_socket_location : nil }
174
+ end
175
+
176
+ def create_routes_file(m)
177
+ m.file "configs/routes.rb", "config/routes.rb"
178
+ end
179
+
180
+ def create_seeds_file(m)
181
+ m.file "configs/seeds.rb", "db/seeds.rb"
182
+ end
183
+
184
+ def create_initializer_files(m)
185
+ %w(
186
+ backtrace_silencers
187
+ inflections
188
+ mime_types
189
+ new_rails_defaults
190
+ ).each do |initializer|
191
+ m.file "configs/initializers/#{initializer}.rb", "config/initializers/#{initializer}.rb"
192
+ end
193
+
194
+ m.template "configs/initializers/session_store.rb", "config/initializers/session_store.rb",
195
+ :assigns => { :app_name => @app_name, :app_secret => ActiveSupport::SecureRandom.hex(64) }
196
+ end
197
+
198
+ def create_locale_file(m)
199
+ m.file "configs/locales/en.yml", "config/locales/en.yml"
200
+ end
201
+
202
+ def create_environment_files(m)
203
+ m.template "environments/environment.rb", "config/environment.rb",
204
+ :assigns => { :freeze => options[:freeze] }
205
+
206
+ m.file "environments/boot.rb", "config/boot.rb"
207
+ m.file "environments/production.rb", "config/environments/production.rb"
208
+ m.file "environments/development.rb", "config/environments/development.rb"
209
+ m.file "environments/test.rb", "config/environments/test.rb"
210
+ end
211
+
212
+
213
+ def create_dispatch_files(m)
214
+ if options[:with_dispatchers]
215
+ dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
216
+
217
+ m.file "dispatches/config.ru", "config.ru"
218
+ m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options
219
+ m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options
220
+ m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options
221
+ end
222
+ end
223
+
224
+ def create_error_files(m)
225
+ %w( 404 422 500 ).each do |file|
226
+ m.file "html/#{file}.html", "public/#{file}.html"
227
+ end
228
+ end
229
+
230
+ def create_welcome_file(m)
231
+ m.file 'html/index.html', 'public/index.html'
232
+ end
233
+
234
+ def create_browser_convention_files(m)
235
+ m.file "html/favicon.ico", "public/favicon.ico"
236
+ m.file "html/robots.txt", "public/robots.txt"
237
+ end
238
+
239
+ def create_rails_image(m)
240
+ m.file "html/images/rails.png", "public/images/rails.png"
241
+ end
242
+
243
+ def create_javascript_files(m)
244
+ %w( prototype effects dragdrop controls application ).each do |javascript|
245
+ m.file "html/javascripts/#{javascript}.js", "public/javascripts/#{javascript}.js"
246
+ end
247
+ end
248
+
249
+
250
+ def mysql_socket_location
251
+ [
252
+ "/tmp/mysql.sock", # default
253
+ "/var/run/mysqld/mysqld.sock", # debian/gentoo
254
+ "/var/tmp/mysql.sock", # freebsd
255
+ "/var/lib/mysql/mysql.sock", # fedora
256
+ "/opt/local/lib/mysql/mysql.sock", # fedora
257
+ "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
258
+ "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
259
+ "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
260
+ "/opt/lampp/var/mysql/mysql.sock" # xampp for linux
261
+ ].find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
262
+ end
263
+ end
@@ -0,0 +1,18 @@
1
+ STDOUT.sync = true
2
+
3
+ module Rails
4
+ class Git < Scm
5
+ def self.clone(repos, branch=nil)
6
+ system "git clone #{repos}"
7
+
8
+ if branch
9
+ system "cd #{repos.split('/').last}/"
10
+ system "git checkout #{branch}"
11
+ end
12
+ end
13
+
14
+ def self.run(command)
15
+ system "git #{command}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ module Rails
2
+ class Scm
3
+ private
4
+ def self.hash_to_parameters(hash)
5
+ hash.collect { |key, value| "--#{key} #{(value.kind_of?(String) ? value : "")}"}.join(" ")
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Rails
2
+ class Svn < Scm
3
+ def self.checkout(repos, branch = nil)
4
+ `svn checkout #{repos}/#{branch || "trunk"}`
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,401 @@
1
+ require File.dirname(__FILE__) + '/scm/scm'
2
+ require File.dirname(__FILE__) + '/scm/git'
3
+ require File.dirname(__FILE__) + '/scm/svn'
4
+
5
+ require 'open-uri'
6
+ require 'fileutils'
7
+
8
+ module Rails
9
+ class TemplateRunner
10
+ attr_reader :root
11
+ attr_writer :logger
12
+
13
+ def initialize(template, root = '') # :nodoc:
14
+ @root = File.expand_path(File.directory?(root) ? root : File.join(Dir.pwd, root))
15
+
16
+ log 'applying', "template: #{template}"
17
+
18
+ load_template(template)
19
+
20
+ log 'applied', "#{template}"
21
+ end
22
+
23
+ def load_template(template)
24
+ begin
25
+ code = open(template).read
26
+ in_root { self.instance_eval(code) }
27
+ rescue LoadError, Errno::ENOENT => e
28
+ raise "The template [#{template}] could not be loaded. Error: #{e}"
29
+ end
30
+ end
31
+
32
+ # Create a new file in the Rails project folder. Specify the
33
+ # relative path from RAILS_ROOT. Data is the return value of a block
34
+ # or a data string.
35
+ #
36
+ # ==== Examples
37
+ #
38
+ # file("lib/fun_party.rb") do
39
+ # hostname = ask("What is the virtual hostname I should use?")
40
+ # "vhost.name = #{hostname}"
41
+ # end
42
+ #
43
+ # file("config/apach.conf", "your apache config")
44
+ #
45
+ def file(filename, data = nil, log_action = true, &block)
46
+ log 'file', filename if log_action
47
+ dir, file = [File.dirname(filename), File.basename(filename)]
48
+
49
+ inside(dir) do
50
+ File.open(file, "w") do |f|
51
+ if block_given?
52
+ f.write(block.call)
53
+ else
54
+ f.write(data)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ # Install a plugin. You must provide either a Subversion url or Git url.
61
+ # For a Git-hosted plugin, you can specify if it should be added as a submodule instead of cloned.
62
+ #
63
+ # ==== Examples
64
+ #
65
+ # plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git'
66
+ # plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git', :submodule => true
67
+ # plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk'
68
+ #
69
+ def plugin(name, options)
70
+ log 'plugin', name
71
+
72
+ if options[:git] && options[:submodule]
73
+ in_root do
74
+ Git.run("submodule add #{options[:git]} vendor/plugins/#{name}")
75
+ end
76
+ elsif options[:git] || options[:svn]
77
+ in_root do
78
+ run_ruby_script("script/plugin install #{options[:svn] || options[:git]}", false)
79
+ end
80
+ else
81
+ log "! no git or svn provided for #{name}. skipping..."
82
+ end
83
+ end
84
+
85
+ # Adds an entry into config/environment.rb for the supplied gem :
86
+ def gem(name, options = {})
87
+ log 'gem', name
88
+ env = options.delete(:env)
89
+
90
+ gems_code = "config.gem '#{name}'"
91
+
92
+ if options.any?
93
+ opts = options.inject([]) {|result, h| result << [":#{h[0]} => #{h[1].inspect.gsub('"',"'")}"] }.sort.join(", ")
94
+ gems_code << ", #{opts}"
95
+ end
96
+
97
+ environment gems_code, :env => env
98
+ end
99
+
100
+ # Adds a line inside the Initializer block for config/environment.rb. Used by #gem
101
+ # If options :env is specified, the line is appended to the corresponding
102
+ # file in config/environments/#{env}.rb
103
+ def environment(data = nil, options = {}, &block)
104
+ sentinel = 'Rails::Initializer.run do |config|'
105
+
106
+ data = block.call if !data && block_given?
107
+
108
+ in_root do
109
+ if options[:env].nil?
110
+ gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
111
+ "#{match}\n " << data
112
+ end
113
+ else
114
+ Array.wrap(options[:env]).each do|env|
115
+ append_file "config/environments/#{env}.rb", "\n#{data}"
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ # Run a command in git.
122
+ #
123
+ # ==== Examples
124
+ #
125
+ # git :init
126
+ # git :add => "this.file that.rb"
127
+ # git :add => "onefile.rb", :rm => "badfile.cxx"
128
+ #
129
+ def git(command = {})
130
+ in_root do
131
+ if command.is_a?(Symbol)
132
+ log 'running', "git #{command}"
133
+ Git.run(command.to_s)
134
+ else
135
+ command.each do |command, options|
136
+ log 'running', "git #{command} #{options}"
137
+ Git.run("#{command} #{options}")
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ # Create a new file in the vendor/ directory. Code can be specified
144
+ # in a block or a data string can be given.
145
+ #
146
+ # ==== Examples
147
+ #
148
+ # vendor("sekrit.rb") do
149
+ # sekrit_salt = "#{Time.now}--#{3.years.ago}--#{rand}--"
150
+ # "salt = '#{sekrit_salt}'"
151
+ # end
152
+ #
153
+ # vendor("foreign.rb", "# Foreign code is fun")
154
+ #
155
+ def vendor(filename, data = nil, &block)
156
+ log 'vendoring', filename
157
+ file("vendor/#{filename}", data, false, &block)
158
+ end
159
+
160
+ # Create a new file in the lib/ directory. Code can be specified
161
+ # in a block or a data string can be given.
162
+ #
163
+ # ==== Examples
164
+ #
165
+ # lib("crypto.rb") do
166
+ # "crypted_special_value = '#{rand}--#{Time.now}--#{rand(1337)}--'"
167
+ # end
168
+ #
169
+ # lib("foreign.rb", "# Foreign code is fun")
170
+ #
171
+ def lib(filename, data = nil, &block)
172
+ log 'lib', filename
173
+ file("lib/#{filename}", data, false, &block)
174
+ end
175
+
176
+ # Create a new Rakefile with the provided code (either in a block or a string).
177
+ #
178
+ # ==== Examples
179
+ #
180
+ # rakefile("bootstrap.rake") do
181
+ # project = ask("What is the UNIX name of your project?")
182
+ #
183
+ # <<-TASK
184
+ # namespace :#{project} do
185
+ # task :bootstrap do
186
+ # puts "i like boots!"
187
+ # end
188
+ # end
189
+ # TASK
190
+ # end
191
+ #
192
+ # rakefile("seed.rake", "puts 'im plantin ur seedz'")
193
+ #
194
+ def rakefile(filename, data = nil, &block)
195
+ log 'rakefile', filename
196
+ file("lib/tasks/#{filename}", data, false, &block)
197
+ end
198
+
199
+ # Create a new initializer with the provided code (either in a block or a string).
200
+ #
201
+ # ==== Examples
202
+ #
203
+ # initializer("globals.rb") do
204
+ # data = ""
205
+ #
206
+ # ['MY_WORK', 'ADMINS', 'BEST_COMPANY_EVAR'].each do
207
+ # data << "#{const} = :entp"
208
+ # end
209
+ #
210
+ # data
211
+ # end
212
+ #
213
+ # initializer("api.rb", "API_KEY = '123456'")
214
+ #
215
+ def initializer(filename, data = nil, &block)
216
+ log 'initializer', filename
217
+ file("config/initializers/#{filename}", data, false, &block)
218
+ end
219
+
220
+ # Generate something using a generator from Rails or a plugin.
221
+ # The second parameter is the argument string that is passed to
222
+ # the generator or an Array that is joined.
223
+ #
224
+ # ==== Example
225
+ #
226
+ # generate(:authenticated, "user session")
227
+ #
228
+ def generate(what, *args)
229
+ log 'generating', what
230
+ argument = args.map(&:to_s).flatten.join(" ")
231
+
232
+ in_root { run_ruby_script("script/generate #{what} #{argument}", false) }
233
+ end
234
+
235
+ # Executes a command
236
+ #
237
+ # ==== Example
238
+ #
239
+ # inside('vendor') do
240
+ # run('ln -s ~/edge rails')
241
+ # end
242
+ #
243
+ def run(command, log_action = true)
244
+ log 'executing', "#{command} from #{Dir.pwd}" if log_action
245
+ `#{command}`
246
+ end
247
+
248
+ # Executes a ruby script (taking into account WIN32 platform quirks)
249
+ def run_ruby_script(command, log_action = true)
250
+ ruby_command = RUBY_PLATFORM=~ /win32/ ? 'ruby ' : ''
251
+ run("#{ruby_command}#{command}", log_action)
252
+ end
253
+
254
+ # Runs the supplied rake task
255
+ #
256
+ # ==== Example
257
+ #
258
+ # rake("db:migrate")
259
+ # rake("db:migrate", :env => "production")
260
+ # rake("gems:install", :sudo => true)
261
+ #
262
+ def rake(command, options = {})
263
+ log 'rake', command
264
+ env = options[:env] || 'development'
265
+ sudo = options[:sudo] ? 'sudo ' : ''
266
+ in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", false) }
267
+ end
268
+
269
+ # Just run the capify command in root
270
+ #
271
+ # ==== Example
272
+ #
273
+ # capify!
274
+ #
275
+ def capify!
276
+ log 'capifying'
277
+ in_root { run('capify .', false) }
278
+ end
279
+
280
+ # Add Rails to /vendor/rails
281
+ #
282
+ # ==== Example
283
+ #
284
+ # freeze!
285
+ #
286
+ def freeze!(args = {})
287
+ log 'vendor', 'rails edge'
288
+ in_root { run('rake rails:freeze:edge', false) }
289
+ end
290
+
291
+ # Make an entry in Rails routing file conifg/routes.rb
292
+ #
293
+ # === Example
294
+ #
295
+ # route "map.root :controller => :welcome"
296
+ #
297
+ def route(routing_code)
298
+ log 'route', routing_code
299
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
300
+
301
+ in_root do
302
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
303
+ "#{match}\n #{routing_code}\n"
304
+ end
305
+ end
306
+ end
307
+
308
+ protected
309
+
310
+ # Get a user's input
311
+ #
312
+ # ==== Example
313
+ #
314
+ # answer = ask("Should I freeze the latest Rails?")
315
+ # freeze! if ask("Should I freeze the latest Rails?") == "yes"
316
+ #
317
+ def ask(string)
318
+ log '', string
319
+ STDIN.gets.strip
320
+ end
321
+
322
+ # Do something in the root of the Rails application or
323
+ # a provided subfolder; the full path is yielded to the block you provide.
324
+ # The path is set back to the previous path when the method exits.
325
+ def inside(dir = '', &block)
326
+ folder = File.join(root, dir)
327
+ FileUtils.mkdir_p(folder) unless File.exist?(folder)
328
+ FileUtils.cd(folder) { block.arity == 1 ? yield(folder) : yield }
329
+ end
330
+
331
+ def in_root
332
+ FileUtils.cd(root) { yield }
333
+ end
334
+
335
+ # Helper to test if the user says yes(y)?
336
+ #
337
+ # ==== Example
338
+ #
339
+ # freeze! if yes?("Should I freeze the latest Rails?")
340
+ #
341
+ def yes?(question)
342
+ answer = ask(question).downcase
343
+ answer == "y" || answer == "yes"
344
+ end
345
+
346
+ # Helper to test if the user does NOT say yes(y)?
347
+ #
348
+ # ==== Example
349
+ #
350
+ # capify! if no?("Will you be using vlad to deploy your application?")
351
+ #
352
+ def no?(question)
353
+ !yes?(question)
354
+ end
355
+
356
+ # Run a regular expression replacement on a file
357
+ #
358
+ # ==== Example
359
+ #
360
+ # gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
361
+ #
362
+ def gsub_file(relative_destination, regexp, *args, &block)
363
+ path = destination_path(relative_destination)
364
+ content = File.read(path).gsub(regexp, *args, &block)
365
+ File.open(path, 'wb') { |file| file.write(content) }
366
+ end
367
+
368
+ # Append text to a file
369
+ #
370
+ # ==== Example
371
+ #
372
+ # append_file 'config/environments/test.rb', 'config.gem "rspec"'
373
+ #
374
+ def append_file(relative_destination, data)
375
+ path = destination_path(relative_destination)
376
+ File.open(path, 'ab') { |file| file.write(data) }
377
+ end
378
+
379
+ def destination_path(relative_destination)
380
+ File.join(root, relative_destination)
381
+ end
382
+
383
+ def log(action, message = '')
384
+ logger.log(action, message)
385
+ end
386
+
387
+ def logger
388
+ @logger ||= Rails::Generator::Base.logger
389
+ end
390
+
391
+ def logger
392
+ @logger ||= if defined?(Rails::Generator::Base)
393
+ Rails::Generator::Base.logger
394
+ else
395
+ require 'rails_generator/simple_logger'
396
+ Rails::Generator::SimpleLogger.new(STDOUT)
397
+ end
398
+ end
399
+
400
+ end
401
+ end