implement the file switcher thingy
This commit is contained in:
parent
27b2ee03db
commit
832048d946
18
bin/rocco
18
bin/rocco
@ -27,6 +27,7 @@ end
|
||||
|
||||
# Parse command line options, aborting if anything goes wrong.
|
||||
output_dir = '.'
|
||||
sources = []
|
||||
ARGV.options { |o|
|
||||
o.program_name = File.basename($0)
|
||||
o.on("-o", "--output=DIR") { |dir| output_dir = dir }
|
||||
@ -34,6 +35,14 @@ ARGV.options { |o|
|
||||
o.parse!
|
||||
} or abort_with_note
|
||||
|
||||
# Eat sources from ARGV.
|
||||
sources << ARGV.shift while ARGV.any?
|
||||
|
||||
# Make sure we have some files to work with.
|
||||
if sources.empty?
|
||||
abort_with_note "#{File.basename($0)}: no input <file>s given"
|
||||
end
|
||||
|
||||
# What a fucking mess. Most of this is duplicated in rocco.rb too.
|
||||
libdir = File.expand_path('../../lib', __FILE__).sub(/^#{Dir.pwd}\//, '')
|
||||
begin
|
||||
@ -65,9 +74,10 @@ end
|
||||
# Create the output directory if it doesn't already exist.
|
||||
Dir.mkdir output_dir if !File.directory?(output_dir)
|
||||
|
||||
ARGV.each do |filename|
|
||||
rocco = Rocco.new(filename)
|
||||
dest = "#{output_dir}/#{File.basename(filename, '.rb') + '.html'}"
|
||||
warn "rocco: #{filename} -> #{dest}"
|
||||
# Run each file through Rocco and write output.
|
||||
sources.each do |filename|
|
||||
rocco = Rocco.new(filename, sources)
|
||||
dest = File.join(output_dir, File.basename(filename, '.rb') + '.html')
|
||||
puts "rocco: #{filename} -> #{dest}"
|
||||
File.open(dest, 'wb') { |fd| fd.write(rocco.to_html) }
|
||||
end
|
||||
|
15
lib/rocco.rb
15
lib/rocco.rb
@ -56,14 +56,14 @@ end
|
||||
|
||||
#### Public Interface
|
||||
|
||||
# `Rocco.new` takes a source `filename` and an optional `block`.
|
||||
# When `block` is given, it must read the contents of the file using
|
||||
# whatever means necessary and return it as a string. With no `block`, the
|
||||
# file is read to retrieve data.
|
||||
# `Rocco.new` takes a source `filename`, an optional list of source filenames
|
||||
# for other documentation sources, and an optional `block`. When `block` is
|
||||
# given, it must read the contents of the file using whatever means necessary
|
||||
# and return it as a string. With no `block`, the file is read to retrieve data.
|
||||
class Rocco
|
||||
VERSION = '0.2'
|
||||
|
||||
def initialize(filename, &block)
|
||||
def initialize(filename, sources=[], &block)
|
||||
@file = filename
|
||||
@data =
|
||||
if block_given?
|
||||
@ -71,6 +71,7 @@ class Rocco
|
||||
else
|
||||
File.read(filename)
|
||||
end
|
||||
@sources = sources
|
||||
@sections = highlight(split(parse(@data)))
|
||||
end
|
||||
|
||||
@ -83,6 +84,10 @@ class Rocco
|
||||
# respectively.
|
||||
attr_reader :sections
|
||||
|
||||
# A list of all source filenames included in the documentation set. Useful
|
||||
# for building an index of other files.
|
||||
attr_reader :sources
|
||||
|
||||
# Generate HTML output for the entire document.
|
||||
require 'rocco/layout'
|
||||
def to_html
|
||||
|
@ -8,6 +8,18 @@
|
||||
<body>
|
||||
<div id='container'>
|
||||
<div id="background"></div>
|
||||
{{#sources?}}
|
||||
<div id="jump_to">
|
||||
Jump To …
|
||||
<div id="jump_wrapper">
|
||||
<div id="jump_page">
|
||||
{{#sources}}
|
||||
<a class="source" href="{{ url }}">{{ basename }}</a>
|
||||
{{/sources}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/sources?}}
|
||||
<table cellspacing=0 cellpadding=0>
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -21,4 +21,18 @@ class Rocco::Layout < Mustache
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def sources?
|
||||
@doc.sources.length > 1
|
||||
end
|
||||
|
||||
def sources
|
||||
@doc.sources.sort.map do |source|
|
||||
{
|
||||
:path => source,
|
||||
:basename => File.basename(source),
|
||||
:url => File.basename(source, '.rb') + '.html'
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -92,7 +92,7 @@ class Rocco
|
||||
prerequisites = [@dest, source_file] + rocco_source_files
|
||||
file dest_file => prerequisites do |f|
|
||||
verbose { puts "rocco: #{source_file} -> #{dest_file}" }
|
||||
rocco = Rocco.new(source_file)
|
||||
rocco = Rocco.new(source_file, @sources.to_a)
|
||||
File.open(dest_file, 'wb') { |fd| fd.write(rocco.to_html) }
|
||||
end
|
||||
task @name => dest_file
|
||||
|
Loading…
Reference in New Issue
Block a user