Skip to content

Commit

Permalink
Combine the docs into a single template/formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr committed Aug 3, 2009
1 parent 8582789 commit d81b7a8
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 166 deletions.
44 changes: 5 additions & 39 deletions Rakefile
Expand Up @@ -16,10 +16,7 @@ REV = `#{GIT} rev-list HEAD`.strip.split.length
VERS = ENV['VERSION'] || (REV.zero? ? BRANCH : [BRANCH, REV] * '.')

CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'test/test.log', '.*.pt']
RDOC_OPTS = ['--title', "Camping, a Microframework",
"--line-numbers",
"--quiet",
"--main", "README"]
RDOC_OPTS = ["--line-numbers", "--quiet", "--main", "README"]

## Packaging
spec =
Expand Down Expand Up @@ -73,10 +70,9 @@ require 'rdoc'

if defined?(RDoc::VERSION) && RDoc::VERSION[0,3] == "2.4"
require 'rdoc/generator/singledarkfish'
require 'rdoc/generator/book'
require 'rdoctask'

Camping::RDocTask.new(:rdoc) do |rdoc|
Camping::RDocTask.new(:docs) do |rdoc|
rdoc.before_running_rdoc do
mv "lib/camping.rb", "lib/camping-mural.rb"
mv "lib/camping-unabridged.rb", "lib/camping.rb"
Expand All @@ -87,41 +83,11 @@ if defined?(RDoc::VERSION) && RDoc::VERSION[0,3] == "2.4"
mv "lib/camping-mural.rb", "lib/camping.rb"
end

rdoc.rdoc_dir = 'doc/api'
rdoc.options += ['-f', 'singledarkfish', *RDOC_OPTS]
rdoc.template = "flipbook"
rdoc.title = "Camping, the Reference"
rdoc.rdoc_files.add ['lib/camping.rb', 'lib/camping/**/*.rb']
end

Camping::RDocTask.new(:readme) do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.options += RDOC_OPTS
rdoc.options += ['-f', 'singledarkfish', *RDOC_OPTS]
rdoc.template = "flipbook"
rdoc.title = "Camping, a Microframework"
rdoc.rdoc_files.add ['README']
end

Camping::RDocTask.new(:book) do |rdoc|
rdoc.rdoc_dir = 'doc/book'
rdoc.options += ['-f', 'book', *RDOC_OPTS]
rdoc.template = "flipbook"
rdoc.title = "Camping, the Book"
rdoc.rdoc_files.add ['book/*']
end

desc "Build full documentation."
task :docs => [:readme, :rdoc, :book]
desc "Rebuild full documentation."
task :redocs => [:rereadme, :rerdoc, :rebook]
desc "Remove full documentation."
task :clobber_docs => [:clobber_readme, :clobber_rdoc, :clobber_book]

%w(docs redocs clobber_docs).each do |task_name|
task = Rake::Task[task_name]
task.prerequisites.each do |pre|
Rake::Task[pre].instance_eval { @comment = nil }
end
rdoc.rdoc_files.add ['README', 'lib/camping.rb', 'lib/camping/**/*.rb', 'book/*']
end

task :rubygems_docs do
Expand Down
44 changes: 0 additions & 44 deletions extras/rdoc/generator/book.rb

This file was deleted.

55 changes: 45 additions & 10 deletions extras/rdoc/generator/singledarkfish.rb
Expand Up @@ -2,7 +2,7 @@
# vim: noet ts=2 sts=8 sw=2

require 'rubygems'
gem 'rdoc', '>= 2.4' unless defined? $rdoc_rakefile
gem 'rdoc', '>= 2.4'

require 'pp'
require 'pathname'
Expand Down Expand Up @@ -122,10 +122,10 @@ def file_dir
'#file-'
end

def index_template
'reference.rhtml'
def template(name)
"#{name}.rhtml"
end

### Build the initial indices and output objects
### based on an array of TopLevel objects containing
### the extracted information.
Expand All @@ -137,17 +137,20 @@ def generate( top_levels )
@methods = @classes.map { |m| m.method_list }.flatten.sort
@modsort = get_sorted_module_list( @classes )

# Now actually write the output
generate_index
# Now actually write the output
write_style_sheet
generate_thing(:readme, 'index.html')
generate_thing(:reference, 'api.html')
generate_thing(:book, 'book.html')
rescue StandardError => err
debug_msg "%s: %s\n %s" % [ err.class.name, err.message, err.backtrace.join("\n ") ]
raise
end

def generate_index
debug_msg "Rendering the index page..."
def generate_thing(name, to)
debug_msg "Rendering #{name}..."

templatefile = @template_dir + index_template
templatefile = @template_dir + template(name)
template_src = templatefile.read
template = ERB.new( template_src, nil, '<>' )
template.filename = templatefile.to_s
Expand All @@ -165,7 +168,9 @@ def generate_index
], err.backtrace
end

