Skip to content

Commit

Permalink
let rake tasks be robust to a missing RDoc in Rubinius [Fixes #10462]
Browse files Browse the repository at this point in the history
See the comment in the rescue clause towards the top of the patch for the rationale.
  • Loading branch information
fxn committed May 6, 2013
1 parent 3d5b259 commit eba5a32
Showing 1 changed file with 56 additions and 45 deletions.
101 changes: 56 additions & 45 deletions railties/lib/rails/tasks/documentation.rake
@@ -1,61 +1,72 @@
require 'rdoc/task' begin
require 'rails/api/task' require 'rdoc/task'
rescue LoadError
# Rubinius installs RDoc as a gem, and for this interpreter "rdoc/task" is
# available only if the application bundle includes "rdoc" (normally as a
# dependency of the "sdoc" gem.)
#
# If RDoc is not available it is fine that we do not generate the tasks that
# depend on it. Just be robust to this gotcha and go on.
else
require 'rails/api/task'


# Monkey-patch to remove redoc'ing and clobber descriptions to cut down on rake -T noise # Monkey-patch to remove redoc'ing and clobber descriptions to cut down on rake -T noise
class RDocTaskWithoutDescriptions < RDoc::Task class RDocTaskWithoutDescriptions < RDoc::Task
include ::Rake::DSL include ::Rake::DSL


def define def define
task rdoc_task_name task rdoc_task_name


task rerdoc_task_name => [clobber_task_name, rdoc_task_name] task rerdoc_task_name => [clobber_task_name, rdoc_task_name]


task clobber_task_name do task clobber_task_name do
rm_r rdoc_dir rescue nil rm_r rdoc_dir rescue nil
end end


task :clobber => [clobber_task_name] task :clobber => [clobber_task_name]


directory @rdoc_dir directory @rdoc_dir
task rdoc_task_name => [rdoc_target] task rdoc_task_name => [rdoc_target]
file rdoc_target => @rdoc_files + [Rake.application.rakefile] do file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
rm_r @rdoc_dir rescue nil rm_r @rdoc_dir rescue nil
@before_running_rdoc.call if @before_running_rdoc @before_running_rdoc.call if @before_running_rdoc
args = option_list + @rdoc_files args = option_list + @rdoc_files
if @external if @external
argstring = args.join(' ') argstring = args.join(' ')
sh %{ruby -Ivendor vendor/rd #{argstring}} sh %{ruby -Ivendor vendor/rd #{argstring}}
else else
require 'rdoc/rdoc' require 'rdoc/rdoc'
RDoc::RDoc.new.document(args) RDoc::RDoc.new.document(args)
end
end end
self
end end
self
end end
end


namespace :doc do namespace :doc do
def gem_path(gem_name) def gem_path(gem_name)
path = $LOAD_PATH.grep(/#{gem_name}[\w.-]*\/lib$/).first path = $LOAD_PATH.grep(/#{gem_name}[\w.-]*\/lib$/).first
yield File.dirname(path) if path yield File.dirname(path) if path
end end


RDocTaskWithoutDescriptions.new("app") { |rdoc| RDocTaskWithoutDescriptions.new("app") { |rdoc|
rdoc.rdoc_dir = 'doc/app' rdoc.rdoc_dir = 'doc/app'
rdoc.template = ENV['template'] if ENV['template'] rdoc.template = ENV['template'] if ENV['template']
rdoc.title = ENV['title'] || "Rails Application Documentation" rdoc.title = ENV['title'] || "Rails Application Documentation"
rdoc.options << '--line-numbers' rdoc.options << '--line-numbers'
rdoc.options << '--charset' << 'utf-8' rdoc.options << '--charset' << 'utf-8'
rdoc.rdoc_files.include('README.rdoc') rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('app/**/*.rb') rdoc.rdoc_files.include('app/**/*.rb')
rdoc.rdoc_files.include('lib/**/*.rb') rdoc.rdoc_files.include('lib/**/*.rb')
} }
Rake::Task['doc:app'].comment = "Generate docs for the app -- also available doc:rails, doc:guides (options: TEMPLATE=/rdoc-template.rb, TITLE=\"Custom Title\")" 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.' # desc 'Generate documentation for the Rails framework.'
Rails::API::AppTask.new('rails') Rails::API::AppTask.new('rails')
end
end


# desc "Generate Rails Guides" namespace :doc do
task :guides do task :guides do
# FIXME: Reaching outside lib directory is a bad idea # FIXME: Reaching outside lib directory is a bad idea
require File.expand_path('../../../../../guides/rails_guides', __FILE__) require File.expand_path('../../../../../guides/rails_guides', __FILE__)
Expand Down

0 comments on commit eba5a32

Please sign in to comment.