Class: Primrose::Components::Navbar
- Defined in:
- lib/primrose/components/navbar.rb
Constant Summary collapse
- TEMPLATE =
"<nav class=\"<%= 'sticky' if @sticky %>\">\n <%= @brand if @brand %>\n <ul>\n <% @links.each do |link| %>\n <li class=\"<%= 'active' if link[:url] == @active_link %>\">\n <a href=\"<%= link[:url] %>\"><%= link[:text] %></a>\n <% if link[:dropdown] %>\n <ul class=\"dropdown\">\n <% link[:dropdown].each do |dropdown_link| %>\n <li><a href=\"<%= dropdown_link[:url] %>\"><%= dropdown_link[:text] %></a></li>\n <% end %>\n </ul>\n <% end %>\n </li>\n <% end %>\n </ul>\n</nav>\n"
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 |