outfile = @basedir + @options.op_dir + 'index.html'
outfile = @basedir + @options.op_dir + to
FileUtils.mkdir_p(File.dirname(outfile))

unless $dryrun
debug_msg "Outputting to %s" % [outfile.expand_path]
outfile.open( 'w', 0644 ) do |fh|
Expand All @@ -175,6 +180,36 @@ def generate_index
debug_msg "Would have output to %s" % [outfile.expand_path]
end
end

## For book.rhtml

def chapters
@chapters ||= @files.select do |file|
next unless file.full_name =~ /^book\//

(class << file; self; end).class_eval { attr_accessor :title, :content, :toc, :id }
file.toc = []
file.content = file.description

file.content.gsub!(%r{<h2>(.*?)</h2>}) do
file.title = $1
file.id = make_id($1)
'<h2 class="ruled" id="%s">%s</h2>' % [file.id, file.title]
end

file.content.gsub!(%r{<h3>(.*?)</h3>}) do |match|
arr = [file.id + '-' + make_id($1), $1]
file.toc << arr
'<h3 id="%s">%s</h3>' % arr
end

true
end
end

def make_id(title)
title.downcase.gsub(/\s/, '-').gsub(/[^\w-]+/, '')
end
end # Roc::Generator::SingleDarkfish

# :stopdoc:
12 changes: 6 additions & 6 deletions extras/rdoc/generator/template/flipbook/book.rhtml
Expand Up @@ -2,15 +2,15 @@
<html>
<head>
<title><%= @options.title %></title>
<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
<script src="../js/jquery.js" type="text/javascript"></script>
<script src="../js/camping.js" type="text/javascript"></script>
<link rel="stylesheet" href="rdoc.css" type="text/css" media="screen" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/camping.js" type="text/javascript"></script>
</head>
<body>
<div id="menu">
<ul id="links">
<li><a href="../">front</a> | </li>
<li><a href="../api/">reference</a> | </li>
<li><a href="index.html">front</a> | </li>
<li><a href="api.html">reference</a> | </li>
<li><a href="http://wiki.github.com/why/camping">wiki</a> | </li>
<li><a href="http://github.com/why/camping">code</a></li>
</ul>
Expand All @@ -21,7 +21,7 @@
<div class="page_shade">
<div class="page">
<p class="header"><%= Time.now %></p>
<h1><%= @options.title %></h1>
<h1>Camping, the Book</h1>
<ol>
<% chapters.each do |chapter| %>
<li>
Expand Down
Empty file.
Empty file.
62 changes: 0 additions & 62 deletions extras/rdoc/generator/template/flipbook/index.rhtml

This file was deleted.

31 changes: 31 additions & 0 deletions extras/rdoc/generator/template/flipbook/readme.rhtml
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title><%= h @options.title %></title>
<link rel="stylesheet" href="rdoc.css" type="text/css" media="screen" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/camping.js" type="text/javascript"></script>
</head>
<body>
<div id="menu">
<ul id="links">
<li><a href="book.html">book</a> | </li>
<li><a href="api.html">reference</a> | </li>
<li><a href="http://wiki.github.com/why/camping">wiki</a> | </li>
<li><a href="http://github.com/why/camping">code</a></li>
</ul>
<p id="version">Camping <%= VERS %></p>
</div>

<div id="fullpage">
<div class="page_shade">
<div class="page">
<p class="header"><%= Time.now %></p>
<h1><%= h @options.title %></h1>
<img src="images/Camping.gif" alt="The Camping Badge" id="logo">
<%= @files.find { |f| f.full_name == @options.main_page }.description.sub(%r{^\s*<h1.*?/h1>}i, '') %>
</div>
</div>
</div>
</body>
</html>
10 changes: 5 additions & 5 deletions extras/rdoc/generator/template/flipbook/reference.rhtml
Expand Up @@ -2,15 +2,15 @@
<html>
<head>
<title>Camping, the Reference</title>
<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
<script src="../js/jquery.js" type="text/javascript"></script>
<script src="../js/camping.js" type="text/javascript"></script>
<link rel="stylesheet" href="rdoc.css" type="text/css" media="screen" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/camping.js" type="text/javascript"></script>
</head>
<body>
<div id="menu">
<ul id="links">
<li><a href="../">front</a> | </li>
<li><a href="../book/">book</a> | </li>
<li><a href="index.html">front</a> | </li>
<li><a href="book.html">book</a> | </li>
<li><a href="http://wiki.github.com/why/camping">wiki</a> | </li>
<li><a href="http://github.com/why/camping">code</a></li>
</ul>
Expand Down

0 comments on commit d81b7a8

Please sign in to comment.