Class TaskJuggler::RichTextDocument
In: lib/taskjuggler/RichText/Document.rb
Parent: Object

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.

Methods

Attributes

functionHandlers  [R] 

Public Class methods

Create a new empty RichTextDocument object.

[Source]

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

Public Instance methods

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

[Source]

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

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

[Source]

# File lib/taskjuggler/RichText/Document.rb, line 78
    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

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’.

[Source]

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

      generateHTMLTableOfContents(directory)

      @snippets.each do |snip|
        snip.generateHTML(directory)
      end
    end

Register a new RichTextFunctionHandler for this document.

[Source]

# File lib/taskjuggler/RichText/Document.rb, line 42
    def registerFunctionHandler(handler)
      @functionHandlers << handler
    end

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 RichTextDocument#checkInternalReferences this function must be called first.

[Source]

# File lib/taskjuggler/RichText/Document.rb, line 62
    def tableOfContents
      @toc = TableOfContents.new
      @references = {}
      @anchors = []
      @snippets.each do |snip|
        snip.tableOfContents(@toc, snip.name)
        @anchors << snip.name
        @toc.each do |tocEntry|
          @anchors << snip.name + '#' + tocEntry.tag
        end
        (refs = snip.internalReferences).empty? ||
          @references[snip.name] = refs
      end
    end

[Validate]