* lib/rdoc/rubygems_hook.rb: Fixed generation of documentation.

Disabled rdoc generation by default to match RubyGems defaults.
  Reduced diff with RubyGems::RDoc.
* test/rdoc/test_rdoc_rubygems_hook.rb:  Tests for the above.
* test/rubygems/test_gem_rdoc.rb:  ditto.

* lib/rdoc/store.rb:  Removed useless variable assignment


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2012-12-14 05:16:56 +00:00
Родитель 1dfe3d93fa
Коммит 8adec52962
5 изменённых файлов: 75 добавлений и 28 удалений

Просмотреть файл

@ -1,3 +1,13 @@
Fri Dec 14 14:16:42 2012 Eric Hodel <drbrain@segment7.net>
* lib/rdoc/rubygems_hook.rb: Fixed generation of documentation.
Disabled rdoc generation by default to match RubyGems defaults.
Reduced diff with RubyGems::RDoc.
* test/rdoc/test_rdoc_rubygems_hook.rb: Tests for the above.
* test/rubygems/test_gem_rdoc.rb: ditto.
* lib/rdoc/store.rb: Removed useless variable assignment
Fri Dec 14 13:58:40 2012 Eric Hodel <drbrain@segment7.net> Fri Dec 14 13:58:40 2012 Eric Hodel <drbrain@segment7.net>
* lib/rubygems/commands/rdoc_command.rb: When overwriting * lib/rubygems/commands/rdoc_command.rb: When overwriting

Просмотреть файл

@ -68,10 +68,12 @@ class RDoc::RubygemsHook
## ##
# Creates a new documentation generator for +spec+. RDoc and ri data # Creates a new documentation generator for +spec+. RDoc and ri data
# generation can be disabled through +generate_rdoc+ and +generate_ri+ # generation can be enabled or disabled through +generate_rdoc+ and
# respectively. # +generate_ri+ respectively.
#
# Only +generate_ri+ is enabled by default.
def initialize spec, generate_rdoc = true, generate_ri = true def initialize spec, generate_rdoc = false, generate_ri = true
@doc_dir = spec.doc_dir @doc_dir = spec.doc_dir
@force = false @force = false
@rdoc = nil @rdoc = nil
@ -139,13 +141,11 @@ class RDoc::RubygemsHook
setup setup
options = ::RDoc::Options.new options = nil
options.default_title = "#{@spec.full_name} Documentation"
options.files = []
options.files.concat @spec.require_paths
options.files.concat @spec.extra_rdoc_files
args = @spec.rdoc_options args = @spec.rdoc_options
args.concat @spec.require_paths
args.concat @spec.extra_rdoc_files
case config_args = Gem.configuration[:rdoc] case config_args = Gem.configuration[:rdoc]
when String then when String then
@ -155,7 +155,13 @@ class RDoc::RubygemsHook
end end
delete_legacy_args args delete_legacy_args args
options.parse args
Dir.chdir @spec.full_gem_path do
options = ::RDoc::Options.new
options.default_title = "#{@spec.full_name} Documentation"
options.parse args
end
options.quiet = !Gem.configuration.really_verbose options.quiet = !Gem.configuration.really_verbose
@rdoc = new_rdoc @rdoc = new_rdoc
@ -167,7 +173,7 @@ class RDoc::RubygemsHook
store.main = options.main_page store.main = options.main_page
store.title = options.title store.title = options.title
@rdoc.store = RDoc::Store.new @rdoc.store = store
say "Parsing documentation for #{@spec.full_name}" say "Parsing documentation for #{@spec.full_name}"

Просмотреть файл

@ -596,7 +596,7 @@ class RDoc::Store
def load_class_data klass_name def load_class_data klass_name
file = class_file klass_name file = class_file klass_name
obj = open file, 'rb' do |io| open file, 'rb' do |io|
Marshal.load io.read Marshal.load io.read
end end
rescue Errno::ENOENT => e rescue Errno::ENOENT => e

Просмотреть файл

