Class: TaskJuggler::RichTextDocument
- Defined in:
- lib/taskjuggler/RichText/Document.rb
Overview
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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#functionHandlers ⇒ Object
readonly
Returns the value of attribute functionHandlers.
Instance Method Summary collapse
-
#addSnip(file) ⇒ Object
Add a new structured text file to the document.
-
#checkInternalReferences ⇒ Object
Make sure that all internal references only point to known snippets.
-
#generateHTML(directory = '') ⇒ Object
Generate HTML files for all registered text files.
-
#initialize ⇒ RichTextDocument
constructor
Create a new empty RichTextDocument object.
-
#registerFunctionHandler(handler) ⇒ Object
Register a new RichTextFunctionHandler for this document.
-
#tableOfContents ⇒ Object
Call this method to generate a table of contents for all files that were registered so far.
Constructor Details
#initialize ⇒ RichTextDocument
Create a new empty RichTextDocument object.
31 32 33 34 35 36 37 38 39 |
# File 'lib/taskjuggler/RichText/Document.rb', line 31 def initialize @functionHandlers = [] @snippets = [] @dirty = false @sectionCounter = [ 0, 0, 0 ] @linkTarget = nil @toc = nil @anchors = [] end |
Instance Attribute Details
#functionHandlers ⇒ Object (readonly)
Returns the value of attribute functionHandlers.
28 29 30 |
# File 'lib/taskjuggler/RichText/Document.rb', line 28 def functionHandlers @functionHandlers end |
Instance Method Details
#addSnip(file) ⇒ Object
Add a new structured text file to the document. file must be the name of a file with RichText compatible syntax elements.
48 49 50 51 52 53 |
# 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 |
#checkInternalReferences ⇒ Object
Make sure that all internal references only point to known snippets.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/taskjuggler/RichText/Document.rb', line 80 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 = '') ⇒ Object
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’.
97 98 99 100 101 102 103 104 105 |
# File 'lib/taskjuggler/RichText/Document.rb', line 97 def generateHTML(directory = '') crossReference generateHTMLTableOfContents(directory) @snippets.each do |snip| snip.generateHTML(directory) end end |
#registerFunctionHandler(handler) ⇒ Object
Register a new RichTextFunctionHandler for this document.
42 43 44 |
# File 'lib/taskjuggler/RichText/Document.rb', line 42 def registerFunctionHandler(handler) @functionHandlers << handler end |
#tableOfContents ⇒ Object
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.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/taskjuggler/RichText/Document.rb', line 62 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 |