railties 3.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (334) hide show
  1. data/CHANGELOG +2201 -0
  2. data/README +286 -0
  3. data/bin/rails +11 -0
  4. data/builtin/rails_info/rails/info.rb +147 -0
  5. data/builtin/rails_info/rails/info_controller.rb +15 -0
  6. data/builtin/rails_info/rails/info_helper.rb +2 -0
  7. data/builtin/routes.rb +3 -0
  8. data/guides/files/javascripts/code_highlighter.js +188 -0
  9. data/guides/files/javascripts/guides.js +7 -0
  10. data/guides/files/javascripts/highlighters.js +90 -0
  11. data/guides/files/stylesheets/main.css +441 -0
  12. data/guides/files/stylesheets/print.css +52 -0
  13. data/guides/files/stylesheets/reset.css +43 -0
  14. data/guides/files/stylesheets/style.css +13 -0
  15. data/guides/files/stylesheets/syntax.css +31 -0
  16. data/guides/images/belongs_to.png +0 -0
  17. data/guides/images/book_icon.gif +0 -0
  18. data/guides/images/bullet.gif +0 -0
  19. data/guides/images/chapters_icon.gif +0 -0
  20. data/guides/images/check_bullet.gif +0 -0
  21. data/guides/images/credits_pic_blank.gif +0 -0
  22. data/guides/images/csrf.png +0 -0
  23. data/guides/images/customized_error_messages.png +0 -0
  24. data/guides/images/error_messages.png +0 -0
  25. data/guides/images/feature_tile.gif +0 -0
  26. data/guides/images/footer_tile.gif +0 -0
  27. data/guides/images/fxn.png +0 -0
  28. data/guides/images/grey_bullet.gif +0 -0
  29. data/guides/images/habtm.png +0 -0
  30. data/guides/images/has_many.png +0 -0
  31. data/guides/images/has_many_through.png +0 -0
  32. data/guides/images/has_one.png +0 -0
  33. data/guides/images/has_one_through.png +0 -0
  34. data/guides/images/header_backdrop.png +0 -0
  35. data/guides/images/header_tile.gif +0 -0
  36. data/guides/images/i18n/demo_localized_pirate.png +0 -0
  37. data/guides/images/i18n/demo_translated_en.png +0 -0
  38. data/guides/images/i18n/demo_translated_pirate.png +0 -0
  39. data/guides/images/i18n/demo_translation_missing.png +0 -0
  40. data/guides/images/i18n/demo_untranslated.png +0 -0
  41. data/guides/images/icons/README +5 -0
  42. data/guides/images/icons/callouts/1.png +0 -0
  43. data/guides/images/icons/callouts/10.png +0 -0
  44. data/guides/images/icons/callouts/11.png +0 -0
  45. data/guides/images/icons/callouts/12.png +0 -0
  46. data/guides/images/icons/callouts/13.png +0 -0
  47. data/guides/images/icons/callouts/14.png +0 -0
  48. data/guides/images/icons/callouts/15.png +0 -0
  49. data/guides/images/icons/callouts/2.png +0 -0
  50. data/guides/images/icons/callouts/3.png +0 -0
  51. data/guides/images/icons/callouts/4.png +0 -0
  52. data/guides/images/icons/callouts/5.png +0 -0
  53. data/guides/images/icons/callouts/6.png +0 -0
  54. data/guides/images/icons/callouts/7.png +0 -0
  55. data/guides/images/icons/callouts/8.png +0 -0
  56. data/guides/images/icons/callouts/9.png +0 -0
  57. data/guides/images/icons/caution.png +0 -0
  58. data/guides/images/icons/example.png +0 -0
  59. data/guides/images/icons/home.png +0 -0
  60. data/guides/images/icons/important.png +0 -0
  61. data/guides/images/icons/next.png +0 -0
  62. data/guides/images/icons/note.png +0 -0
  63. data/guides/images/icons/prev.png +0 -0
  64. data/guides/images/icons/tip.png +0 -0
  65. data/guides/images/icons/up.png +0 -0
  66. data/guides/images/icons/warning.png +0 -0
  67. data/guides/images/nav_arrow.gif +0 -0
  68. data/guides/images/polymorphic.png +0 -0
  69. data/guides/images/posts_index.png +0 -0
  70. data/guides/images/rails_guides_logo.gif +0 -0
  71. data/guides/images/rails_logo_remix.gif +0 -0
  72. data/guides/images/rails_welcome.png +0 -0
  73. data/guides/images/session_fixation.png +0 -0
  74. data/guides/images/tab_grey.gif +0 -0
  75. data/guides/images/tab_info.gif +0 -0
  76. data/guides/images/tab_note.gif +0 -0
  77. data/guides/images/tab_red.gif +0 -0
  78. data/guides/images/tab_yellow.gif +0 -0
  79. data/guides/images/tab_yellow.png +0 -0
  80. data/guides/images/validation_error_messages.png +0 -0
  81. data/guides/rails_guides.rb +44 -0
  82. data/guides/rails_guides/generator.rb +178 -0
  83. data/guides/rails_guides/helpers.rb +34 -0
  84. data/guides/rails_guides/indexer.rb +55 -0
  85. data/guides/rails_guides/levenshtein.rb +31 -0
  86. data/guides/rails_guides/textile_extensions.rb +41 -0
  87. data/guides/source/2_2_release_notes.textile +422 -0
  88. data/guides/source/2_3_release_notes.textile +610 -0
  89. data/guides/source/3_0_release_notes.textile +560 -0
  90. data/guides/source/action_controller_overview.textile +783 -0
  91. data/guides/source/action_mailer_basics.textile +437 -0
  92. data/guides/source/action_view_overview.textile +1481 -0
  93. data/guides/source/active_record_basics.textile +204 -0
  94. data/guides/source/active_record_querying.textile +961 -0
  95. data/guides/source/active_support_core_extensions.textile +1835 -0
  96. data/guides/source/activerecord_validations_callbacks.textile +1127 -0
  97. data/guides/source/ajax_on_rails.textile +342 -0
  98. data/guides/source/association_basics.textile +1816 -0
  99. data/guides/source/caching_with_rails.textile +390 -0
  100. data/guides/source/command_line.textile +589 -0
  101. data/guides/source/configuring.textile +290 -0
  102. data/guides/source/contribute.textile +71 -0
  103. data/guides/source/contributing_to_rails.textile +272 -0
  104. data/guides/source/credits.textile.erb +52 -0
  105. data/guides/source/debugging_rails_applications.textile +709 -0
  106. data/guides/source/form_helpers.textile +768 -0
  107. data/guides/source/generators.textile +378 -0
  108. data/guides/source/getting_started.textile +1310 -0
  109. data/guides/source/i18n.textile +879 -0
  110. data/guides/source/index.textile.erb +124 -0
  111. data/guides/source/layout.html.erb +103 -0
  112. data/guides/source/layouts_and_rendering.textile +979 -0
  113. data/guides/source/migrations.textile +591 -0
  114. data/guides/source/nested_model_forms.textile +222 -0
  115. data/guides/source/performance_testing.textile +531 -0
  116. data/guides/source/plugins.textile +1512 -0
  117. data/guides/source/rails_application_templates.textile +238 -0
  118. data/guides/source/rails_on_rack.textile +306 -0
  119. data/guides/source/routing.textile +903 -0
  120. data/guides/source/security.textile +984 -0
  121. data/guides/source/testing.textile +946 -0
  122. data/lib/generators/erb.rb +8 -0
  123. data/lib/generators/erb/controller/controller_generator.rb +21 -0
  124. data/lib/generators/erb/controller/templates/view.html.erb +2 -0
  125. data/lib/generators/erb/mailer/mailer_generator.rb +20 -0
  126. data/lib/generators/erb/mailer/templates/view.text.erb +3 -0
  127. data/lib/generators/erb/scaffold/scaffold_generator.rb +53 -0
  128. data/lib/generators/erb/scaffold/templates/_form.html.erb +13 -0
  129. data/lib/generators/erb/scaffold/templates/edit.html.erb +6 -0
  130. data/lib/generators/erb/scaffold/templates/index.html.erb +27 -0
  131. data/lib/generators/erb/scaffold/templates/layout.html.erb +16 -0
  132. data/lib/generators/erb/scaffold/templates/new.html.erb +5 -0
  133. data/lib/generators/erb/scaffold/templates/show.html.erb +10 -0
  134. data/lib/generators/rails/app/USAGE +9 -0
  135. data/lib/generators/rails/app/app_generator.rb +262 -0
  136. data/lib/generators/rails/app/templates/Gemfile +34 -0
  137. data/lib/generators/rails/app/templates/README +243 -0
  138. data/lib/generators/rails/app/templates/Rakefile +10 -0
  139. data/lib/generators/rails/app/templates/app/controllers/application_controller.rb +3 -0
  140. data/lib/generators/rails/app/templates/app/helpers/application_helper.rb +2 -0
  141. data/lib/generators/rails/app/templates/app/models/.empty_directory +0 -0
  142. data/lib/generators/rails/app/templates/app/views/layouts/.empty_directory +0 -0
  143. data/lib/generators/rails/app/templates/config.ru +4 -0
  144. data/lib/generators/rails/app/templates/config/application.rb +51 -0
  145. data/lib/generators/rails/app/templates/config/boot.rb +17 -0
  146. data/lib/generators/rails/app/templates/config/databases/frontbase.yml +28 -0
  147. data/lib/generators/rails/app/templates/config/databases/ibm_db.yml +71 -0
  148. data/lib/generators/rails/app/templates/config/databases/mysql.yml +60 -0
  149. data/lib/generators/rails/app/templates/config/databases/oracle.yml +39 -0
  150. data/lib/generators/rails/app/templates/config/databases/postgresql.yml +51 -0
  151. data/lib/generators/rails/app/templates/config/databases/sqlite3.yml +22 -0
  152. data/lib/generators/rails/app/templates/config/environment.rb +5 -0
  153. data/lib/generators/rails/app/templates/config/environments/development.rb.tt +19 -0
  154. data/lib/generators/rails/app/templates/config/environments/production.rb.tt +33 -0
  155. data/lib/generators/rails/app/templates/config/environments/test.rb.tt +29 -0
  156. data/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb +7 -0
  157. data/lib/generators/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt +7 -0
  158. data/lib/generators/rails/app/templates/config/initializers/inflections.rb +10 -0
  159. data/lib/generators/rails/app/templates/config/initializers/mime_types.rb +5 -0
  160. data/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt +15 -0
  161. data/lib/generators/rails/app/templates/config/locales/en.yml +5 -0
  162. data/lib/generators/rails/app/templates/config/routes.rb +58 -0
  163. data/lib/generators/rails/app/templates/db/seeds.rb +7 -0
  164. data/lib/generators/rails/app/templates/doc/README_FOR_APP +2 -0
  165. data/lib/generators/rails/app/templates/gitignore +4 -0
  166. data/lib/generators/rails/app/templates/public/404.html +26 -0
  167. data/lib/generators/rails/app/templates/public/422.html +26 -0
  168. data/lib/generators/rails/app/templates/public/500.html +26 -0
  169. data/lib/generators/rails/app/templates/public/favicon.ico +0 -0
  170. data/lib/generators/rails/app/templates/public/images/rails.png +0 -0
  171. data/lib/generators/rails/app/templates/public/index.html +278 -0
  172. data/lib/generators/rails/app/templates/public/javascripts/application.js +2 -0
  173. data/lib/generators/rails/app/templates/public/javascripts/controls.js +963 -0
  174. data/lib/generators/rails/app/templates/public/javascripts/dragdrop.js +973 -0
  175. data/lib/generators/rails/app/templates/public/javascripts/effects.js +1128 -0
  176. data/lib/generators/rails/app/templates/public/javascripts/prototype.js +4320 -0
  177. data/lib/generators/rails/app/templates/public/javascripts/rails.js +110 -0
  178. data/lib/generators/rails/app/templates/public/robots.txt +5 -0
  179. data/lib/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  180. data/lib/generators/rails/app/templates/script/rails +9 -0
  181. data/lib/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  182. data/lib/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  183. data/lib/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  184. data/lib/generators/rails/app/templates/test/performance/browsing_test.rb +9 -0
  185. data/lib/generators/rails/app/templates/test/test_helper.rb +13 -0
  186. data/lib/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  187. data/lib/generators/rails/controller/USAGE +18 -0
  188. data/lib/generators/rails/controller/controller_generator.rb +14 -0
  189. data/lib/generators/rails/controller/templates/controller.rb +7 -0
  190. data/lib/generators/rails/generator/USAGE +11 -0
  191. data/lib/generators/rails/generator/generator_generator.rb +25 -0
  192. data/lib/generators/rails/generator/templates/%file_name%_generator.rb.tt +5 -0
  193. data/lib/generators/rails/generator/templates/USAGE.tt +8 -0
  194. data/lib/generators/rails/generator/templates/templates/.empty_directory +0 -0
  195. data/lib/generators/rails/helper/USAGE +17 -0
  196. data/lib/generators/rails/helper/helper_generator.rb +13 -0
  197. data/lib/generators/rails/helper/templates/helper.rb +2 -0
  198. data/lib/generators/rails/integration_test/USAGE +10 -0
  199. data/lib/generators/rails/integration_test/integration_test_generator.rb +7 -0
  200. data/lib/generators/rails/mailer/USAGE +15 -0
  201. data/lib/generators/rails/mailer/mailer_generator.rb +14 -0
  202. data/lib/generators/rails/mailer/templates/mailer.rb +16 -0
  203. data/lib/generators/rails/metal/USAGE +8 -0
  204. data/lib/generators/rails/metal/metal_generator.rb +11 -0
  205. data/lib/generators/rails/metal/templates/metal.rb +12 -0
  206. data/lib/generators/rails/migration/USAGE +29 -0
  207. data/lib/generators/rails/migration/migration_generator.rb +8 -0
  208. data/lib/generators/rails/model/USAGE +30 -0
  209. data/lib/generators/rails/model/model_generator.rb +8 -0
  210. data/lib/generators/rails/model_subclass/model_subclass_generator.rb +12 -0
  211. data/lib/generators/rails/observer/USAGE +12 -0
  212. data/lib/generators/rails/observer/observer_generator.rb +7 -0
  213. data/lib/generators/rails/performance_test/USAGE +10 -0
  214. data/lib/generators/rails/performance_test/performance_test_generator.rb +7 -0
  215. data/lib/generators/rails/plugin/USAGE +13 -0
  216. data/lib/generators/rails/plugin/plugin_generator.rb +47 -0
  217. data/lib/generators/rails/plugin/templates/MIT-LICENSE.tt +20 -0
  218. data/lib/generators/rails/plugin/templates/README.tt +13 -0
  219. data/lib/generators/rails/plugin/templates/Rakefile.tt +10 -0
  220. data/lib/generators/rails/plugin/templates/init.rb +1 -0
  221. data/lib/generators/rails/plugin/templates/install.rb +1 -0
  222. data/lib/generators/rails/plugin/templates/lib/%file_name%.rb.tt +1 -0
  223. data/lib/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +4 -0
  224. data/lib/generators/rails/plugin/templates/uninstall.rb +1 -0
  225. data/lib/generators/rails/resource/USAGE +23 -0
  226. data/lib/generators/rails/resource/resource_generator.rb +34 -0
  227. data/lib/generators/rails/scaffold/USAGE +29 -0
  228. data/lib/generators/rails/scaffold/scaffold_generator.rb +13 -0
  229. data/lib/generators/rails/scaffold_controller/USAGE +20 -0
  230. data/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb +27 -0
  231. data/lib/generators/rails/scaffold_controller/templates/controller.rb +85 -0
  232. data/lib/generators/rails/session_migration/USAGE +8 -0
  233. data/lib/generators/rails/session_migration/session_migration_generator.rb +8 -0
  234. data/lib/generators/rails/stylesheets/USAGE +5 -0
  235. data/lib/generators/rails/stylesheets/stylesheets_generator.rb +9 -0
  236. data/lib/generators/rails/stylesheets/templates/scaffold.css +61 -0
  237. data/lib/generators/test_unit.rb +8 -0
  238. data/lib/generators/test_unit/controller/controller_generator.rb +14 -0
  239. data/lib/generators/test_unit/controller/templates/functional_test.rb +8 -0
  240. data/lib/generators/test_unit/helper/helper_generator.rb +13 -0
  241. data/lib/generators/test_unit/helper/templates/helper_test.rb +4 -0
  242. data/lib/generators/test_unit/integration/integration_generator.rb +13 -0
  243. data/lib/generators/test_unit/integration/templates/integration_test.rb +10 -0
  244. data/lib/generators/test_unit/mailer/mailer_generator.rb +21 -0
  245. data/lib/generators/test_unit/mailer/templates/fixture +3 -0
  246. data/lib/generators/test_unit/mailer/templates/functional_test.rb +22 -0
  247. data/lib/generators/test_unit/model/model_generator.rb +24 -0
  248. data/lib/generators/test_unit/model/templates/fixtures.yml +23 -0
  249. data/lib/generators/test_unit/model/templates/unit_test.rb +8 -0
  250. data/lib/generators/test_unit/observer/observer_generator.rb +13 -0
  251. data/lib/generators/test_unit/observer/templates/unit_test.rb +8 -0
  252. data/lib/generators/test_unit/performance/performance_generator.rb +13 -0
  253. data/lib/generators/test_unit/performance/templates/performance_test.rb +9 -0
  254. data/lib/generators/test_unit/plugin/plugin_generator.rb +13 -0
  255. data/lib/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +8 -0
  256. data/lib/generators/test_unit/plugin/templates/test_helper.rb +3 -0
  257. data/lib/generators/test_unit/scaffold/scaffold_generator.rb +18 -0
  258. data/lib/generators/test_unit/scaffold/templates/functional_test.rb +47 -0
  259. data/lib/rails.rb +95 -0
  260. data/lib/rails/all.rb +14 -0
  261. data/lib/rails/application.rb +125 -0
  262. data/lib/rails/application/bootstrap.rb +85 -0
  263. data/lib/rails/application/configurable.rb +19 -0
  264. data/lib/rails/application/configuration.rb +86 -0
  265. data/lib/rails/application/finisher.rb +49 -0
  266. data/lib/rails/application/metal_loader.rb +50 -0
  267. data/lib/rails/application/railties.rb +31 -0
  268. data/lib/rails/application/routes_reloader.rb +46 -0
  269. data/lib/rails/backtrace_cleaner.rb +54 -0
  270. data/lib/rails/code_statistics.rb +107 -0
  271. data/lib/rails/commands.rb +72 -0
  272. data/lib/rails/commands/application.rb +13 -0
  273. data/lib/rails/commands/console.rb +55 -0
  274. data/lib/rails/commands/dbconsole.rb +104 -0
  275. data/lib/rails/commands/destroy.rb +9 -0
  276. data/lib/rails/commands/generate.rb +9 -0
  277. data/lib/rails/commands/performance/benchmarker.rb +23 -0
  278. data/lib/rails/commands/performance/profiler.rb +46 -0
  279. data/lib/rails/commands/plugin.rb +542 -0
  280. data/lib/rails/commands/runner.rb +51 -0
  281. data/lib/rails/commands/server.rb +75 -0
  282. data/lib/rails/commands/update.rb +9 -0
  283. data/lib/rails/configuration.rb +191 -0
  284. data/lib/rails/console/app.rb +33 -0
  285. data/lib/rails/console/helpers.rb +5 -0
  286. data/lib/rails/console/sandbox.rb +6 -0
  287. data/lib/rails/deprecation.rb +62 -0
  288. data/lib/rails/dispatcher.rb +24 -0
  289. data/lib/rails/engine.rb +130 -0
  290. data/lib/rails/engine/configurable.rb +25 -0
  291. data/lib/rails/engine/configuration.rb +49 -0
  292. data/lib/rails/generators.rb +289 -0
  293. data/lib/rails/generators/actions.rb +309 -0
  294. data/lib/rails/generators/active_model.rb +78 -0
  295. data/lib/rails/generators/base.rb +362 -0
  296. data/lib/rails/generators/generated_attribute.rb +48 -0
  297. data/lib/rails/generators/migration.rb +64 -0
  298. data/lib/rails/generators/named_base.rb +95 -0
  299. data/lib/rails/generators/resource_helpers.rb +80 -0
  300. data/lib/rails/generators/test_case.rb +239 -0
  301. data/lib/rails/initializable.rb +97 -0
  302. data/lib/rails/paths.rb +144 -0
  303. data/lib/rails/performance_test_help.rb +3 -0
  304. data/lib/rails/plugin.rb +64 -0
  305. data/lib/rails/rack.rb +8 -0
  306. data/lib/rails/rack/debugger.rb +23 -0
  307. data/lib/rails/rack/log_tailer.rb +33 -0
  308. data/lib/rails/rack/logger.rb +34 -0
  309. data/lib/rails/rack/static.rb +5 -0
  310. data/lib/rails/railtie.rb +74 -0
  311. data/lib/rails/railtie/configurable.rb +23 -0
  312. data/lib/rails/railtie/configuration.rb +9 -0
  313. data/lib/rails/railties_path.rb +1 -0
  314. data/lib/rails/ruby_version_check.rb +10 -0
  315. data/lib/rails/rubyprof_ext.rb +35 -0
  316. data/lib/rails/source_annotation_extractor.rb +102 -0
  317. data/lib/rails/subscriber.rb +108 -0
  318. data/lib/rails/subscriber/test_helper.rb +98 -0
  319. data/lib/rails/tasks.rb +16 -0
  320. data/lib/rails/tasks/annotations.rake +20 -0
  321. data/lib/rails/tasks/documentation.rake +96 -0
  322. data/lib/rails/tasks/framework.rake +69 -0
  323. data/lib/rails/tasks/log.rake +9 -0
  324. data/lib/rails/tasks/middleware.rake +7 -0
  325. data/lib/rails/tasks/misc.rake +71 -0
  326. data/lib/rails/tasks/routes.rake +17 -0
  327. data/lib/rails/tasks/statistics.rake +16 -0
  328. data/lib/rails/tasks/tmp.rake +37 -0
  329. data/lib/rails/test_help.rb +30 -0
  330. data/lib/rails/test_unit/railtie.rb +17 -0
  331. data/lib/rails/test_unit/testing.rake +130 -0
  332. data/lib/rails/version.rb +9 -0
  333. data/lib/rails/webrick_server.rb +156 -0
  334. metadata +427 -0