@ -10,7 +10,15 @@ class TestRDocRubygemsHook < Gem::TestCase
skip 'requires RubyGems 1.9+' unless skip 'requires RubyGems 1.9+' unless
Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.9') Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.9')
@a = quick_spec 'a' @a = quick_spec 'a' do |s|
s.rdoc_options = %w[--main MyTitle]
s.extra_rdoc_files = %w[README]
end
write_file File.join(@tempdir, 'lib', 'a.rb')
write_file File.join(@tempdir, 'README')
install_gem @a
@hook = RDoc::RubygemsHook.new @a @hook = RDoc::RubygemsHook.new @a
@ -24,7 +32,7 @@ class TestRDocRubygemsHook < Gem::TestCase
end end
def test_initialize def test_initialize
assert @hook.generate_rdoc refute @hook.generate_rdoc
assert @hook.generate_ri assert @hook.generate_ri
rdoc = RDoc::RubygemsHook.new @a, false, false rdoc = RDoc::RubygemsHook.new @a, false, false
@ -66,12 +74,37 @@ class TestRDocRubygemsHook < Gem::TestCase
@hook.generate @hook.generate
refute @hook.rdoc_installed?
assert @hook.ri_installed?
rdoc = @hook.instance_variable_get :@rdoc
refute rdoc.options.hyperlink_all
assert_equal Pathname(@a.full_gem_path), rdoc.options.root
assert_equal %w[README lib], rdoc.options.files.sort
assert_equal 'MyTitle', rdoc.store.main
end
def test_generate_all
@hook.generate_rdoc = true
@hook.generate_ri = true
FileUtils.mkdir_p @a.doc_dir
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
@hook.generate
assert @hook.rdoc_installed? assert @hook.rdoc_installed?
assert @hook.ri_installed? assert @hook.ri_installed?
rdoc = @hook.instance_variable_get :@rdoc rdoc = @hook.instance_variable_get :@rdoc
refute rdoc.options.hyperlink_all refute rdoc.options.hyperlink_all
assert_equal Pathname(@a.full_gem_path), rdoc.options.root
assert_equal %w[README lib], rdoc.options.files.sort
assert_equal 'MyTitle', rdoc.store.main
end end
def test_generate_configuration_rdoc_array def test_generate_configuration_rdoc_array
@ -133,7 +166,7 @@ class TestRDocRubygemsHook < Gem::TestCase
@hook.generate @hook.generate
assert_path_exists File.join(@a.doc_dir('rdoc'), 'index.html') refute_path_exists File.join(@a.doc_dir('rdoc'), 'index.html')
assert_path_exists File.join(@a.doc_dir('ri'), 'cache.ri') assert_path_exists File.join(@a.doc_dir('ri'), 'cache.ri')
end end
@ -183,7 +216,7 @@ class TestRDocRubygemsHook < Gem::TestCase
assert_equal @a.base_dir, e.directory assert_equal @a.base_dir, e.directory
ensure ensure
FileUtils.chmod 0755, @a.base_dir FileUtils.chmod(0755, @a.base_dir) if File.directory?(@a.base_dir)
end end
def test_ri_installed? def test_ri_installed?
@ -202,20 +235,18 @@ class TestRDocRubygemsHook < Gem::TestCase
def test_setup_unwritable def test_setup_unwritable
skip 'chmod not supported' if Gem.win_platform? skip 'chmod not supported' if Gem.win_platform?
begin FileUtils.mkdir_p @a.doc_dir
FileUtils.mkdir_p @a.doc_dir FileUtils.chmod 0, @a.doc_dir
FileUtils.chmod 0, @a.doc_dir
e = assert_raises Gem::FilePermissionError do e = assert_raises Gem::FilePermissionError do
@hook.setup @hook.setup
end end
assert_equal @a.doc_dir, e.directory assert_equal @a.doc_dir, e.directory
ensure ensure
if File.exist? @a.doc_dir if File.exist? @a.doc_dir
FileUtils.chmod 0755, @a.doc_dir FileUtils.chmod 0755, @a.doc_dir
FileUtils.rm_r @a.doc_dir FileUtils.rm_r @a.doc_dir
end
end end
end end

Просмотреть файл

@ -43,7 +43,7 @@ class TestGemRDoc < Gem::TestCase
end end
def test_initialize def test_initialize
assert @hook.generate_rdoc refute @hook.generate_rdoc
assert @hook.generate_ri assert @hook.generate_ri
rdoc = Gem::RDoc.new @a, false, false rdoc = Gem::RDoc.new @a, false, false