Class: TaskJuggler::RichTextSnip
- Defined in:
- lib/taskjuggler/RichText/Snip.rb
Overview
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.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nextSnip ⇒ Object
Returns the value of attribute nextSnip.
-
#prevSnip ⇒ Object
Returns the value of attribute prevSnip.
Instance Method Summary collapse
-
#cssClass=(css) ⇒ Object
Set the CSS class.
-
#generateHTML(directory = '') ⇒ Object
Generate a HTML version of the structured text.
-
#initialize(document, fileName, sectionCounter) ⇒ RichTextSnip
constructor
Create a RichTextSnip object.
-
#internalReferences ⇒ Object
Return an Array with all other snippet names that are referenced by internal references in this snip.
-
#linkTarget=(target) ⇒ Object
Set the target for all anchor links in the document.
-
#tableOfContents(toc, fileName) ⇒ Object
Generate a TableOfContents object from the section headers of the RichTextSnip.
Constructor Details
#initialize(document, fileName, sectionCounter) ⇒ RichTextSnip
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 Integer Array. These 3 numbers are used to store the section counters over multiple RichTextSnip objects.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/taskjuggler/RichText/Snip.rb', line 33 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 |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/taskjuggler/RichText/Snip.rb', line 25 def name @name end |
#nextSnip ⇒ Object
Returns the value of attribute nextSnip.
26 27 28 |
# File 'lib/taskjuggler/RichText/Snip.rb', line 26 def nextSnip @nextSnip end |
#prevSnip ⇒ Object
Returns the value of attribute prevSnip.
26 27 28 |
# File 'lib/taskjuggler/RichText/Snip.rb', line 26 def prevSnip @prevSnip end |
Instance Method Details
#cssClass=(css) ⇒ Object
Set the CSS class.
57 58 59 |
# File 'lib/taskjuggler/RichText/Snip.rb', line 57 def cssClass=(css) @richText.cssClass = css end |
#generateHTML(directory = '') ⇒ Object
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.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/taskjuggler/RichText/Snip.rb', line 76 def generateHTML(directory = '') html = HTMLDocument.new head = html.generateHead(@name) head << @document.generateStyleSheet html.html << (body = XMLElement.new('body')) body << @document.generateHTMLHeader body << body << (div = XMLElement.new('div', 'style' => 'width:90%; margin-left:5%; margin-right:5%')) div << @richText.to_html body << body << @document. html.write(directory + @name + '.html') end |
#internalReferences ⇒ Object
Return an Array with all other snippet names that are referenced by internal references in this snip.
69 70 71 |
# File 'lib/taskjuggler/RichText/Snip.rb', line 69 def internalReferences @richText.internalReferences end |
#linkTarget=(target) ⇒ Object
Set the target for all anchor links in the document.
52 53 54 |
# File 'lib/taskjuggler/RichText/Snip.rb', line 52 def linkTarget=(target) @richText.linkTarget = target end |
#tableOfContents(toc, fileName) ⇒ Object
Generate a TableOfContents object from the section headers of the RichTextSnip.
63 64 65 |
# File 'lib/taskjuggler/RichText/Snip.rb', line 63 def tableOfContents(toc, fileName) @richText.tableOfContents(toc, fileName) end |