Parent

Class Index [+]

Quicksearch

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 31
31:     def initialize
32:       @functionHandlers = []
33:       @snippets = []
34:       @dirty = false
35:       @sectionCounter = [ 0, 0, 0 ]
36:       @linkTarget = nil
37:       @toc = nil
38:       @anchors = []
39:     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 48
48:     def addSnip(file)
49:       @snippets << (snippet = RichTextSnip.new(self, file, @sectionCounter))
50:       snippet.linkTarget = @linkTarget
51:       @dirty = true
52:       snippet
53:     end
checkInternalReferences() click to toggle source

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

    # File lib/taskjuggler/RichText/Document.rb, line 78
78:     def checkInternalReferences
79:       @references.each do |snip, refs|
80:         refs.each do |reference|
81:           unless @anchors.include?(reference)
82:             # TODO: Probably an Exception is cleaner here.
83:             puts "Warning: Rich text file #{snip} references unknown " +
84:                  "object #{reference}"
85:           end
86:         end
87:       end
88:     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 95
 95:     def generateHTML(directory = '')
 96:       crossReference
 97: 
 98:       generateHTMLTableOfContents(directory)
 99: 
100:       @snippets.each do |snip|
101:         snip.generateHTML(directory)
102:       end
103:     end
registerFunctionHandler(handler) click to toggle source

Register a new RichTextFunctionHandler for this document.

    # File lib/taskjuggler/RichText/Document.rb, line 42
42:     def registerFunctionHandler(handler)
43:       @functionHandlers << handler
44:     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 RichTextDocument#checkInternalReferences this function must be called first.

    # File lib/taskjuggler/RichText/Document.rb, line 62
62:     def tableOfContents
63:       @toc = TableOfContents.new
64:       @references = {}
65:       @anchors = []
66:       @snippets.each do |snip|
67:         snip.tableOfContents(@toc, snip.name)
68:         @anchors << snip.name
69:         @toc.each do |tocEntry|
70:           @anchors << snip.name + '#' + tocEntry.tag
71:         end
72:         (refs = snip.internalReferences).empty? ||
73:           @references[snip.name] = refs
74:       end
75:     end

Private Instance Methods

crossReference() click to toggle source

Register the previous and next file with each of the text files. This function is used by the output generators to have links to the next and previous file in the sequence embedded into the generated files.

     # File lib/taskjuggler/RichText/Document.rb, line 110
110:     def crossReference
111:       return unless @dirty
112: 
113:       prevSnip = nil
114:       @snippets.each do |snip|
115:         if prevSnip
116:           snip.prevSnip = prevSnip
117:           prevSnip.nextSnip = snip
118:         end
119:         prevSnip = snip
120:       end
121: 
122:       @dirty = false
123:     end
generateHTMLTableOfContents(directory) click to toggle source

Generate a HTML file with the table of contense for all registered files.

     # File lib/taskjuggler/RichText/Document.rb, line 126
126:     def generateHTMLTableOfContents(directory)
127:       html = HTMLDocument.new
128:       head = html.generateHead('Index')
129:       html << (body = XMLElement.new('body'))
130: 
131:       body << generateHTMLCover <<
132:         @toc.to_html <<
133:         XMLElement.new('br', {}, true) <<
134:         XMLElement.new('hr', {}, true) <<
135:         XMLElement.new('br', {}, true) <<
136:         generateHTMLFooter
137: 
138:       html.write(directory + 'toc.html')
139:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.