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.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/taskjuggler/RichText/Snip.rb', line 34

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.



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

def name
  @name
end

#nextSnipObject

Returns the value of attribute nextSnip.



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

def nextSnip
  @nextSnip
end

#prevSnipObject

Returns the value of attribute prevSnip.



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

def prevSnip
  @prevSnip
end

Instance Method Details

#cssClass=(css) ⇒ Object

Set the CSS class.



58
59
60
# File 'lib/taskjuggler/RichText/Snip.rb', line 58

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.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/taskjuggler/RichText/Snip.rb', line 77

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.



70
71
72
# File 'lib/taskjuggler/RichText/Snip.rb', line 70

def internalReferences
  @richText.internalReferences
end

#linkTarget=(target) ⇒ Object

Set the target for all anchor links in the document.



53
54
55
# File 'lib/taskjuggler/RichText/Snip.rb', line 53

def linkTarget=(target)
  @richText.linkTarget = target
end

#tableOfContents(toc, fileName) ⇒ Object

Generate a TableOfContents object from the section headers of the RichTextSnip.



64
65
66
# File 'lib/taskjuggler/RichText/Snip.rb', line 64

def tableOfContents(toc, fileName)
  @richText.tableOfContents(toc, fileName)
end