Class: Nav::ItemComponent

Inherits:
SparkComponents::Component
  • Object
show all
Defined in:
app/components/spark/nav/item_component.rb

Direct Known Subclasses

TabPanels::TabComponent

Instance Method Summary collapse

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/components/spark/nav/item_component.rb', line 41

def active?
  root_attr[:href] != "#" && @view.current_page?(root_attr[:href]) || active
end

#before_renderObject



7
8
9
10
# File 'app/components/spark/nav/item_component.rb', line 7

def before_render
  #root_attr(href: href || "#")
  add_class "active" if active?
end

#labelObject



25
26
27
28
29
30
31
# File 'app/components/spark/nav/item_component.rb', line 25

def label
  if new?
    "new"
  elsif beta
    "beta"
  end
end

#new?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'app/components/spark/nav/item_component.rb', line 33

def new?
  if new.is_a?(String)
    30.days.ago <= Time.zone.parse( new )
  else
    new
  end
end

#renderObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/spark/nav/item_component.rb', line 12

def render
  (:a, tag_attrs) do
    concat component("ui/icon", name: icon, size: icon_size, class: join_class("icon")) if icon
    concat tag.span(class: join_class("content")) {
      concat tag.span(text || @yield, class: join_class("text"))
      concat tag.span(label.upcase, class: [join_class("label"), label]) if label
    }
    concat tag.span(detail, class: join_class("detail")) if detail
    concat tag.span(badge, class: join_class("badge")) if badge
    concat @yield if text
  end
end