Class: Tramway::Navbar
- Inherits:
-
Object
- Object
- Tramway::Navbar
- Defined in:
- lib/tramway/navbar.rb
Overview
Navbar object provides left and right elements
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
-
#initialize(context) ⇒ Navbar
constructor
A new instance of Navbar.
- #item(text_or_url, url = nil) ⇒ Object
- #left {|_self| ... } ⇒ Object
- #right {|_self| ... } ⇒ Object
Constructor Details
#initialize(context) ⇒ Navbar
Returns a new instance of Navbar.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tramway/navbar.rb', line 8 def initialize(context) @context = context @items = { left: [], right: [] } @filling = nil entities = Tramway.config.entities return unless entities.any? preset_left entities end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/tramway/navbar.rb', line 6 def context @context end |
#items ⇒ Object (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
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tramway/navbar.rb', line 36 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, &) rendered_item = if url.present? render_ignoring_block(text_or_url, url, **) else render_using_block(text_or_url, **, &) end @items[@filling] << rendered_item end |
#left {|_self| ... } ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/tramway/navbar.rb', line 20 def left return unless block_given? filling_side(:left) yield self reset_filling end |
#right {|_self| ... } ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/tramway/navbar.rb', line 28 def right return unless block_given? filling_side(:right) yield self reset_filling end |