rocco/lib/rocco/layout.rb
Mike West bb9b167b13 Variables for use in Mustache templates.
Added:

*   `docs?`:    True if `docs` contains text of any sort, False if
                it's empty.

*   `code?`:    True if `code` contains text of any sort, False if
                it's empty.

*   `empty?`:   True if both `code` and `docs` are empty.  False
                otherwise.

*   `header?`:  True if `docs` contains _only_ a HTML header.  False
                otherwise.
2010-10-17 13:16:45 +02:00

48 lines
931 B
Ruby

require 'mustache'
class Rocco::Layout < Mustache
self.template_path = File.dirname(__FILE__)
def initialize(doc, file=nil)
@doc = doc
if not file.nil?
Rocco::Layout.template_file = file
end
end
def title
File.basename(@doc.file)
end
def sections
num = 0
@doc.sections.map do |docs,code|
{
:docs => docs,
:docs? => !docs.empty?,
:header? => /^<h.>.+<\/h.>$/.match( docs ),
:code => code,
:code? => !code.empty?,
:empty? => ( code.empty? && docs.empty? ),
:num => (num += 1)
}
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).split('.')[0..-2].join('.') + '.html'
}
end
end
end