A RichTextSnip is a building block for a RichTextDocument. It represents the contense of a text file that contains structured text using the RichText syntax. The class can read-in such a text file and generate an equivalent HTML version.
Create a RichTextSnip object. document is a reference to the RichTextDocument. fileName is the name of the structured text file using RichText syntax. sectionCounter is an 3 item Fixnum Array. These 3 numbers are used to store the section counters over multiple RichTextSnip objects.
# File lib/taskjuggler/RichText/Snip.rb, line 31 def initialize(document, fileName, sectionCounter) @document = document # Strip any directories from fileName. @name = fileName.index('/') ? fileName[fileName.rindex('/') + 1 .. -1] : fileName text = '' File.open(fileName) do |file| file.each_line { |line| text += line } end rText = RichText.new(text, @document.functionHandlers) unless (@richText = rText.generateIntermediateFormat(sectionCounter)) exit end @prevSnip = @nextSnip = nil end
Set the CSS class.
# File lib/taskjuggler/RichText/Snip.rb, line 55 def cssClass=(css) @richText.cssClass = css end
Generate a HTML version of the structured text. The base file name is the same as the original file. directory is the name of the output directory.
# File lib/taskjuggler/RichText/Snip.rb, line 74 def generateHTML(directory = '') html = HTMLDocument.new head = html.generateHead(@name) head << @document.generateStyleSheet html.html << (body = XMLElement.new('body')) body << @document.generateHTMLHeader body << generateHTMLNavigationBar body << (div = XMLElement.new('div', 'style' => 'width:90%; margin-left:5%; margin-right:5%')) div << @richText.to_html body << generateHTMLNavigationBar body << @document.generateHTMLFooter html.write(directory + @name + '.html') end
Return an Array with all other snippet names that are referenced by internal references in this snip.
# File lib/taskjuggler/RichText/Snip.rb, line 67 def internalReferences @richText.internalReferences end
Set the target for all anchor links in the document.
# File lib/taskjuggler/RichText/Snip.rb, line 50 def linkTarget=(target) @richText.linkTarget = target end
Generate a TableOfContents object from the section headers of the RichTextSnip.
# File lib/taskjuggler/RichText/Snip.rb, line 61 def tableOfContents(toc, fileName) @richText.tableOfContents(toc, fileName) end