2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4 # See LICENSE.txt for permissions.
13 include UserInteraction
15 # Create a document manager for the given gem spec.
17 # spec:: The Gem::Specification object representing the gem.
18 # rdoc_args:: Optional arguments for RDoc (template etc.) as a String.
20 def initialize(spec, rdoc_args="")
22 @doc_dir = File.join(spec.installation_path, "doc", spec.full_name)
23 @rdoc_args = rdoc_args.nil? ? [] : rdoc_args.split
26 # Is the RDoc documentation installed?
28 return File.exist?(File.join(@doc_dir, "rdoc"))
31 # Generate the RI documents for this gem spec.
33 # Note that if both RI and RDoc documents are generated from the
34 # same process, the RI docs should be done first (a likely bug in
35 # RDoc will cause RI docs generation to fail if run after RDoc).
37 if @spec.has_rdoc then
39 install_ri # RDoc bug, ri goes first
42 FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
45 # Generate the RDoc documents for this gem spec.
47 # Note that if both RI and RDoc documents are generated from the
48 # same process, the RI docs should be done first (a likely bug in
49 # RDoc will cause RI docs generation to fail if run after RDoc).
51 if @spec.has_rdoc then
56 FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
59 # Load the RDoc documentation generator library.
61 if File.exist?(@doc_dir) && !File.writable?(@doc_dir) then
62 raise Gem::FilePermissionError.new(@doc_dir)
65 FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
76 raise Gem::DocumentError,
77 "ERROR: RDoc documentation generator not installed!"
82 rdoc_dir = File.join @doc_dir, 'rdoc'
84 FileUtils.rm_rf rdoc_dir
86 say "Installing RDoc documentation for #{@spec.full_name}..."
87 run_rdoc '--op', rdoc_dir
91 ri_dir = File.join @doc_dir, 'ri'
93 FileUtils.rm_rf ri_dir
95 say "Installing ri documentation for #{@spec.full_name}..."
96 run_rdoc '--ri', '--op', ri_dir
100 args << @spec.rdoc_options
101 args << DocManager.configured_args
103 args << @spec.require_paths.clone
104 args << @spec.extra_rdoc_files
105 args = args.flatten.map do |arg| arg.to_s end
110 Dir.chdir(@spec.full_gem_path)
113 rescue Errno::EACCES => e
114 dirname = File.dirname e.message.split("-")[1].strip
115 raise Gem::FilePermissionError.new(dirname)
116 rescue RuntimeError => ex
117 alert_error "While generating documentation for #{@spec.full_name}"
118 ui.errs.puts "... MESSAGE: #{ex}"
119 ui.errs.puts "... RDOC args: #{args.join(' ')}"
120 ui.errs.puts "\t#{ex.backtrace.join "\n\t"}" if
121 Gem.configuration.backtrace
122 ui.errs.puts "(continuing with the rest of the installation)"
129 raise Gem::FilePermissionError.new(@spec.installation_path) unless
130 File.writable? @spec.installation_path
133 @spec.name, @spec.version, @spec.original_platform].join '-'
135 doc_dir = File.join @spec.installation_path, 'doc', @spec.full_name
136 unless File.directory? doc_dir then
137 doc_dir = File.join @spec.installation_path, 'doc', original_name
140 FileUtils.rm_rf doc_dir
142 ri_dir = File.join @spec.installation_path, 'ri', @spec.full_name
144 unless File.directory? ri_dir then
145 ri_dir = File.join @spec.installation_path, 'ri', original_name
148 FileUtils.rm_rf ri_dir
153 @configured_args ||= []
156 def configured_args=(args)
159 @configured_args = args
161 @configured_args = args.split