Skip to content

Commit

Permalink
Don't combine all the chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr committed Aug 5, 2009
1 parent 8ca2969 commit 5bd4e2a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 63 deletions.
74 changes: 16 additions & 58 deletions extras/rdoc/generator/singledarkfish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,6 @@ class RDoc::Generator::SingleDarkfish < RDoc::Generator::Darkfish
end
end
end

RDoc::Generator::Markup.instance_eval do
org = instance_method(:description)
define_method(:description) do
old = org.bind(self).call
if RDoc::Generator::SingleDarkfish.current?
old.gsub(/ href="\d\d_([^"]+)"/) do |m|
id, sub = $1.split("#")
id = File.basename(id, ".html")
id << "-#{sub}" if sub

" href=\"book.html##{id}\""
end
else
old
end
end
end

def self.current?
RDoc::RDoc.current.generator.class.ancestors.include?(self)
Expand Down Expand Up @@ -136,10 +118,6 @@ def class_dir
'#class-'
end

def file_dir
'#file-'
end

def template(name)
"#{name}.rhtml"
end
Expand All @@ -159,44 +137,29 @@ def generate( top_levels )
write_style_sheet
generate_thing(:readme, 'index.html')
generate_thing(:reference, 'api.html')
generate_thing(:book, 'book.html')
generate_thing(:toc, 'book.html')
generate_book
rescue StandardError => err
debug_msg "%s: %s\n %s" % [ err.class.name, err.message, err.backtrace.join("\n ") ]
raise
end

def generate_book
chapters.each do |file|
templatefile = @template_dir + template(:page)
outfile = @basedir + @options.op_dir + file.path
render_template(templatefile, binding, outfile)
end
end

def generate_thing(name, to)
debug_msg "Rendering #{name}..."

templatefile = @template_dir + template(name)
template_src = templatefile.read
template = ERB.new( template_src, nil, '<>' )
template.filename = templatefile.to_s
context = binding()

output = nil

begin
output = template.result( context )
rescue NoMethodError => err
raise RDoc::Error, "Error while evaluating %s: %s (at %p)" % [
templatefile,
err.message,
eval( "_erbout[-50,50]", context )
], err.backtrace
end

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|
fh.print( output )
end
else
debug_msg "Would have output to %s" % [outfile.expand_path]
end

render_template(templatefile, binding, outfile)
end

## For book.rhtml
Expand All @@ -207,18 +170,13 @@ def chapters

(class << file; self; end).class_eval { attr_accessor :title, :content, :toc, :id }
file.toc = []
file.id = file.base_name[/\d\d_([^.]+)/, 1]
file.content = file.description
file.title = file.content[%r{<h1>(.*?)</h1>}, 1]

file.content.gsub!(%r{<h2>(.*?)</h2>}) do
file.title = $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.content.gsub!(%r{<h2>(.*?)</h2>}) do |match|
arr = [make_id($1), $1]
file.toc << arr
'<h3 id="%s">%s</h3>' % arr
'<h2 class="ruled" id="%s">%s</h2>' % arr
end

true
Expand Down
30 changes: 30 additions & 0 deletions extras/rdoc/generator/template/flipbook/page.rhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!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="index.html">front</a> | </li>
<li><a href="book.html">ToC</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>
<%= file.content %>
</div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@
<ol>
<% chapters.each do |chapter| %>
<li>
<a href="#<%= chapter.id %>"><%= chapter.title %></a>
<a href="<%= chapter.path %>"><%= chapter.title %></a>
<% unless chapter.toc.empty? %>
<ul>
<% chapter.toc.each do |id, title| %>
<li><a href="#<%= id %>"><%= title %></a></li>
<li><a href="<%= chapter.path %>#<%= id %>"><%= title %></a></li>
<% end %>
</ul>
<% end %>
</li>
<% end %>
</ol>
<% chapters.each do |chapter| %>
<%= chapter.content %>
<% end %>
</div>
</div>
</div>
Expand Down

0 comments on commit 5bd4e2a

Please sign in to comment.