Class: Primrose::Components::Navbar
- Defined in:
- lib/primrose/components/navbar.rb
Constant Summary collapse
- TEMPLATE =
<<~ERB <nav class="<%= 'sticky' if @sticky %>"> <%= @brand if @brand %> <ul> <% @links.each do |link| %> <li class="<%= 'active' if link[:url] == @active_link %>"> <a href="<%= link[:url] %>"><%= link[:text] %></a> <% if link[:dropdown] %> <ul class="dropdown"> <% link[:dropdown].each do |dropdown_link| %> <li><a href="<%= dropdown_link[:url] %>"><%= dropdown_link[:text] %></a></li> <% end %> </ul> <% end %> </li> <% end %> </ul> </nav> ERB
Instance Attribute Summary
Attributes inherited from Rose
#children, #event_handlers, #state
Instance Method Summary collapse
-
#initialize(*args, links:, active_link: nil, sticky: false, brand: nil) ⇒ Navbar
constructor
A new instance of Navbar.
- #render ⇒ Object
- #set_active_link(new_active_link) ⇒ Object
Methods inherited from Rose
#add_child, #get_binding, #handle_error, #lifecycle, #on, #render_children, #trigger
Constructor Details
#initialize(*args, links:, active_link: nil, sticky: false, brand: nil) ⇒ Navbar
Returns a new instance of Navbar.
26 27 28 29 30 31 32 |
# File 'lib/primrose/components/navbar.rb', line 26 def initialize(*args, links:, active_link: nil, sticky: false, brand: nil) @links = links @active_link = active_link @sticky = sticky @brand = brand super() end |
Instance Method Details
#render ⇒ Object
34 35 36 |
# File 'lib/primrose/components/navbar.rb', line 34 def render Prim.render(TEMPLATE, self) end |
#set_active_link(new_active_link) ⇒ Object
38 39 40 |
# File 'lib/primrose/components/navbar.rb', line 38 def set_active_link(new_active_link) @state.alter({ active_link: new_active_link }) end |