railties 3.1.12 → 3.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +2292 -41
- data/README.rdoc +14 -5
- data/bin/rails +7 -0
- data/guides/code/getting_started/Gemfile +27 -0
- data/guides/code/getting_started/README.rdoc +261 -0
- data/guides/code/getting_started/Rakefile +7 -0
- data/guides/code/getting_started/app/assets/images/rails.png +0 -0
- data/guides/code/getting_started/app/assets/javascripts/application.js +9 -0
- data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/javascripts/home.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/application.css +7 -0
- data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/home.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +3 -0
- data/guides/code/getting_started/app/assets/stylesheets/scaffolds.css.scss +56 -0
- data/guides/code/getting_started/app/controllers/application_controller.rb +3 -0
- data/guides/code/getting_started/app/controllers/comments_controller.rb +16 -0
- data/guides/code/getting_started/app/controllers/home_controller.rb +5 -0
- data/guides/code/getting_started/app/controllers/posts_controller.rb +84 -0
- data/guides/code/getting_started/app/helpers/application_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/comments_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/home_helper.rb +2 -0
- data/guides/code/getting_started/app/helpers/posts_helper.rb +5 -0
- data/guides/code/getting_started/app/models/comment.rb +3 -0
- data/guides/code/getting_started/app/models/post.rb +11 -0
- data/guides/code/getting_started/app/models/tag.rb +3 -0
- data/guides/code/getting_started/app/views/comments/_comment.html.erb +15 -0
- data/guides/code/getting_started/app/views/comments/_form.html.erb +13 -0
- data/guides/code/getting_started/app/views/home/index.html.erb +2 -0
- data/guides/code/getting_started/app/views/layouts/application.html.erb +14 -0
- data/guides/code/getting_started/app/views/posts/_form.html.erb +32 -0
- data/guides/code/getting_started/app/views/posts/edit.html.erb +6 -0
- data/guides/code/getting_started/app/views/posts/index.html.erb +27 -0
- data/guides/code/getting_started/app/views/posts/new.html.erb +5 -0
- data/guides/code/getting_started/app/views/posts/show.html.erb +31 -0
- data/guides/code/getting_started/app/views/tags/_form.html.erb +12 -0
- data/guides/code/getting_started/config.ru +4 -0
- data/guides/code/getting_started/config/application.rb +53 -0
- data/guides/code/getting_started/config/boot.rb +6 -0
- data/guides/code/getting_started/config/database.yml +25 -0
- data/guides/code/getting_started/config/environment.rb +5 -0
- data/guides/code/getting_started/config/environments/development.rb +37 -0
- data/guides/code/getting_started/config/environments/production.rb +67 -0
- data/guides/code/getting_started/config/environments/test.rb +37 -0
- data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +7 -0
- data/guides/code/getting_started/config/initializers/inflections.rb +10 -0
- data/guides/code/getting_started/config/initializers/mime_types.rb +5 -0
- data/guides/code/getting_started/config/initializers/secret_token.rb +7 -0
- data/guides/code/getting_started/config/initializers/session_store.rb +8 -0
- data/guides/code/getting_started/config/initializers/wrap_parameters.rb +14 -0
- data/guides/code/getting_started/config/locales/en.yml +5 -0
- data/guides/code/getting_started/config/routes.rb +64 -0
- data/guides/code/getting_started/db/migrate/20110901012504_create_posts.rb +11 -0
- data/guides/code/getting_started/db/migrate/20110901012815_create_comments.rb +12 -0
- data/guides/code/getting_started/db/migrate/20110901013701_create_tags.rb +11 -0
- data/guides/code/getting_started/db/schema.rb +43 -0
- data/guides/code/getting_started/db/seeds.rb +7 -0
- data/guides/code/getting_started/doc/README_FOR_APP +2 -0
- data/guides/code/getting_started/public/404.html +26 -0
- data/guides/code/getting_started/public/422.html +26 -0
- data/guides/code/getting_started/public/500.html +26 -0
- data/guides/code/getting_started/public/favicon.ico +0 -0
- data/guides/code/getting_started/public/robots.txt +5 -0
- data/guides/code/getting_started/script/rails +6 -0
- data/guides/code/getting_started/test/fixtures/comments.yml +11 -0
- data/guides/code/getting_started/test/fixtures/posts.yml +11 -0
- data/guides/code/getting_started/test/fixtures/tags.yml +9 -0
- data/guides/code/getting_started/test/functional/comments_controller_test.rb +7 -0
- data/guides/code/getting_started/test/functional/home_controller_test.rb +9 -0
- data/guides/code/getting_started/test/functional/posts_controller_test.rb +49 -0
- data/guides/code/getting_started/test/performance/browsing_test.rb +12 -0
- data/guides/code/getting_started/test/test_helper.rb +13 -0
- data/guides/code/getting_started/test/unit/comment_test.rb +7 -0
- data/guides/code/getting_started/test/unit/helpers/comments_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/helpers/home_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/helpers/posts_helper_test.rb +4 -0
- data/guides/code/getting_started/test/unit/post_test.rb +7 -0
- data/guides/code/getting_started/test/unit/tag_test.rb +7 -0
- data/guides/rails_guides/generator.rb +2 -1
- data/guides/source/3_0_release_notes.textile +2 -2
- data/guides/source/3_1_release_notes.textile +3 -110
- data/guides/source/action_controller_overview.textile +11 -13
- data/guides/source/action_mailer_basics.textile +7 -18
- data/guides/source/action_view_overview.textile +78 -9
- data/guides/source/active_model_basics.textile +205 -0
- data/guides/source/active_record_basics.textile +31 -31
- data/guides/source/active_record_querying.textile +288 -67
- data/guides/source/active_record_validations_callbacks.textile +69 -75
- data/guides/source/active_resource_basics.textile +48 -2
- data/guides/source/active_support_core_extensions.textile +145 -24
- data/guides/source/ajax_on_rails.textile +65 -7
- data/guides/source/api_documentation_guidelines.textile +0 -6
- data/guides/source/asset_pipeline.textile +2 -2
- data/guides/source/association_basics.textile +25 -34
- data/guides/source/caching_with_rails.textile +12 -17
- data/guides/source/command_line.textile +29 -19
- data/guides/source/configuring.textile +40 -18
- data/guides/source/contributing_to_ruby_on_rails.textile +11 -18
- data/guides/source/debugging_rails_applications.textile +10 -21
- data/guides/source/engines.textile +618 -0
- data/guides/source/form_helpers.textile +1 -12
- data/guides/source/generators.textile +9 -11
- data/guides/source/getting_started.textile +152 -152
- data/guides/source/i18n.textile +4 -5
- data/guides/source/index.html.erb +0 -1
- data/guides/source/initialization.textile +26 -26
- data/guides/source/layouts_and_rendering.textile +97 -61
- data/guides/source/migrations.textile +380 -161
- data/guides/source/performance_testing.textile +4 -10
- data/guides/source/plugins.textile +11 -19
- data/guides/source/rails_application_templates.textile +12 -4
- data/guides/source/rails_on_rack.textile +25 -19
- data/guides/source/routing.textile +6 -13
- data/guides/source/ruby_on_rails_guides_guidelines.textile +0 -5
- data/guides/source/security.textile +11 -15
- data/guides/source/testing.textile +1 -9
- data/lib/rails/application.rb +107 -42
- data/lib/rails/application/bootstrap.rb +12 -11
- data/lib/rails/application/configuration.rb +27 -21
- data/lib/rails/application/finisher.rb +40 -17
- data/lib/rails/application/route_inspector.rb +75 -0
- data/lib/rails/application/routes_reloader.rb +15 -4
- data/lib/rails/code_statistics.rb +16 -5
- data/lib/rails/commands.rb +6 -5
- data/lib/rails/commands/application.rb +8 -1
- data/lib/rails/commands/console.rb +2 -0
- data/lib/rails/commands/dbconsole.rb +2 -2
- data/lib/rails/commands/destroy.rb +0 -2
- data/lib/rails/commands/generate.rb +3 -3
- data/lib/rails/commands/plugin.rb +161 -159
- data/lib/rails/commands/plugin_new.rb +3 -2
- data/lib/rails/commands/runner.rb +4 -0
- data/lib/rails/console/app.rb +26 -22
- data/lib/rails/console/helpers.rb +9 -5
- data/lib/rails/engine.rb +70 -34
- data/lib/rails/engine/commands.rb +39 -0
- data/lib/rails/engine/configuration.rb +1 -1
- data/lib/rails/generators.rb +3 -14
- data/lib/rails/generators/actions.rb +36 -9
- data/lib/rails/generators/app_base.rb +34 -38
- data/lib/rails/generators/base.rb +4 -4
- data/lib/rails/generators/generated_attribute.rb +1 -1
- data/lib/rails/generators/named_base.rb +1 -3
- data/lib/rails/generators/rails/app/USAGE +6 -0
- data/lib/rails/generators/rails/app/app_generator.rb +6 -2
- data/lib/rails/generators/rails/app/templates/Gemfile +4 -3
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +9 -3
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +11 -5
- data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb +11 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -6
- data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +5 -0
- data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/app/templates/public/500.html +0 -1
- data/lib/rails/generators/rails/app/templates/public/index.html +1 -1
- data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
- data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
- data/lib/rails/generators/rails/controller/templates/controller.rb +1 -1
- data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +17 -5
- data/lib/rails/generators/rails/plugin_new/templates/Rakefile +1 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/%name%/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/gitignore +4 -3
- data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +1 -1
- data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -3
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +2 -2
- data/lib/rails/generators/rails/task/USAGE +9 -0
- data/lib/rails/generators/rails/task/task_generator.rb +12 -0
- data/lib/rails/generators/rails/task/templates/task.rb +8 -0
- data/lib/rails/generators/resource_helpers.rb +3 -3
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +0 -2
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +4 -4
- data/lib/rails/paths.rb +11 -38
- data/lib/rails/rack/debugger.rb +3 -4
- data/lib/rails/rack/logger.rb +26 -12
- data/lib/rails/railtie.rb +6 -1
- data/lib/rails/railtie/configuration.rb +12 -5
- data/lib/rails/source_annotation_extractor.rb +12 -10
- data/lib/rails/tasks/documentation.rake +3 -1
- data/lib/rails/tasks/engine.rake +1 -0
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/routes.rake +3 -23
- data/lib/rails/test_help.rb +1 -2
- data/lib/rails/test_unit/testing.rake +8 -4
- data/lib/rails/version.rb +3 -3
- metadata +131 -61
- checksums.yaml +0 -7
- data/lib/rails/generators/rails/plugin/USAGE +0 -13
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +0 -54
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +0 -20
- data/lib/rails/generators/rails/plugin/templates/README.tt +0 -13
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +0 -23
- data/lib/rails/generators/rails/plugin/templates/init.rb +0 -1
- data/lib/rails/generators/rails/plugin/templates/install.rb +0 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt +0 -1
- data/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +0 -4
- data/lib/rails/generators/rails/plugin/templates/uninstall.rb +0 -1
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module Rails
|
2
|
+
module ConsoleMethods
|
3
|
+
def helper
|
4
|
+
@helper ||= ApplicationController.helpers
|
5
|
+
end
|
4
6
|
|
5
|
-
def controller
|
6
|
-
|
7
|
+
def controller
|
8
|
+
@controller ||= ApplicationController.new
|
9
|
+
end
|
10
|
+
end
|
7
11
|
end
|
data/lib/rails/engine.rb
CHANGED
@@ -228,7 +228,7 @@ module Rails
|
|
228
228
|
# resources :articles
|
229
229
|
# end
|
230
230
|
#
|
231
|
-
# The routes above will automatically point to <tt>MyEngine::
|
231
|
+
# The routes above will automatically point to <tt>MyEngine::ApplicationController</tt>. Furthermore, you don't
|
232
232
|
# need to use longer url helpers like <tt>my_engine_articles_path</tt>. Instead, you should simply use
|
233
233
|
# <tt>articles_path</tt> as you would do with your application.
|
234
234
|
#
|
@@ -296,16 +296,16 @@ module Rails
|
|
296
296
|
# If you want to share just a few specific helpers you can add them to application's
|
297
297
|
# helpers in ApplicationController:
|
298
298
|
#
|
299
|
-
#
|
300
|
-
#
|
301
|
-
#
|
299
|
+
# class ApplicationController < ActionController::Base
|
300
|
+
# helper MyEngine::SharedEngineHelper
|
301
|
+
# end
|
302
302
|
#
|
303
303
|
# If you want to include all of the engine's helpers, you can use #helpers method on an engine's
|
304
304
|
# instance:
|
305
305
|
#
|
306
|
-
#
|
307
|
-
#
|
308
|
-
#
|
306
|
+
# class ApplicationController < ActionController::Base
|
307
|
+
# helper MyEngine::Engine.helpers
|
308
|
+
# end
|
309
309
|
#
|
310
310
|
# It will include all of the helpers from engine's directory. Take into account that this does
|
311
311
|
# not include helpers defined in controllers with helper_method or other similar solutions,
|
@@ -330,10 +330,29 @@ module Rails
|
|
330
330
|
#
|
331
331
|
# MyEngine::Engine.load_seed
|
332
332
|
#
|
333
|
+
# == Loading priority
|
334
|
+
#
|
335
|
+
# In order to change engine's priority you can use config.railties_order in main application.
|
336
|
+
# It will affect the priority of loading views, helpers, assets and all the other files
|
337
|
+
# related to engine or application.
|
338
|
+
#
|
339
|
+
# Example:
|
340
|
+
#
|
341
|
+
# # load Blog::Engine with highest priority, followed by application and other railties
|
342
|
+
# config.railties_order = [Blog::Engine, :main_app, :all]
|
343
|
+
#
|
333
344
|
class Engine < Railtie
|
334
345
|
autoload :Configuration, "rails/engine/configuration"
|
335
346
|
autoload :Railties, "rails/engine/railties"
|
336
347
|
|
348
|
+
def load_generators(app=self)
|
349
|
+
initialize_generators
|
350
|
+
railties.all { |r| r.load_generators(app) }
|
351
|
+
Rails::Generators.configure!(app.config.generators)
|
352
|
+
super
|
353
|
+
self
|
354
|
+
end
|
355
|
+
|
337
356
|
class << self
|
338
357
|
attr_accessor :called_from, :isolated
|
339
358
|
alias :isolated? :isolated
|
@@ -363,20 +382,28 @@ module Rails
|
|
363
382
|
self.routes.default_scope = { :module => ActiveSupport::Inflector.underscore(mod.name) }
|
364
383
|
self.isolated = true
|
365
384
|
|
366
|
-
unless mod.respond_to?(:
|
367
|
-
name = engine_name
|
368
|
-
|
385
|
+
unless mod.respond_to?(:railtie_namespace)
|
386
|
+
name, railtie = engine_name, self
|
387
|
+
|
369
388
|
mod.singleton_class.instance_eval do
|
370
|
-
define_method(:
|
371
|
-
_railtie
|
372
|
-
end
|
389
|
+
define_method(:railtie_namespace) { railtie }
|
373
390
|
|
374
391
|
unless mod.respond_to?(:table_name_prefix)
|
375
|
-
define_method(:table_name_prefix)
|
376
|
-
|
377
|
-
|
392
|
+
define_method(:table_name_prefix) { "#{name}_" }
|
393
|
+
end
|
394
|
+
|
395
|
+
unless mod.respond_to?(:use_relative_model_naming?)
|
396
|
+
class_eval "def use_relative_model_naming?; true; end", __FILE__, __LINE__
|
378
397
|
end
|
379
|
-
|
398
|
+
|
399
|
+
unless mod.respond_to?(:railtie_helpers_paths)
|
400
|
+
define_method(:railtie_helpers_paths) { railtie.helpers_paths }
|
401
|
+
end
|
402
|
+
|
403
|
+
unless mod.respond_to?(:railtie_routes_url_helpers)
|
404
|
+
define_method(:railtie_routes_url_helpers) { railtie.routes_url_helpers }
|
405
|
+
end
|
406
|
+
end
|
380
407
|
end
|
381
408
|
end
|
382
409
|
|
@@ -397,20 +424,15 @@ module Rails
|
|
397
424
|
super
|
398
425
|
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
|
399
426
|
end
|
400
|
-
|
401
|
-
def load_generators(app=self)
|
402
|
-
railties.all { |r| r.load_generators(app) }
|
403
|
-
super
|
404
|
-
end
|
405
427
|
|
406
428
|
def load_console(app=self)
|
407
429
|
railties.all { |r| r.load_console(app) }
|
408
430
|
super
|
409
431
|
end
|
410
|
-
|
432
|
+
|
411
433
|
def eager_load!
|
412
434
|
railties.all(&:eager_load!)
|
413
|
-
|
435
|
+
|
414
436
|
config.eager_load_paths.each do |load_path|
|
415
437
|
matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
|
416
438
|
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
|
@@ -426,13 +448,6 @@ module Rails
|
|
426
448
|
def helpers
|
427
449
|
@helpers ||= begin
|
428
450
|
helpers = Module.new
|
429
|
-
|
430
|
-
helpers_paths = if config.respond_to?(:helpers_paths)
|
431
|
-
config.helpers_paths
|
432
|
-
else
|
433
|
-
paths["app/helpers"].existent
|
434
|
-
end
|
435
|
-
|
436
451
|
all = ActionController::Base.all_helpers_from_path(helpers_paths)
|
437
452
|
ActionController::Base.modules_for_helpers(all).each do |mod|
|
438
453
|
helpers.send(:include, mod)
|
@@ -441,6 +456,14 @@ module Rails
|
|
441
456
|
end
|
442
457
|
end
|
443
458
|
|
459
|
+
def helpers_paths
|
460
|
+
paths["app/helpers"].existent
|
461
|
+
end
|
462
|
+
|
463
|
+
def routes_url_helpers
|
464
|
+
routes.url_helpers
|
465
|
+
end
|
466
|
+
|
444
467
|
def app
|
445
468
|
@app ||= begin
|
446
469
|
config.middleware = config.middleware.merge_into(default_middleware_stack)
|
@@ -468,10 +491,19 @@ module Rails
|
|
468
491
|
@routes
|
469
492
|
end
|
470
493
|
|
494
|
+
def ordered_railties
|
495
|
+
railties.all + [self]
|
496
|
+
end
|
497
|
+
|
471
498
|
def initializers
|
472
499
|
initializers = []
|
473
|
-
|
474
|
-
|
500
|
+
ordered_railties.each do |r|
|
501
|
+
if r == self
|
502
|
+
initializers += super
|
503
|
+
else
|
504
|
+
initializers += r.initializers
|
505
|
+
end
|
506
|
+
end
|
475
507
|
initializers
|
476
508
|
end
|
477
509
|
|
@@ -485,7 +517,7 @@ module Rails
|
|
485
517
|
# Blog::Engine.load_seed
|
486
518
|
def load_seed
|
487
519
|
seed_file = paths["db/seeds"].existent.first
|
488
|
-
load(seed_file) if seed_file
|
520
|
+
load(seed_file) if seed_file
|
489
521
|
end
|
490
522
|
|
491
523
|
# Add configured load paths to ruby load paths and remove duplicates.
|
@@ -579,6 +611,10 @@ module Rails
|
|
579
611
|
|
580
612
|
protected
|
581
613
|
|
614
|
+
def initialize_generators
|
615
|
+
require "rails/generators"
|
616
|
+
end
|
617
|
+
|
582
618
|
def routes?
|
583
619
|
defined?(@routes)
|
584
620
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'active_support/core_ext/object/inclusion'
|
2
|
+
|
3
|
+
ARGV << '--help' if ARGV.empty?
|
4
|
+
|
5
|
+
aliases = {
|
6
|
+
"g" => "generate",
|
7
|
+
"d" => "destroy"
|
8
|
+
}
|
9
|
+
|
10
|
+
command = ARGV.shift
|
11
|
+
command = aliases[command] || command
|
12
|
+
|
13
|
+
require ENGINE_PATH
|
14
|
+
engine = ::Rails::Engine.find(ENGINE_ROOT)
|
15
|
+
|
16
|
+
case command
|
17
|
+
when 'generate', 'destroy'
|
18
|
+
require 'rails/generators'
|
19
|
+
Rails::Generators.namespace = engine.railtie_namespace
|
20
|
+
engine.load_generators
|
21
|
+
require "rails/commands/#{command}"
|
22
|
+
|
23
|
+
when '--version', '-v'
|
24
|
+
ARGV.unshift '--version'
|
25
|
+
require 'rails/commands/application'
|
26
|
+
|
27
|
+
else
|
28
|
+
puts "Error: Command not recognized" unless command.in?(['-h', '--help'])
|
29
|
+
puts <<-EOT
|
30
|
+
Usage: rails COMMAND [ARGS]
|
31
|
+
|
32
|
+
The common rails commands available for engines are:
|
33
|
+
generate Generate new code (short-cut alias: "g")
|
34
|
+
destroy Undo code generated with "generate" (short-cut alias: "d")
|
35
|
+
|
36
|
+
All commands can be run with -h for more information.
|
37
|
+
EOT
|
38
|
+
exit(1)
|
39
|
+
end
|
data/lib/rails/generators.rb
CHANGED
@@ -20,6 +20,8 @@ module Rails
|
|
20
20
|
autoload :ResourceHelpers, 'rails/generators/resource_helpers'
|
21
21
|
autoload :TestCase, 'rails/generators/test_case'
|
22
22
|
|
23
|
+
mattr_accessor :namespace
|
24
|
+
|
23
25
|
DEFAULT_ALIASES = {
|
24
26
|
:rails => {
|
25
27
|
:actions => '-a',
|
@@ -68,7 +70,7 @@ module Rails
|
|
68
70
|
}
|
69
71
|
}
|
70
72
|
|
71
|
-
def self.configure!(config
|
73
|
+
def self.configure!(config) #:nodoc:
|
72
74
|
no_color! unless config.colorize_logging
|
73
75
|
aliases.deep_merge! config.aliases
|
74
76
|
options.deep_merge! config.options
|
@@ -286,7 +288,6 @@ module Rails
|
|
286
288
|
# Receives namespaces in an array and tries to find matching generators
|
287
289
|
# in the load path.
|
288
290
|
def self.lookup(namespaces) #:nodoc:
|
289
|
-
load_generators_from_railties!
|
290
291
|
paths = namespaces_to_paths(namespaces)
|
291
292
|
|
292
293
|
paths.each do |raw_path|
|
@@ -298,9 +299,6 @@ module Rails
|
|
298
299
|
return
|
299
300
|
rescue LoadError => e
|
300
301
|
raise unless e.message =~ /#{Regexp.escape(path)}$/
|
301
|
-
rescue NameError => e
|
302
|
-
raise unless e.message =~ /Rails::Generator([\s(::)]|$)/
|
303
|
-
warn "[WARNING] Could not load generator #{path.inspect} because it's a Rails 2.x generator, which is not supported anymore. Error: #{e.message}.\n#{e.backtrace.join("\n")}"
|
304
302
|
rescue Exception => e
|
305
303
|
warn "[WARNING] Could not load generator #{path.inspect}. Error: #{e.message}.\n#{e.backtrace.join("\n")}"
|
306
304
|
end
|
@@ -310,8 +308,6 @@ module Rails
|
|
310
308
|
|
311
309
|
# This will try to load any generator in the load path to show in help.
|
312
310
|
def self.lookup! #:nodoc:
|
313
|
-
load_generators_from_railties!
|
314
|
-
|
315
311
|
$LOAD_PATH.each do |base|
|
316
312
|
Dir[File.join(base, "{rails/generators,generators}", "**", "*_generator.rb")].each do |path|
|
317
313
|
begin
|
@@ -324,13 +320,6 @@ module Rails
|
|
324
320
|
end
|
325
321
|
end
|
326
322
|
|
327
|
-
# Allow generators to be loaded from custom paths.
|
328
|
-
def self.load_generators_from_railties! #:nodoc:
|
329
|
-
return if defined?(@generators_from_railties) || Rails.application.nil?
|
330
|
-
@generators_from_railties = true
|
331
|
-
Rails.application.load_generators
|
332
|
-
end
|
333
|
-
|
334
323
|
# Convert namespaces to paths by replacing ":" for "/" and adding
|
335
324
|
# an extra lookup. For example, "rails:model" should be searched
|
336
325
|
# in both: "rails/model/model_generator" and "rails/model_generator".
|
@@ -68,7 +68,33 @@ module Rails
|
|
68
68
|
end
|
69
69
|
|
70
70
|
in_root do
|
71
|
-
|
71
|
+
str = "gem #{parts.join(", ")}"
|
72
|
+
str = " " + str if @in_group
|
73
|
+
str = "\n" + str
|
74
|
+
append_file "Gemfile", str, :verbose => false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Wraps gem entries inside a group.
|
79
|
+
#
|
80
|
+
# ==== Example
|
81
|
+
#
|
82
|
+
# gem_group :development, :test do
|
83
|
+
# gem "rspec-rails"
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
def gem_group(*names, &block)
|
87
|
+
name = names.map(&:inspect).join(", ")
|
88
|
+
log :gemfile, "group #{name}"
|
89
|
+
|
90
|
+
in_root do
|
91
|
+
append_file "Gemfile", "\ngroup #{name} do", :force => true
|
92
|
+
|
93
|
+
@in_group = true
|
94
|
+
instance_eval(&block)
|
95
|
+
@in_group = false
|
96
|
+
|
97
|
+
append_file "Gemfile", "\nend\n", :force => true
|
72
98
|
end
|
73
99
|
end
|
74
100
|
|
@@ -92,14 +118,15 @@ module Rails
|
|
92
118
|
#
|
93
119
|
def environment(data=nil, options={}, &block)
|
94
120
|
sentinel = /class [a-z_:]+ < Rails::Application/i
|
121
|
+
env_file_sentinel = /::Application\.configure do/
|
95
122
|
data = block.call if !data && block_given?
|
96
123
|
|
97
124
|
in_root do
|
98
125
|
if options[:env].nil?
|
99
|
-
inject_into_file 'config/application.rb', "\n
|
126
|
+
inject_into_file 'config/application.rb', "\n #{data}", :after => sentinel, :verbose => false
|
100
127
|
else
|
101
|
-
Array.wrap(options[:env]).each do|env|
|
102
|
-
|
128
|
+
Array.wrap(options[:env]).each do |env|
|
129
|
+
inject_into_file "config/environments/#{env}.rb", "\n #{data}", :after => env_file_sentinel, :verbose => false
|
103
130
|
end
|
104
131
|
end
|
105
132
|
end
|
@@ -114,11 +141,11 @@ module Rails
|
|
114
141
|
# git :add => "this.file that.rb"
|
115
142
|
# git :add => "onefile.rb", :rm => "badfile.cxx"
|
116
143
|
#
|
117
|
-
def git(
|
118
|
-
if
|
119
|
-
run "git #{
|
144
|
+
def git(commands={})
|
145
|
+
if commands.is_a?(Symbol)
|
146
|
+
run "git #{commands}"
|
120
147
|
else
|
121
|
-
|
148
|
+
commands.each do |cmd, options|
|
122
149
|
run "git #{cmd} #{options}"
|
123
150
|
end
|
124
151
|
end
|
@@ -226,7 +253,7 @@ module Rails
|
|
226
253
|
#
|
227
254
|
def rake(command, options={})
|
228
255
|
log :rake, command
|
229
|
-
env = options[:env] || 'development'
|
256
|
+
env = options[:env] || ENV["RAILS_ENV"] || 'development'
|
230
257
|
sudo = options[:sudo] && RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ ? 'sudo ' : ''
|
231
258
|
in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", :verbose => false) }
|
232
259
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'digest/md5'
|
2
|
-
require '
|
2
|
+
require 'securerandom'
|
3
3
|
require 'active_support/core_ext/string/strip'
|
4
4
|
require 'rails/version' unless defined?(Rails::VERSION)
|
5
5
|
require 'rbconfig'
|
@@ -138,17 +138,21 @@ module Rails
|
|
138
138
|
if options.dev?
|
139
139
|
<<-GEMFILE.strip_heredoc
|
140
140
|
gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}'
|
141
|
+
gem 'journey', :git => 'git://github.com/rails/journey.git'
|
142
|
+
gem 'arel', :git => 'git://github.com/rails/arel.git'
|
141
143
|
GEMFILE
|
142
144
|
elsif options.edge?
|
143
145
|
<<-GEMFILE.strip_heredoc
|
144
146
|
gem 'rails', :git => 'git://github.com/rails/rails.git'
|
147
|
+
gem 'journey', :git => 'git://github.com/rails/journey.git'
|
148
|
+
gem 'arel', :git => 'git://github.com/rails/arel.git'
|
145
149
|
GEMFILE
|
146
150
|
else
|
147
151
|
<<-GEMFILE.strip_heredoc
|
148
152
|
gem 'rails', '#{Rails::VERSION::STRING}'
|
149
153
|
|
150
154
|
# Bundle edge Rails instead:
|
151
|
-
# gem 'rails',
|
155
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
152
156
|
GEMFILE
|
153
157
|
end
|
154
158
|
end
|
@@ -156,11 +160,11 @@ module Rails
|
|
156
160
|
def gem_for_database
|
157
161
|
# %w( mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql )
|
158
162
|
case options[:database]
|
159
|
-
when "oracle"
|
160
|
-
when "postgresql"
|
161
|
-
when "frontbase"
|
162
|
-
when "mysql"
|
163
|
-
when "sqlserver"
|
163
|
+
when "oracle" then "ruby-oci8"
|
164
|
+
when "postgresql" then "pg"
|
165
|
+
when "frontbase" then "ruby-frontbase"
|
166
|
+
when "mysql" then "mysql2"
|
167
|
+
when "sqlserver" then "activerecord-sqlserver-adapter"
|
164
168
|
when "jdbcmysql" then "activerecord-jdbcmysql-adapter"
|
165
169
|
when "jdbcsqlite3" then "activerecord-jdbcsqlite3-adapter"
|
166
170
|
when "jdbcpostgresql" then "activerecord-jdbcpostgresql-adapter"
|
@@ -188,32 +192,32 @@ module Rails
|
|
188
192
|
end
|
189
193
|
end
|
190
194
|
|
191
|
-
def
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
195
|
+
def assets_gemfile_entry
|
196
|
+
return if options[:skip_sprockets]
|
197
|
+
|
198
|
+
gemfile = if options.dev? || options.edge?
|
199
|
+
<<-GEMFILE
|
200
|
+
# Gems used only for assets and not required
|
201
|
+
# in production environments by default.
|
202
|
+
group :assets do
|
203
|
+
gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git'
|
204
|
+
gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git'
|
205
|
+
#{"gem 'therubyrhino'\n" if defined?(JRUBY_VERSION)}
|
206
|
+
gem 'uglifier', '>= 1.0.3'
|
207
|
+
end
|
208
|
+
GEMFILE
|
209
|
+
else
|
210
|
+
<<-GEMFILE
|
211
|
+
# Gems used only for assets and not required
|
212
|
+
# in production environments by default.
|
213
|
+
group :assets do
|
214
|
+
gem 'sass-rails', '~> 3.2.0'
|
215
|
+
gem 'coffee-rails', '~> 3.2.0'
|
216
|
+
#{"gem 'therubyrhino'\n" if defined?(JRUBY_VERSION)}
|
217
|
+
gem 'uglifier', '>= 1.0.3'
|
198
218
|
end
|
199
219
|
GEMFILE
|
200
220
|
end
|
201
|
-
end
|
202
|
-
|
203
|
-
def assets_gemfile_entry
|
204
|
-
return if options[:skip_sprockets]
|
205
|
-
gemfile = <<-GEMFILE.strip_heredoc
|
206
|
-
# Gems used only for assets and not required
|
207
|
-
# in production environments by default.
|
208
|
-
group :assets do
|
209
|
-
gem 'sass-rails', #{options.dev? || options.edge? ? " :git => 'git://github.com/rails/sass-rails.git', :branch => '3-1-stable'" : " '~> 3.1.5'"}
|
210
|
-
gem 'coffee-rails', #{options.dev? || options.edge? ? ":git => 'git://github.com/rails/coffee-rails.git', :branch => '3-1-stable'" : "'~> 3.1.1'"}
|
211
|
-
|
212
|
-
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
213
|
-
#{javascript_runtime_gemfile_entry}
|
214
|
-
gem 'uglifier', '>= 1.0.3'
|
215
|
-
end
|
216
|
-
GEMFILE
|
217
221
|
|
218
222
|
gemfile.strip_heredoc.gsub(/^[ \t]*$/, '')
|
219
223
|
end
|
@@ -222,14 +226,6 @@ module Rails
|
|
222
226
|
"gem '#{options[:javascript]}-rails'" unless options[:skip_javascript]
|
223
227
|
end
|
224
228
|
|
225
|
-
def javascript_runtime_gemfile_entry
|
226
|
-
if defined?(JRUBY_VERSION)
|
227
|
-
"gem 'therubyrhino'\n"
|
228
|
-
else
|
229
|
-
"# gem 'therubyracer'\n"
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
229
|
def bundle_command(command)
|
234
230
|
say_status :run, "bundle #{command}"
|
235
231
|
|