Class: TaskJuggler::NavigatorElement
- Defined in:
- lib/taskjuggler/reports/Navigator.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(parent, label = nil, url = nil) ⇒ NavigatorElement
constructor
A new instance of NavigatorElement.
- #to_html(html = nil) ⇒ Object
-
#to_s(indent = 0) ⇒ Object
Return a text version of the tree.
Constructor Details
#initialize(parent, label = nil, url = nil) ⇒ NavigatorElement
Returns a new instance of NavigatorElement.
23 24 25 26 27 28 29 30 31 |
# 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 |
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
21 22 23 |
# File 'lib/taskjuggler/reports/Navigator.rb', line 21 def current @current end |
#elements ⇒ Object
Returns the value of attribute elements.
21 22 23 |
# File 'lib/taskjuggler/reports/Navigator.rb', line 21 def elements @elements end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
20 21 22 |
# File 'lib/taskjuggler/reports/Navigator.rb', line 20 def label @label end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
20 21 22 |
# File 'lib/taskjuggler/reports/Navigator.rb', line 20 def parent @parent end |
#url ⇒ Object
Returns the value of attribute url.
21 22 23 |
# File 'lib/taskjuggler/reports/Navigator.rb', line 21 def url @url end |
Instance Method Details
#to_html(html = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# 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) ⇒ Object
Return a text version of the tree. Currently used for debugging only.
85 86 87 88 89 90 91 92 |
# 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 |