@@ -0,0 +1,9 @@
1
+ require 'rails/generators'
2
+
3
+ if ARGV.size == 0
4
+ Rails::Generators.help
5
+ exit
6
+ end
7
+
8
+ name = ARGV.shift
9
+ Rails::Generators.invoke name, ARGV, :behavior => :revoke, :destination_root => Rails.root
@@ -0,0 +1,9 @@
1
+ require 'rails/generators'
2
+
3
+ if ARGV.size == 0
4
+ Rails::Generators.help
5
+ exit
6
+ end
7
+
8
+ name = ARGV.shift
9
+ Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => Rails.root
@@ -0,0 +1,23 @@
1
+ if ARGV.empty?
2
+ puts "Usage: benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ..."
3
+ exit 1
4
+ end
5
+
6
+ begin
7
+ N = Integer(ARGV.first)
8
+ ARGV.shift
9
+ rescue ArgumentError
10
+ N = 1
11
+ end
12
+
13
+ require 'benchmark'
14
+ include Benchmark
15
+
16
+ # Don't include compilation in the benchmark
17
+ ARGV.each { |expression| eval(expression) }
18
+
19
+ bm(6) do |x|
20
+ ARGV.each_with_index do |expression, idx|
21
+ x.report("##{idx + 1}") { N.times { eval(expression) } }
22
+ end
23
+ end
@@ -0,0 +1,46 @@
1
+ if ARGV.empty?
2
+ $stderr.puts "Usage: profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]"
3
+ exit(1)
4
+ end
5
+
6
+ # Define a method to profile.
7
+ if ARGV[1] and ARGV[1].to_i > 1
8
+ eval "def profile_me() #{ARGV[1]}.times { #{ARGV[0]} } end"
9
+ else
10
+ eval "def profile_me() #{ARGV[0]} end"
11
+ end
12
+
13
+ # Use the ruby-prof extension if available. Fall back to stdlib profiler.
14
+ begin
15
+ begin
16
+ require "ruby-prof"
17
+ $stderr.puts 'Using the ruby-prof extension.'
18
+ RubyProf.measure_mode = RubyProf::WALL_TIME
19
+ RubyProf.start
20
+ profile_me
21
+ results = RubyProf.stop
22
+ if ARGV[2]
23
+ printer_class = RubyProf.const_get((ARGV[2] + "_printer").classify)
24
+ else
25
+ printer_class = RubyProf::FlatPrinter
26
+ end
27
+ printer = printer_class.new(results)
28
+ printer.print($stderr)
29
+ rescue LoadError
30
+ require "prof"
31
+ $stderr.puts 'Using the old ruby-prof extension.'
32
+ Prof.clock_mode = Prof::GETTIMEOFDAY
33
+ Prof.start
34
+ profile_me
35
+ results = Prof.stop
36
+ require 'rubyprof_ext'
37
+ Prof.print_profile(results, $stderr)
38
+ end
39
+ rescue LoadError
40
+ require 'profiler'
41
+ $stderr.puts 'Using the standard Ruby profiler.'
42
+ Profiler__.start_profile
43
+ profile_me
44
+ Profiler__.stop_profile
45
+ Profiler__.print_profile($stderr)
46
+ end
@@ -0,0 +1,542 @@
1
+ # Rails Plugin Manager.
2
+ #
3
+ # Installing plugins:
4
+ #
5
+ # $ ./script/plugin install continuous_builder asset_timestamping
6
+ #
7
+ # Specifying revisions:
8
+ #
9
+ # * Subversion revision is a single integer.
10
+ #
11
+ # * Git revision format:
12
+ # - full - 'refs/tags/1.8.0' or 'refs/heads/experimental'
13
+ # - short: 'experimental' (equivalent to 'refs/heads/experimental')
14
+ # 'tag 1.8.0' (equivalent to 'refs/tags/1.8.0')
15
+ #
16
+ #
17
+ # This is Free Software, copyright 2005 by Ryan Tomayko (rtomayko@gmail.com)
18
+ # and is licensed MIT: (http://www.opensource.org/licenses/mit-license.php)
19
+
20
+ $verbose = false
21
+
22
+
23
+ require 'open-uri'
24
+ require 'fileutils'
25
+ require 'tempfile'
26
+
27
+ include FileUtils
28
+
29
+ class RailsEnvironment
30
+ attr_reader :root
31
+
32
+ def initialize(dir)
33
+ @root = dir
34
+ end
35
+
36
+ def self.find(dir=nil)
37
+ dir ||= pwd
38
+ while dir.length > 1
39
+ return new(dir) if File.exist?(File.join(dir, 'config', 'environment.rb'))
40
+ dir = File.dirname(dir)
41
+ end
42
+ end
43
+
44
+ def self.default
45
+ @default ||= find
46
+ end
47
+
48
+ def self.default=(rails_env)
49
+ @default = rails_env
50
+ end
51
+
52
+ def install(name_uri_or_plugin)
53
+ if name_uri_or_plugin.is_a? String
54
+ if name_uri_or_plugin =~ /:\/\//
55
+ plugin = Plugin.new(name_uri_or_plugin)
56
+ else
57
+ plugin = Plugins[name_uri_or_plugin]
58
+ end
59
+ else
60
+ plugin = name_uri_or_plugin
61
+ end
62
+ unless plugin.nil?
63
+ plugin.install
64
+ else
65
+ puts "Plugin not found: #{name_uri_or_plugin}"
66
+ end
67
+ end
68
+
69
+ def use_svn?
70
+ require 'active_support/core_ext/kernel'
71
+ silence_stderr {`svn --version` rescue nil}
72
+ !$?.nil? && $?.success?
73
+ end
74
+
75
+ def use_externals?
76
+ use_svn? && File.directory?("#{root}/vendor/plugins/.svn")
77
+ end
78
+
79
+ def use_checkout?
80
+ # this is a bit of a guess. we assume that if the rails environment
81
+ # is under subversion then they probably want the plugin checked out
82
+ # instead of exported. This can be overridden on the command line
83
+ File.directory?("#{root}/.svn")
84
+ end
85
+
86
+ def best_install_method
87
+ return :http unless use_svn?
88
+ case
89
+ when use_externals? then :externals
90
+ when use_checkout? then :checkout
91
+ else :export
92
+ end
93
+ end
94
+
95
+ def externals
96
+ return [] unless use_externals?
97
+ ext = `svn propget svn:externals "#{root}/vendor/plugins"`
98
+ lines = ext.respond_to?(:lines) ? ext.lines : ext
99
+ lines.reject{ |line| line.strip == '' }.map do |line|
100
+ line.strip.split(/\s+/, 2)
101
+ end
102
+ end
103
+
104
+ def externals=(items)
105
+ unless items.is_a? String
106
+ items = items.map{|name,uri| "#{name.ljust(29)} #{uri.chomp('/')}"}.join("\n")
107
+ end
108
+ Tempfile.open("svn-set-prop") do |file|
109
+ file.write(items)
110
+ file.flush
111
+ system("svn propset -q svn:externals -F \"#{file.path}\" \"#{root}/vendor/plugins\"")
112
+ end
113
+ end
114
+
115
+ end
116
+
117
+ class Plugin
118
+ attr_reader :name, :uri
119
+
120
+ def initialize(uri, name = nil)
121
+ @uri = uri
122
+ guess_name(uri)
123
+ end
124
+
125
+ def self.find(name)
126
+ new(name)
127
+ end
128
+
129
+ def to_s
130
+ "#{@name.ljust(30)}#{@uri}"
131
+ end
132
+
133
+ def svn_url?
134
+ @uri =~ /svn(?:\+ssh)?:\/\/*/
135
+ end
136
+
137
+ def git_url?
138
+ @uri =~ /^git:\/\// || @uri =~ /\.git$/
139
+ end
140
+
141
+ def installed?
142
+ File.directory?("#{rails_env.root}/vendor/plugins/#{name}") \
143
+ or rails_env.externals.detect{ |name, repo| self.uri == repo }
144
+ end
145
+
146
+ def install(method=nil, options = {})
147
+ method ||= rails_env.best_install_method?
148
+ if :http == method
149
+ method = :export if svn_url?
150
+ method = :git if git_url?
151
+ end
152
+
153
+ uninstall if installed? and options[:force]
154
+
155
+ unless installed?
156
+ send("install_using_#{method}", options)
157
+ run_install_hook
158
+ else
159
+ puts "already installed: #{name} (#{uri}). pass --force to reinstall"
160
+ end
161
+ end
162
+
163
+ def uninstall
164
+ path = "#{rails_env.root}/vendor/plugins/#{name}"
165
+ if File.directory?(path)
166
+ puts "Removing 'vendor/plugins/#{name}'" if $verbose
167
+ run_uninstall_hook
168
+ rm_r path
169
+ else
170
+ puts "Plugin doesn't exist: #{path}"
171
+ end
172
+
173
+ if rails_env.use_externals?
174
+ # clean up svn:externals
175
+ externals = rails_env.externals
176
+ externals.reject!{|n,u| name == n or name == u}
177
+ rails_env.externals = externals
178
+ end
179
+ end
180
+
181
+ def info
182
+ tmp = "#{rails_env.root}/_tmp_about.yml"
183
+ if svn_url?
184
+ cmd = "svn export #{@uri} \"#{rails_env.root}/#{tmp}\""
185
+ puts cmd if $verbose
186
+ system(cmd)
187
+ end
188
+ open(svn_url? ? tmp : File.join(@uri, 'about.yml')) do |stream|
189
+ stream.read
190
+ end rescue "No about.yml found in #{uri}"
191
+ ensure
192
+ FileUtils.rm_rf tmp if svn_url?
193
+ end
194
+
195
+ private
196
+
197
+ def run_install_hook
198
+ install_hook_file = "#{rails_env.root}/vendor/plugins/#{name}/install.rb"
199
+ load install_hook_file if File.exist? install_hook_file
200
+ end
201
+
202
+ def run_uninstall_hook
203
+ uninstall_hook_file = "#{rails_env.root}/vendor/plugins/#{name}/uninstall.rb"
204
+ load uninstall_hook_file if File.exist? uninstall_hook_file
205
+ end
206
+
207
+ def install_using_export(options = {})
208
+ svn_command :export, options
209
+ end
210
+
211
+ def install_using_checkout(options = {})
212
+ svn_command :checkout, options
213
+ end
214
+
215
+ def install_using_externals(options = {})
216
+ externals = rails_env.externals
217
+ externals.push([@name, uri])
218
+ rails_env.externals = externals
219
+ install_using_checkout(options)
220
+ end
221
+
222
+ def install_using_http(options = {})
223
+ root = rails_env.root
224
+ mkdir_p "#{root}/vendor/plugins/#{@name}"
225
+ Dir.chdir "#{root}/vendor/plugins/#{@name}" do
226
+ puts "fetching from '#{uri}'" if $verbose
227
+ fetcher = RecursiveHTTPFetcher.new(uri, -1)
228
+ fetcher.quiet = true if options[:quiet]
229
+ fetcher.fetch
230
+ end
231
+ end
232
+
233
+ def install_using_git(options = {})
234
+ root = rails_env.root
235
+ mkdir_p(install_path = "#{root}/vendor/plugins/#{name}")
236
+ Dir.chdir install_path do
237
+ init_cmd = "git init"
238
+ init_cmd += " -q" if options[:quiet] and not $verbose
239
+ puts init_cmd if $verbose
240
+ system(init_cmd)
241
+ base_cmd = "git pull --depth 1 #{uri}"
242
+ base_cmd += " -q" if options[:quiet] and not $verbose
243
+ base_cmd += " #{options[:revision]}" if options[:revision]
244
+ puts base_cmd if $verbose
245
+ if system(base_cmd)
246
+ puts "removing: .git .gitignore" if $verbose
247
+ rm_rf %w(.git .gitignore)
248
+ else
249
+ rm_rf install_path
250
+ end
251
+ end
252
+ end
253
+
254
+ def svn_command(cmd, options = {})
255
+ root = rails_env.root
256
+ mkdir_p "#{root}/vendor/plugins"
257
+ base_cmd = "svn #{cmd} #{uri} \"#{root}/vendor/plugins/#{name}\""
258
+ base_cmd += ' -q' if options[:quiet] and not $verbose
259
+ base_cmd += " -r #{options[:revision]}" if options[:revision]
260
+ puts base_cmd if $verbose
261
+ system(base_cmd)
262
+ end
263
+
264
+ def guess_name(url)
265
+ @name = File.basename(url)
266
+ if @name == 'trunk' || @name.empty?
267
+ @name = File.basename(File.dirname(url))
268
+ end
269
+ @name.gsub!(/\.git$/, '') if @name =~ /\.git$/
270
+ end
271
+
272
+ def rails_env
273
+ @rails_env || RailsEnvironment.default
274
+ end
275
+ end
276
+
277
+ # load default environment and parse arguments
278
+ require 'optparse'
279
+ module Commands
280
+
281
+ class Plugin
282
+ attr_reader :environment, :script_name, :sources
283
+ def initialize
284
+ @environment = RailsEnvironment.default
285
+ @rails_root = RailsEnvironment.default.root
286
+ @script_name = File.basename($0)
287
+ @sources = []
288
+ end
289
+
290
+ def environment=(value)
291
+ @environment = value
292
+ RailsEnvironment.default = value
293
+ end
294
+
295
+ def options
296
+ OptionParser.new do |o|
297
+ o.set_summary_indent(' ')
298
+ o.banner = "Usage: plugin [OPTIONS] command"
299
+ o.define_head "Rails plugin manager."
300
+
301
+ o.separator ""
302
+ o.separator "GENERAL OPTIONS"
303
+
304
+ o.on("-r", "--root=DIR", String,
305
+ "Set an explicit rails app directory.",
306
+ "Default: #{@rails_root}") { |rails_root| @rails_root = rails_root; self.environment = RailsEnvironment.new(@rails_root) }
307
+ o.on("-s", "--source=URL1,URL2", Array,
308
+ "Use the specified plugin repositories instead of the defaults.") { |sources| @sources = sources}
309
+
310
+ o.on("-v", "--verbose", "Turn on verbose output.") { |verbose| $verbose = verbose }
311
+ o.on("-h", "--help", "Show this help message.") { puts o; exit }
312
+
313
+ o.separator ""
314
+ o.separator "COMMANDS"
315
+
316
+ o.separator " install Install plugin(s) from known repositories or URLs."
317
+ o.separator " remove Uninstall plugins."
318
+
319
+ o.separator ""
320
+ o.separator "EXAMPLES"
321
+ o.separator " Install a plugin:"
322
+ o.separator " #{@script_name} install continuous_builder\n"
323
+ o.separator " Install a plugin from a subversion URL:"
324
+ o.separator " #{@script_name} install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder\n"
325
+ o.separator " Install a plugin from a git URL:"
326
+ o.separator " #{@script_name} install git://github.com/SomeGuy/my_awesome_plugin.git\n"
327
+ o.separator " Install a plugin and add a svn:externals entry to vendor/plugins"
328
+ o.separator " #{@script_name} install -x continuous_builder\n"
329
+ end
330
+ end
331
+
332
+ def parse!(args=ARGV)
333
+ general, sub = split_args(args)
334
+ options.parse!(general)
335
+
336
+ command = general.shift
337
+ if command =~ /^(install|remove)$/
338
+ command = Commands.const_get(command.capitalize).new(self)
339
+ command.parse!(sub)
340
+ else
341
+ puts "Unknown command: #{command}"
342
+ puts options
343
+ exit 1
344
+ end
345
+ end
346
+
347
+ def split_args(args)
348
+ left = []
349
+ left << args.shift while args[0] and args[0] =~ /^-/
350
+ left << args.shift if args[0]
351
+ return [left, args]
352
+ end
353
+
354
+ def self.parse!(args=ARGV)
355
+ Plugin.new.parse!(args)
356
+ end
357
+ end
358
+
359
+ class Install
360
+ def initialize(base_command)
361
+ @base_command = base_command
362
+ @method = :http
363
+ @options = { :quiet => false, :revision => nil, :force => false }
364
+ end
365
+
366
+ def options
367
+ OptionParser.new do |o|
368
+ o.set_summary_indent(' ')
369
+ o.banner = "Usage: #{@base_command.script_name} install PLUGIN [PLUGIN [PLUGIN] ...]"
370
+ o.define_head "Install one or more plugins."
371
+ o.separator ""
372
+ o.separator "Options:"
373
+ o.on( "-x", "--externals",
374
+ "Use svn:externals to grab the plugin.",
375
+ "Enables plugin updates and plugin versioning.") { |v| @method = :externals }
376
+ o.on( "-o", "--checkout",
377
+ "Use svn checkout to grab the plugin.",
378
+ "Enables updating but does not add a svn:externals entry.") { |v| @method = :checkout }
379
+ o.on( "-e", "--export",
380
+ "Use svn export to grab the plugin.",
381
+ "Exports the plugin, allowing you to check it into your local repository. Does not enable updates, or add an svn:externals entry.") { |v| @method = :export }
382
+ o.on( "-q", "--quiet",
383
+ "Suppresses the output from installation.",
384
+ "Ignored if -v is passed (./script/plugin -v install ...)") { |v| @options[:quiet] = true }
385
+ o.on( "-r REVISION", "--revision REVISION",
386
+ "Checks out the given revision from subversion or git.",
387
+ "Ignored if subversion/git is not used.") { |v| @options[:revision] = v }
388
+ o.on( "-f", "--force",
389
+ "Reinstalls a plugin if it's already installed.") { |v| @options[:force] = true }
390
+ o.separator ""
391
+ o.separator "You can specify plugin names as given in 'plugin list' output or absolute URLs to "
392
+ o.separator "a plugin repository."
393
+ end
394
+ end
395
+
396
+ def determine_install_method
397
+ best = @base_command.environment.best_install_method
398
+ @method = :http if best == :http and @method == :export
399
+ case
400
+ when (best == :http and @method != :http)
401
+ msg = "Cannot install using subversion because `svn' cannot be found in your PATH"
402
+ when (best == :export and (@method != :export and @method != :http))
403
+ msg = "Cannot install using #{@method} because this project is not under subversion."
404
+ when (best != :externals and @method == :externals)
405
+ msg = "Cannot install using externals because vendor/plugins is not under subversion."
406
+ end
407
+ if msg
408
+ puts msg
409
+ exit 1
410
+ end
411
+ @method
412
+ end
413
+
414
+ def parse!(args)
415
+ options.parse!(args)
416
+ environment = @base_command.environment
417
+ install_method = determine_install_method
418
+ puts "Plugins will be installed using #{install_method}" if $verbose
419
+ args.each do |name|
420
+ ::Plugin.find(name).install(install_method, @options)
421
+ end
422
+ rescue StandardError => e
423
+ puts "Plugin not found: #{args.inspect}"
424
+ puts e.inspect if $verbose
425
+ exit 1
426
+ end
427
+ end
428
+
429
+ class Remove
430
+ def initialize(base_command)
431
+ @base_command = base_command
432
+ end
433
+
434
+ def options
435
+ OptionParser.new do |o|
436
+ o.set_summary_indent(' ')
437
+ o.banner = "Usage: #{@base_command.script_name} remove name [name]..."
438
+ o.define_head "Remove plugins."
439
+ end
440
+ end
441
+
442
+ def parse!(args)
443
+ options.parse!(args)
444
+ root = @base_command.environment.root
445
+ args.each do |name|
446
+ ::Plugin.new(name).uninstall
447
+ end
448
+ end
449
+ end
450
+
451
+ class Info
452
+ def initialize(base_command)
453
+ @base_command = base_command
454
+ end
455
+
456
+ def options
457
+ OptionParser.new do |o|
458
+ o.set_summary_indent(' ')
459
+ o.banner = "Usage: #{@base_command.script_name} info name [name]..."
460
+ o.define_head "Shows plugin info at {url}/about.yml."
461
+ end
462
+ end
463
+
464
+ def parse!(args)
465
+ options.parse!(args)
466
+ args.each do |name|
467
+ puts ::Plugin.find(name).info
468
+ puts
469
+ end
470
+ end
471
+ end
472
+ end
473
+
474
+ class RecursiveHTTPFetcher
475
+ attr_accessor :quiet
476
+ def initialize(urls_to_fetch, level = 1, cwd = ".")
477
+ @level = level
478
+ @cwd = cwd
479
+ @urls_to_fetch = RUBY_VERSION >= '1.9' ? urls_to_fetch.lines : urls_to_fetch.to_a
480
+ @quiet = false
481
+ end
482
+
483
+ def ls
484
+ @urls_to_fetch.collect do |url|
485
+ if url =~ /^svn(\+ssh)?:\/\/.*/
486
+ `svn ls #{url}`.split("\n").map {|entry| "/#{entry}"} rescue nil
487
+ else
488
+ open(url) do |stream|
489
+ links("", stream.read)
490
+ end rescue nil
491
+ end
492
+ end.flatten
493
+ end
494
+
495
+ def push_d(dir)
496
+ @cwd = File.join(@cwd, dir)
497
+ FileUtils.mkdir_p(@cwd)
498
+ end
499
+
500
+ def pop_d
501
+ @cwd = File.dirname(@cwd)
502
+ end
503
+
504
+ def links(base_url, contents)
505
+ links = []
506
+ contents.scan(/href\s*=\s*\"*[^\">]*/i) do |link|
507
+ link = link.sub(/href="/i, "")
508
+ next if link =~ /svnindex.xsl$/
509
+ next if link =~ /^(\w*:|)\/\// || link =~ /^\./
510
+ links << File.join(base_url, link)
511
+ end
512
+ links
513
+ end
514
+
515
+ def download(link)
516
+ puts "+ #{File.join(@cwd, File.basename(link))}" unless @quiet
517
+ open(link) do |stream|
518
+ File.open(File.join(@cwd, File.basename(link)), "wb") do |file|
519
+ file.write(stream.read)
520
+ end
521
+ end
522
+ end
523
+
524
+ def fetch(links = @urls_to_fetch)
525
+ links.each do |l|
526
+ (l =~ /\/$/ || links == @urls_to_fetch) ? fetch_dir(l) : download(l)
527
+ end
528
+ end
529
+
530
+ def fetch_dir(url)
531
+ @level += 1
532
+ push_d(File.basename(url)) if @level > 0
533
+ open(url) do |stream|
534
+ contents = stream.read
535
+ fetch(links(url, contents))
536
+ end
537
+ pop_d if @level > 0
538
+ @level -= 1
539
+ end
540
+ end
541
+
542
+ Commands::Plugin.parse!