Class: Interview::NavigationItem

Inherits:
Link show all
Includes:
HasControls
Defined in:
lib/interview/navigation_item.rb,
lib/interview/navigation_item_old.rb

Instance Attribute Summary collapse

Attributes included from HasControls

#controls

Attributes inherited from Link

#hint, #html_class, #nested_resource, #redirect_to, #style, #url_params

Attributes inherited from Control

#parent

Instance Method Summary collapse

Methods included from HasControls

#add_control, #add_controls, included, #initialize, #siblings

Methods inherited from Link

#assoc_object, #filter=, #initialize, #scope=

Methods inherited from Control

#ancestors, build, definition, #find_attribute, #find_attribute!, inherited, #initialize, #set_attributes, #set_defaults

Instance Attribute Details

#actionObject

Returns the value of attribute action.



6
7
8
# File 'lib/interview/navigation_item.rb', line 6

def action
  @action
end

#activeObject

Returns the value of attribute active.



6
7
8
# File 'lib/interview/navigation_item.rb', line 6

def active
  @active
end

#badge_formulaObject

Returns the value of attribute badge_formula.



6
7
8
# File 'lib/interview/navigation_item.rb', line 6

def badge_formula
  @badge_formula
end

#captionObject

Returns the value of attribute caption.



6
7
8
# File 'lib/interview/navigation_item.rb', line 6

def caption
  @caption
end

#controllerObject

Returns the value of attribute controller.



6
7
8
# File 'lib/interview/navigation_item.rb', line 6

def controller
  @controller
end

#http_methodObject

Returns the value of attribute http_method.



6
7
8
# File 'lib/interview/navigation_item.rb', line 6

def http_method
  @http_method
end

#imageObject

Returns the value of attribute image.



6
7
8
# File 'lib/interview/navigation_item.rb', line 6

def image
  @image
end

#objectObject

Returns the value of attribute object.



6
7
8
# File 'lib/interview/navigation_item.rb', line 6

def object
  @object
end

#trailObject

Returns the value of attribute trail.



6
7
8
# File 'lib/interview/navigation_item.rb', line 6

def trail
  @trail
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/interview/navigation_item.rb', line 6

def url
  @url
end

Instance Method Details

#renderObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/interview/navigation_item.rb', line 9

def render
  css_class = "level#{ancestors.count-1}"
  css_class += " active" if @active
  show_siblings = @active || siblings.any? { |sib| sib.active }
  
  link = Link.new(parent: self, url: @url, controller: @controller, object: @object, 
    action: @action, http_method: @http_method, trail: @trail)
  badge = @badge_formula.call if @badge_formula
  unless badge.nil? or badge == 0 or badge == ''
    link.add_control(HtmlControl.new do |html| 
      html.span badge, class: 'badge pull-right'
    end)
  end
  link.add_control(HtmlControl.new do |html|
    html.span '', class: "glyphicon glyphicon-#{@image}" if @image
    html.text! ' ' if @image and @caption
    html << @caption if @caption
  end)
  
  html = Builder::XmlMarkup.new
  html.li class: css_class do  
    html << link.render
  end
  if show_siblings
    @controls.each do |c| 
      html << c.render 
    end
  end
  return html.target!
end