Class: Spark::Nav::Item

Inherits:
Component::Base show all
Defined in:
app/components/spark/nav/item.rb

Instance Method Summary collapse

Methods inherited from Component::Base

#selector, #to_s, #unique_id

Constructor Details

#initializeItem

Returns a new instance of Item.



11
12
13
14
15
16
17
18
# File 'app/components/spark/nav/item.rb', line 11

def initialize(*)
  super

  @href = @href || "#"
  tag_attrs.add attr_hash(:target, :tabindex, :role)
  classname.base = "nav-item"
  classname.add(:active) if active?
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/components/spark/nav/item.rb', line 36

def active?
  @href != "#" && @active || @view_context && @view_context.current_page?(@href)
end

#labelObject



20
21
22
23
24
25
26
# File 'app/components/spark/nav/item.rb', line 20

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

#new?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'app/components/spark/nav/item.rb', line 28

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