Class: Hensel::Builder::Item

Inherits:
Node
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/hensel/builder/item.rb

Constant Summary

Constants included from Helpers::TagHelpers

Helpers::TagHelpers::BOOLEAN_ATTRIBUTES, Helpers::TagHelpers::ESCAPE_REGEXP, Helpers::TagHelpers::ESCAPE_VALUES

Instance Attribute Summary collapse

Attributes inherited from Node

#attributes, #content, #indent, #name, #parent

Instance Method Summary collapse

Methods inherited from Node

#children, #item, #node

Methods included from Helpers::TagHelpers

#append_attribute, #content_tag, #tag

Constructor Details

#initialize(text, url, **options) ⇒ Item

Returns a new instance of Item.



14
15
16
17
18
# File 'lib/hensel/builder/item.rb', line 14

def initialize(text, url, **options)
  @text    = h(text)
  @url     = url
  @options = Hensel.configuration.default_item_options.merge(options)
end

Instance Attribute Details

#is_firstObject

Returns the value of attribute is_first.



10
11
12
# File 'lib/hensel/builder/item.rb', line 10

def is_first
  @is_first
end

#is_lastObject

Returns the value of attribute is_last.



10
11
12
# File 'lib/hensel/builder/item.rb', line 10

def is_last
  @is_last
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/hensel/builder/item.rb', line 9

def options
  @options
end

#rendererObject

Returns the value of attribute renderer.



10
11
12
# File 'lib/hensel/builder/item.rb', line 10

def renderer
  @renderer
end

#textObject

Returns the value of attribute text.



9
10
11
# File 'lib/hensel/builder/item.rb', line 9

def text
  @text
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/hensel/builder/item.rb', line 9

def url
  @url
end

Instance Method Details

#first?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/hensel/builder/item.rb', line 34

def first?
  !!is_first
end

#last?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/hensel/builder/item.rb', line 38

def last?
  !!is_last
end

#renderObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hensel/builder/item.rb', line 20

def render
  if renderer
    instance_eval(&renderer)
  else
    node(:li, **options) do
      if !Hensel.configuration.last_item_link? && item.last?
        node(:span){ item.text }
      else
        node(:a, href: item.url){ item.text }
      end
    end
  end
end