Skip to content

Instantly share code, notes, and snippets.

@thehenster
Last active April 2, 2020 13:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thehenster/1e9e99505281fd8e5566 to your computer and use it in GitHub Desktop.
Save thehenster/1e9e99505281fd8e5566 to your computer and use it in GitHub Desktop.
A very simple custom RDoc generator
# RDoc can use a custom generator but it isn't that well documentated. Here is a
# sample custom generator to get you going.
#
# Ruby comes with an `rdoc` executable but most of us generate our docs via Rake. To
# use your custom generator with Rake do something like the following in your Rakefile..
#
# require 'rdoc/task'
# require 'simple_rdoc'
#
# RDoc::Task.new('simple_doc') do |i|
# i.generator = 'simple'
# end
#
# And run it with..
#
# rake simple_doc
#
require 'rdoc'
require 'erb'
module RDoc
module Generator
class Simple
::RDoc::RDoc.add_generator self
def initialize(store, options)
@store = store
@options = options
end
def generate
# @store contains the parsed rdoc tree. As well as #all_classes_and_modules
# there are other ways to dip into the tree in https://github.com/rdoc/rdoc/blob/master/lib/rdoc/store.rb
@methods = @store.all_classes_and_modules.uniq.map(&:method_list).flatten
File.open('index.html', 'w') do |file|
file << ERB.new(File.read(template_path)).result(binding)
end
end
# when processing the markup it expects to find these methods
def class_dir; nil; end
def file_dir; nil; end
private
def template_path
File.join(File.dirname(__FILE__), 'simple.html.erb')
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment