Class: TaskJuggler::RichTextSnip

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/taskjuggler/RichText/Snip.rb', line 25

def name
  @name
end

#nextSnipObject

Returns the value of attribute nextSnip.



26
27
28
# File 'lib/taskjuggler/RichText/Snip.rb', line 26

def nextSnip
  @nextSnip
end

#prevSnipObject

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

#internalReferencesObject

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