class TaskJuggler::TOCEntry
A TOCEntry
object is used to store the data of an entry in a TableOfContents
object. It stores the section number, the title, the file name and the name of the tag in this file. The tag is optional and may be nil. The object can be turned into an HTML tree.
Attributes
Public Class Methods
Source
# File lib/taskjuggler/RichText/TOCEntry.rb, line 33 def initialize(number, title, file, tag = nil) @number = number @title = title @file = file @tag = tag end
Create a TOCEntry
object. number: The section number as String
, e. g. ‘1.2.3’ or ‘A.3’. title: The section title as String
. file: The name of the file. tag: An optional tag within the file.
Public Instance Methods
Source
# File lib/taskjuggler/RichText/TOCEntry.rb, line 42 def to_html html = [] if level == 0 # A another table line for some extra distance above main chapters. html << (tr = XMLElement.new('tr')) tr << (td = XMLElement.new('td')) td << XMLElement.new('div', 'style' => 'height:10px') end # Use a different font size depending on the element level. fontSizes = [ 20, 17, 15, 14, 14 ] tr = XMLElement.new('tr', 'style' => "font-size:#{fontSizes[level]}px;") tr << (td = XMLElement.new('td', 'style' => "width:30px;")) # Top-level headings have their number in the left column. td << XMLText.new(@number) if level == 0 tr << (td = XMLElement.new('td')) if level > 0 # Lower level headings have their number in the right column with the # heading text. td << XMLElement.new('span', 'style' => 'padding-right:15px') do XMLText.new(@number) end end tag = @tag ? "##{@tag}" : '' td << (a = XMLElement.new('a', 'href' => "#{@file}.html#{tag}")) a << XMLText.new(@title) html << tr html end
Return the TOCEntry
as equivalent HTML elements. The result is an Array of XMLElement
objects.
Private Instance Methods
Source
# File lib/taskjuggler/RichText/TOCEntry.rb, line 80 def level lev = 0 @number.each_utf8_char { |c| lev += 1 if c == '.' } lev end
Returns the level of the section. It simply counts the number of dots in the section number.