Last active
April 2, 2020 13:29
-
-
Save thehenster/1e9e99505281fd8e5566 to your computer and use it in GitHub Desktop.
A very simple custom RDoc generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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