diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/api/task.rb | 157 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/generators/app_base.rb | 31 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/Gemfile | 5 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/config/application.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/tasks/documentation.rake | 48 |
6 files changed, 190 insertions, 58 deletions
diff --git a/railties/lib/rails/api/task.rb b/railties/lib/rails/api/task.rb new file mode 100644 index 0000000000..1e6458cf93 --- /dev/null +++ b/railties/lib/rails/api/task.rb @@ -0,0 +1,157 @@ +require 'rdoc/task' + +module Rails + module API + class Task < RDoc::Task + RDOC_FILES = { + 'activesupport' => { + :include => %w( + README.rdoc + CHANGELOG.md + lib/active_support/**/*.rb + ), + :exclude => 'lib/active_support/vendor/*' + }, + + 'activerecord' => { + :include => %w( + README.rdoc + CHANGELOG.md + lib/active_record/**/*.rb + ), + :exclude => 'lib/active_record/vendor/*' + }, + + 'activemodel' => { + :include => %w( + README.rdoc + CHANGELOG.md + lib/active_model/**/*.rb + ) + }, + + 'actionpack' => { + :include => %w( + README.rdoc + CHANGELOG.md + lib/abstract_controller/**/*.rb + lib/action_controller/**/*.rb + lib/action_dispatch/**/*.rb + lib/action_view/**/*.rb + ), + :exclude => 'lib/action_controller/vendor/*' + }, + + 'actionmailer' => { + :include => %w( + README.rdoc + CHANGELOG.md + lib/action_mailer/**/*.rb + ), + :exclude => 'lib/action_mailer/vendor/*' + }, + + 'railties' => { + :include => %w( + README.rdoc + CHANGELOG.md + MIT-LICENSE + lib/**/*.rb + ) + } + } + + def initialize(name) + super + + # Every time rake runs this task is instantiated as all the rest. + # Be lazy computing stuff to have as light impact as possible to + # the rest of tasks. + before_running_rdoc do + load_and_configure_sdoc + configure_rdoc_files + setup_horo_variables + end + end + + # Hack, ignore the desc calls performed by the original initializer. + def desc(description) + # no-op + end + + def load_and_configure_sdoc + require 'sdoc' + + self.title = 'Ruby on Rails API' + self.rdoc_dir = api_dir + + options << '-m' << api_main + options << '-e' << 'UTF-8' + + options << '-f' << 'sdoc' + options << '-T' << 'rails' + rescue LoadError + $stderr.puts %(Unable to load SDoc, please add\n\n gem 'sdoc', require: false\n\nto the Gemfile.) + exit 1 + end + + def configure_rdoc_files + rdoc_files.include(api_main) + + RDOC_FILES.each do |component, cfg| + cdr = component_root_dir(component) + + Array(cfg[:include]).each do |pattern| + rdoc_files.include("#{cdr}/#{pattern}") + end + + Array(cfg[:exclude]).each do |pattern| + rdoc_files.exclude("#{cdr}/#{pattern}") + end + end + end + + def setup_horo_variables + ENV['HORO_PROJECT_NAME'] = 'Ruby on Rails' + ENV['HORO_PROJECT_VERSION'] = rails_version + end + + def api_main + component_root_dir('railties') + '/RDOC_MAIN.rdoc' + end + end + + class RepoTask < Task + def load_and_configure_sdoc + super + options << '-g' # link to GitHub, SDoc flag + end + + def component_root_dir(component) + component + end + + def api_dir + 'doc/rdoc' + end + + def rails_version + "master@#{`git rev-parse HEAD`[0, 7]}" + end + end + + class AppTask < Task + def component_root_dir(gem_name) + $:.grep(%r{#{gem_name}[\w.-]*/lib\z}).first[0..-5] + end + + def api_dir + 'doc/api' + end + + def rails_version + Rails::VERSION::STRING + end + end + end +end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 579af8c6a5..93504b3b35 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -107,7 +107,7 @@ module Rails # # The <tt>Application</tt> class adds a couple more paths to this set. And as in your # <tt>Application</tt>, all folders under +app+ are automatically added to the load path. - # If you have an <tt>app/services/tt> folder for example, it will be added by default. + # If you have an <tt>app/services</tt> folder for example, it will be added by default. # # == Endpoint # diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 25baa470d7..8b568ff8df 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -179,16 +179,22 @@ module Rails gemfile = if options.dev? || options.edge? <<-GEMFILE.gsub(/^ {12}/, '') - # Gems used for assets + # Use edge version of sprockets-rails gem 'sprockets-rails', github: 'rails/sprockets-rails' + + # Use SCSS for stylesheets gem 'sass-rails', github: 'rails/sass-rails' - gem 'uglifier', '>= 1.0.3' + + # To use Uglifier as compressor for JavaScript assets + gem 'uglifier', '>= 1.3.0' GEMFILE else <<-GEMFILE.gsub(/^ {12}/, '') - # Gems used for assets + # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.0.beta1' - gem 'uglifier', '>= 1.0.3' + + # To use Uglifier as compressor for JavaScript assets + gem 'uglifier', '>= 1.3.0' GEMFILE end @@ -203,11 +209,19 @@ module Rails end def coffee_gemfile_entry - if options.dev? || options.edge? - "gem 'coffee-rails', github: 'rails/coffee-rails'" + gemfile = if options.dev? || options.edge? + <<-GEMFILE.gsub(/^ {12}/, '') + # Use CoffeeScript for .js.coffee assets and views + gem 'coffee-rails', github: 'rails/coffee-rails' + GEMFILE else - "gem 'coffee-rails', '~> 4.0.0.beta1'" + <<-GEMFILE.gsub(/^ {12}/, '') + # Use CoffeeScript for .js.coffee assets and views + gem 'coffee-rails', '~> 4.0.0.beta1' + GEMFILE end + + gemfile.strip_heredoc.gsub(/^[ \t]*$/, '') end def javascript_gemfile_entry @@ -215,9 +229,8 @@ module Rails unless options[:skip_javascript] <<-GEMFILE.gsub(/^ {12}/, '').strip_heredoc - #{javascript_runtime_gemfile_entry} - # Use CoffeeScript for .js.coffee assets and views #{coffee_gemfile_entry} + #{javascript_runtime_gemfile_entry} gem '#{options[:javascript]}-rails'#{args[options[:javascript]]} diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index f6bd107eba..07cf31dd83 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -9,6 +9,11 @@ source 'https://rubygems.org' <%= assets_gemfile_entry %> <%= javascript_gemfile_entry -%> +group :doc do + # bundle exec rake doc:rails generates the API under doc/api. + gem 'sdoc', require: false +end + # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 1.0.1' diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index daf399a538..ceb2bdf371 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -11,8 +11,9 @@ require "action_mailer/railtie" <%= comment_if :skip_test_unit %>require "rails/test_unit/railtie" <% end -%> -# Assets should be precompiled for production (so we don't need the gems loaded then) -Bundler.require(*Rails.groups(assets: %w(development test))) +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(:default, Rails.env) module <%= app_const_base %> class Application < Rails::Application diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake index 0057b0f887..1c3426028d 100644 --- a/railties/lib/rails/tasks/documentation.rake +++ b/railties/lib/rails/tasks/documentation.rake @@ -1,4 +1,5 @@ require 'rdoc/task' +require 'rails/api/task' # Monkey-patch to remove redoc'ing and clobber descriptions to cut down on rake -T noise class RDocTaskWithoutDescriptions < RDoc::Task @@ -52,52 +53,7 @@ namespace :doc do Rake::Task['doc:app'].comment = "Generate docs for the app -- also available doc:rails, doc:guides (options: TEMPLATE=/rdoc-template.rb, TITLE=\"Custom Title\")" # desc 'Generate documentation for the Rails framework.' - RDocTaskWithoutDescriptions.new("rails") { |rdoc| - rdoc.rdoc_dir = 'doc/api' - rdoc.template = "#{ENV['template']}.rb" if ENV['template'] - rdoc.title = "Rails Framework Documentation" - rdoc.options << '--line-numbers' - - gem_path('rails') do |rails| - rdoc.options << '-m' << "#{rails}/README.rdoc" - end - - gem_path('actionmailer') do |actionmailer| - %w(README.rdoc CHANGELOG.md MIT-LICENSE lib/action_mailer/base.rb).each do |file| - rdoc.rdoc_files.include("#{actionmailer}/#{file}") - end - end - - gem_path('actionpack') do |actionpack| - %w(README.rdoc CHANGELOG.md MIT-LICENSE lib/action_controller/**/*.rb lib/action_view/**/*.rb).each do |file| - rdoc.rdoc_files.include("#{actionpack}/#{file}") - end - end - - gem_path('activemodel') do |activemodel| - %w(README.rdoc CHANGELOG.md MIT-LICENSE lib/active_model/**/*.rb).each do |file| - rdoc.rdoc_files.include("#{activemodel}/#{file}") - end - end - - gem_path('activerecord') do |activerecord| - %w(README.rdoc CHANGELOG.md lib/active_record/**/*.rb).each do |file| - rdoc.rdoc_files.include("#{activerecord}/#{file}") - end - end - - gem_path('activesupport') do |activesupport| - %w(README.rdoc CHANGELOG.md lib/active_support/**/*.rb).each do |file| - rdoc.rdoc_files.include("#{activesupport}/#{file}") - end - end - - gem_path('railties') do |railties| - %w(README.rdoc CHANGELOG.md lib/{*.rb,commands/*.rb,generators/*.rb}).each do |file| - rdoc.rdoc_files.include("#{railties}/#{file}") - end - end - } + Rails::API::AppTask.new('rails') # desc "Generate Rails Guides" task :guides do |