Merge remote branch 'mikewest/template'
Conflicts: lib/rocco.rb
This commit is contained in:
commit
236fb2731c
@ -7,6 +7,7 @@
|
|||||||
#/ -c, --comment-chars=<chars>
|
#/ -c, --comment-chars=<chars>
|
||||||
#/ The string to recognize as a comment marker
|
#/ The string to recognize as a comment marker
|
||||||
#/ -o, --output=<dir> Directory where generated HTML files are written
|
#/ -o, --output=<dir> Directory where generated HTML files are written
|
||||||
|
#/ -t, --template=<path> The file to use as template when rendering HTML
|
||||||
#/ --help Show this help message
|
#/ --help Show this help message
|
||||||
|
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
@ -37,6 +38,7 @@ ARGV.options { |o|
|
|||||||
o.on("-o", "--output=DIR") { |dir| output_dir = dir }
|
o.on("-o", "--output=DIR") { |dir| output_dir = dir }
|
||||||
o.on("-l", "--language=LANG") { |lang| options[:language] = lang }
|
o.on("-l", "--language=LANG") { |lang| options[:language] = lang }
|
||||||
o.on("-c", "--comment-chars=CHARS") { |chars| options[:comment_chars] = Regexp.escape(chars) }
|
o.on("-c", "--comment-chars=CHARS") { |chars| options[:comment_chars] = Regexp.escape(chars) }
|
||||||
|
o.on("-t", "--template=TEMPLATE") { |template| options[:template_file] = template }
|
||||||
o.on_tail("-h", "--help") { usage($stdout, 0) }
|
o.on_tail("-h", "--help") { usage($stdout, 0) }
|
||||||
o.parse!
|
o.parse!
|
||||||
} or abort_with_note
|
} or abort_with_note
|
||||||
|
@ -82,10 +82,12 @@ class Rocco
|
|||||||
defaults = {
|
defaults = {
|
||||||
:language => 'ruby',
|
:language => 'ruby',
|
||||||
:comment_chars => '#',
|
:comment_chars => '#',
|
||||||
|
:template_file => nil
|
||||||
}
|
}
|
||||||
@options = defaults.merge(options)
|
@options = defaults.merge(options)
|
||||||
@sources = sources
|
@sources = sources
|
||||||
@comment_pattern = Regexp.new("^\\s*#{@options[:comment_chars]}\s?")
|
@comment_pattern = Regexp.new("^\\s*#{@options[:comment_chars]}\s?")
|
||||||
|
@template_file = @options[:template_file]
|
||||||
@sections = highlight(split(parse(@data)))
|
@sections = highlight(split(parse(@data)))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -102,10 +104,14 @@ class Rocco
|
|||||||
# for building an index of other files.
|
# for building an index of other files.
|
||||||
attr_reader :sources
|
attr_reader :sources
|
||||||
|
|
||||||
|
# An absolute path to a file that ought be used as a template for the
|
||||||
|
# HTML-rendered documentation.
|
||||||
|
attr_reader :template_file
|
||||||
|
|
||||||
# Generate HTML output for the entire document.
|
# Generate HTML output for the entire document.
|
||||||
require 'rocco/layout'
|
require 'rocco/layout'
|
||||||
def to_html
|
def to_html
|
||||||
Rocco::Layout.new(self).render
|
Rocco::Layout.new(self, @template_file).render
|
||||||
end
|
end
|
||||||
|
|
||||||
#### Internal Parsing and Highlighting
|
#### Internal Parsing and Highlighting
|
||||||
|
@ -3,8 +3,11 @@ require 'mustache'
|
|||||||
class Rocco::Layout < Mustache
|
class Rocco::Layout < Mustache
|
||||||
self.template_path = File.dirname(__FILE__)
|
self.template_path = File.dirname(__FILE__)
|
||||||
|
|
||||||
def initialize(doc)
|
def initialize(doc, file=nil)
|
||||||
@doc = doc
|
@doc = doc
|
||||||
|
if not file.nil?
|
||||||
|
Rocco::Layout.template_file = file
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def title
|
def title
|
||||||
@ -16,7 +19,13 @@ class Rocco::Layout < Mustache
|
|||||||
@doc.sections.map do |docs,code|
|
@doc.sections.map do |docs,code|
|
||||||
{
|
{
|
||||||
:docs => docs,
|
:docs => docs,
|
||||||
|
:docs? => !docs.empty?,
|
||||||
|
:header? => /^<h.>.+<\/h.>$/.match( docs ),
|
||||||
|
|
||||||
:code => code,
|
:code => code,
|
||||||
|
:code? => !code.empty?,
|
||||||
|
|
||||||
|
:empty? => ( code.empty? && docs.empty? ),
|
||||||
:num => (num += 1)
|
:num => (num += 1)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user