Class: Tramway::Navbar

Inherits:
Object
  • Object
show all
Defined in:
lib/tramway/navbar.rb

Overview

Navbar object provides left and right elements

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, with_entities:) ⇒ Navbar

Returns a new instance of Navbar.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tramway/navbar.rb', line 8

def initialize(context, with_entities:)
  @context = context
  @items = { left: [], right: [] }
  @filling = nil

  return unless with_entities

  entities = Tramway.config.entities

  return unless entities.any?

  preset_left entities
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/tramway/navbar.rb', line 6

def context
  @context
end

#itemsObject (readonly)

Returns the value of attribute items.



6
7
8
# File 'lib/tramway/navbar.rb', line 6

def items
  @items
end

Instance Method Details

#item(text_or_url, url = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tramway/navbar.rb', line 38

def item(text_or_url, url = nil, **, &)
  raise 'You cannot provide an argument and a code block at the same time' if provided_url_and_block?(url, &)

  if url.present?
    render_ignoring_block(text_or_url, url, **)
  else
    render_using_block(text_or_url, **, &)
  end => rendered_item

  @items[@filling] << rendered_item
end

#left {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



22
23
24
25
26
27
28
# File 'lib/tramway/navbar.rb', line 22

def left
  return unless block_given?

  filling_side(:left)
  yield self
  reset_filling
end

#right {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



30
31
32
33
34
35
36
# File 'lib/tramway/navbar.rb', line 30

def right
  return unless block_given?

  filling_side(:right)
  yield self
  reset_filling
end