class TaskJuggler::RichTextDocument

A RichTextDocument object collect a set of structured text files into a single document. This document may have a consistent table of contents across all files and can be turned into a set of corresponding HTML files. This class is an abstract class. To use it, a derrived class must define the functions generateHTMLCover, generateStyleSheet, generateHTMLHeader and generateHTMLFooter.

Attributes

functionHandlers[R]

Public Class Methods

new() click to toggle source

Create a new empty RichTextDocument object.

# File lib/taskjuggler/RichText/Document.rb, line 30
def initialize
  @functionHandlers = []
  @snippets = []
  @dirty = false
  @sectionCounter = [ 0, 0, 0 ]
  @linkTarget = nil
  @toc = nil
  @anchors = []
end

Public Instance Methods

addSnip(file) click to toggle source

Add a new structured text file to the document. file must be the name of a file with RichText compatible syntax elements.

# File lib/taskjuggler/RichText/Document.rb, line 47
def addSnip(file)
  @snippets << (snippet = RichTextSnip.new(self, file, @sectionCounter))
  snippet.linkTarget = @linkTarget
  @dirty = true
  snippet
end
checkInternalReferences() click to toggle source

Make sure that all internal references only point to known snippets.

# File lib/taskjuggler/RichText/Document.rb, line 79
def checkInternalReferences
  @references.each do |snip, refs|
    refs.each do |reference|
      unless @anchors.include?(reference)
        # TODO: Probably an Exception is cleaner here.
        puts "Warning: Rich text file #{snip} references unknown " +
             "object #{reference}"
      end
    end
  end
end
generateHTML(directory = '') click to toggle source

Generate HTML files for all registered text files. The files have the same name as the orginal files with '.html' appended. The files will be generated into the directory. directory must be empty or a valid path name that is terminated with a '/'. A table of contense is generated into a file called 'toc.html'.

# File lib/taskjuggler/RichText/Document.rb, line 96
def generateHTML(directory = '')
  crossReference

  generateHTMLTableOfContents(directory)

  @snippets.each do |snip|
    snip.generateHTML(directory)
  end
end
registerFunctionHandler(handler) click to toggle source

Register a new RichTextFunctionHandler for this document.

# File lib/taskjuggler/RichText/Document.rb, line 41
def registerFunctionHandler(handler)
  @functionHandlers << handler
end
tableOfContents() click to toggle source

Call this method to generate a table of contents for all files that were registered so far. The table of contents is stored internally and will be used when the document is produced in a new format. This function also collects a list of all snip names to @anchors and gathers a list of all references to other snippets in @references. As these two lists will be used by #checkInternalReferences this function must be called first.

# File lib/taskjuggler/RichText/Document.rb, line 61
def tableOfContents
  @toc = TableOfContents.new
  @references = {}
  @anchors = []
  # Collect all file names as potentencial anchors.
  @snippets.each do |snip|
    snip.tableOfContents(@toc, snip.name)
    @anchors << snip.name
    (refs = snip.internalReferences).empty? || @references[snip.name] = refs
  end
  # Then add all section entries as well. We use the HTML style
  # <file>#<tag> notation.
  @toc.each do |tocEntry|
    @anchors << tocEntry.file + '#' + tocEntry.tag
  end
end