Permalink
Browse files

Add a RubyGems 1.3.2+ plugin to generate YARD documentation instead of

RDoc. Also re-enable support for `has_rdoc = false` in a gemspec.

To use YARD instead of RDoc, set `has_rdoc = 'yard'` in the gemspec
  • Loading branch information...
1 parent 5b8d227 commit f39eaa6a792a1918c373dc87512fb17d13951ecb @lsegal committed Jun 13, 2009
Showing with 104 additions and 7 deletions.
  1. +6 −2 README.markdown
  2. +87 −0 lib/rubygems_plugin.rb
  3. +11 −5 yard.gemspec
View
8 README.markdown
@@ -1,5 +1,5 @@
-YARD Release 0.2.3 (June 7th 2009)
-===================================
+YARD Release 0.2.3.1 (June 13th 2009)
+=====================================
**Homepage**: [http://yard.rubyforge.org](http://yard.rubyforge.org)
**IRC**: **Join us on IRC in #yard on irc.freenode.net!**
@@ -178,6 +178,10 @@ More options can be seen by typing `yard-graph --help`, but here is an example:
CHANGELOG
---------
+- **Jun.13.09**: 0.2.3.1 release.
+ - Add a RubyGems 1.3.2+ plugin to generate YARD documentation instead of
+ RDoc.
+
- **Jun.07.09**: 0.2.3 release. See the {file:WHATSNEW.markdown} file for a
list of important new features.
View
87 lib/rubygems_plugin.rb
@@ -0,0 +1,87 @@
+require 'rubygems/specification'
+require 'rubygems/doc_manager'
+require File.dirname(__FILE__) + '/yard' unless defined?(YARD)
+
+class Gem::Specification
+ # has_rdoc should not be ignored!
+ overwrite_accessor(:has_rdoc) { @has_rdoc }
+ overwrite_accessor(:has_rdoc=) {|v| @has_rdoc = v }
+
+ def self.has_yardoc=(value)
+ @has_rdoc = 'yard'
+ end
+
+ def has_yardoc
+ @has_rdoc == 'yard'
+ end
+
+ def has_rdoc?
+ @has_rdoc && @has_rdoc != 'yard'
+ end
+
+ alias has_yardoc? has_yardoc
+end
+
+class Gem::DocManager
+ def run_yardoc(*args)
+ args << @spec.rdoc_options
+ args << '--quiet'
+ if @spec.extra_rdoc_files.size > 0
+ args << '--files'
+ args << @spec.extra_rdoc_files.join(",")
+ end
+ args << @spec.require_paths.map {|p| p + "/**/*.rb" }
+ args = args.flatten.map do |arg| arg.to_s end
+
+ old_pwd = Dir.pwd
+ Dir.chdir(@spec.full_gem_path)
+ YARD::CLI::Yardoc.run(*args)
+ rescue Errno::EACCES => e
+ dirname = File.dirname e.message.split("-")[1].strip
+ raise Gem::FilePermissionError.new(dirname)
+ rescue RuntimeError => ex
+ alert_error "While generating documentation for #{@spec.full_name}"
+ ui.errs.puts "... MESSAGE: #{ex}"
+ ui.errs.puts "... YARDDOC args: #{args.join(' ')}"
+ ui.errs.puts "\t#{ex.backtrace.join "\n\t"}" if
+ Gem.configuration.backtrace
+ ui.errs.puts "(continuing with the rest of the installation)"
+ ensure
+ Dir.chdir(old_pwd)
+ end
+
+ def setup_rdoc
+ if File.exist?(@doc_dir) && !File.writable?(@doc_dir) then
+ raise Gem::FilePermissionError.new(@doc_dir)
+ end
+
+ FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
+
+ self.class.load_rdoc if @spec.has_rdoc?
+ end
+
+ def install_yardoc
+ rdoc_dir = File.join(@doc_dir, 'rdoc')
+
+ FileUtils.rm_rf rdoc_dir
+
+ say "Installing YARD documentation for #{@spec.full_name}..."
+ run_yardoc '-o', rdoc_dir
+ end
+
+ def install_ri_yard
+ install_ri_yard_orig if @spec.has_rdoc?
+ end
+ alias install_ri_yard_orig install_ri
+ alias install_ri install_ri_yard
+
+ def install_rdoc_yard
+ if @spec.has_rdoc?
+ install_rdoc_yard_orig
+ elsif @spec.has_yardoc?
+ install_yardoc
+ end
+ end
+ alias install_rdoc_yard_orig install_rdoc
+ alias install_rdoc install_rdoc_yard
+end
View
16 yard.gemspec
@@ -1,16 +1,22 @@
SPEC = Gem::Specification.new do |s|
s.name = "yard"
- s.version = "0.2.3"
- s.date = "2009-06-07"
+ s.summary = "Documentation tool for consistent and usable documentation in Ruby."
+ s.description = <<-eof
+ YARD is a documentation generation tool for the Ruby programming language.
+ It enables the user to generate consistent, usable documentation that can be
+ exported to a number of formats very easily, and also supports extending for
+ custom Ruby constructs such as custom class level definitions.
+ eof
+ s.version = "0.2.3.1"
+ s.date = "2009-06-13"
s.author = "Loren Segal"
s.email = "lsegal@soen.ca"
s.homepage = "http://yard.soen.ca"
s.platform = Gem::Platform::RUBY
- s.summary = "Documentation tool for consistent and usable documentation in Ruby."
- s.files = Dir.glob("{docs,bin,lib,spec,templates,benchmarks}/**/*") + ['LICENSE', 'README.markdown', 'Rakefile']
+ s.files = Dir.glob("{docs,bin,lib,spec,templates,benchmarks}/**/*") + ['LICENSE', 'README.markdown', 'Rakefile', '.yardopts']
s.require_paths = ['lib']
s.executables = [ 'yardoc', 'yri', 'yard-graph' ]
- s.has_rdoc = false
+ s.has_rdoc = 'yard'
s.rubyforge_project = 'yard'
#s.add_dependency 'tadpole'
end

0 comments on commit f39eaa6

Please sign in to comment.