class TaskJuggler::NavigatorElement
Attributes
current[RW]
elements[RW]
label[R]
parent[R]
url[RW]
Public Class Methods
new(parent, label = nil, url = nil)
click to toggle source
# File lib/taskjuggler/reports/Navigator.rb, line 23 def initialize(parent, label = nil, url = nil) @parent = parent @label = label @url = url @elements = [] # True if the current report is included in this NavigatorElement or any # of its sub elements. @current = false end
Public Instance Methods
to_html(html = nil)
click to toggle source
# File lib/taskjuggler/reports/Navigator.rb, line 33 def to_html(html = nil) first = true topLevel = html.nil? # If we don't have a container yet, to put all the menus into, create one. html ||= XMLElement.new('div', 'class' => 'navbar_container') html << XMLElement.new('hr', 'class' => 'navbar_topruler') if topLevel # Create a container for this (sub-)menu. html << (div = XMLElement.new('div', 'class' => 'navbar')) @elements.each do |element| # Separate the menu entries by vertical bars. Prepend them for all but # the first entry. if first first = false else div << XMLText.new('|') end if element.current # The navbar entry is referencing this page. Highlight is as the # currently selected page. div << (span = XMLElement.new('span', 'class' => 'navbar_current')) span << XMLText.new(element.label) else # The navbar entry is refencing another page. Show the link to it. div << (span = XMLElement.new('span', 'class' => 'navbar_other')) span << (a = XMLElement.new('a', 'href' => element.url)) a << XMLText.new(element.label) end end # Now see if the current menu entry is actually just holding another sub # menu and generate that menue in another line after an HR. @elements.each do |element| if element.current && !element.elements.empty? html << XMLElement.new('hr', 'class' => 'navbar_midruler') unless first element.to_html(html) break end end html << XMLElement.new('hr', 'class' => 'navbar_bottomruler') if topLevel html end
to_s(indent = 0)
click to toggle source
Return a text version of the tree. Currently used for debugging only.
# File lib/taskjuggler/reports/Navigator.rb, line 85 def to_s(indent = 0) @elements.each do |element| puts "#{' ' * indent}#{element.current ? '<' : ''}" + "#{element.label}#{element.current ? '>' : ''}" + " -> #{element.url}" element.to_s(indent + 1) end end