class UiBibz::Ui::Core::Navigations::Navbar

Create a Navbar

This element is an extend of UiBibz::Ui::Core::Component.

Attributes

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

(:sm, :md, :lg, :xl, :xxl)

Signatures

UiBibz::Ui::Core::Navbar.new(options = nil, html_options = nil).tap do |nb|
  ...
  nb.nav(options = nil, html_options = nil) do |n|
    n.link content options = nil, html_options = nil, &block
    n.link content options = nil, html_options = nil, &block
  end
  ...
end

Examples

UiBibz::Ui::Core::Navbar.new().tap do |nb|
  nb.nav(position: :right) do |n|
    n.link 'Link 1', "#"
    n.link 'Link 2', "#"
  end
  nb.form(url: 'search/', type: :form_tag) do
    text_field_tag 'search', nil, { class: 'form-control', placeholder: 'Search' }
    button 'Submit', type: :submit
  end
  nb.text 'My text'
end.render

Helper

ui_navbar(options = {}, html_options = {}) do |nb|
  nb.nav(options = {}, html_options = {}) do |n|
    n.link(content, options = {}, html_options = {})
    n.link(options = {}, html_options = {}) do
      content
    end
  end
  nb.brand content
  nb.link 'toto', "#"
end

Public Class Methods

new(content = nil, options = nil, html_options = nil, &block) click to toggle source

See UiBibz::Ui::Core::Component.initialize

Calls superclass method UiBibz::Ui::Core::Component::new
# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 81
def initialize(content = nil, options = nil, html_options = nil, &block)
  super
  @items = []
end

Public Instance Methods

brand(content = nil, options = nil, html_options = nil, &block) click to toggle source
# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 124
def brand(content = nil, options = nil, html_options = nil, &block)
  @brand = UiBibz::Ui::Core::Navigations::NavbarBrand.new(content, options, html_options, &block).render
end
form(model_or_url, options = {}, &block) click to toggle source

Add navbar form items See UiBibz::Ui::Core::NavbarForm

# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 113
def form(model_or_url, options = {}, &block)
  @items << UiBibz::Ui::Core::Navigations::NavbarForm.new(model_or_url, options, &block)
end
id() click to toggle source
# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 128
def id
  @id ||= generate_id('navbar-id')
end
nav(content = nil, options = nil, html_options = nil, &block) click to toggle source

Add navbar nav items See UiBibz::Ui::Core::NavbarNav

navbar_toggle_html(content = nil, &block) click to toggle source
pre_render() click to toggle source

Render html tag

# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 87
def pre_render
  content_tag :nav, html_options do
    UiBibz::Ui::Core::Layouts::Container.new(options[:container], options[:container_html]) do
      if brand_position == :left
        concat title
        concat @navbar_toggle_html
      end
      concat navbar_toggle_button_html
      if brand_position == :right
        concat title
        concat @navbar_toggle_html
      end
      concat body_html
    end.render
  end
end
text(content = nil, options = nil, html_options = nil, &block) click to toggle source

Not use !!!!! Add navbar text items See UiBibz::Ui::Core::NavbarText

# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 120
def text(content = nil, options = nil, html_options = nil, &block)
  @items << UiBibz::Ui::Core::Navigations::NavbarText.new(content, options, html_options, &block)
end

Private Instance Methods

body_html() click to toggle source
# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 155
def body_html
  content_tag :div, class: 'navbar-collapse collapse', id: id do
    concat @items.map(&:render).join.html_safe
  end
end
brand_position() click to toggle source
# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 173
def brand_position
  @options[:brand_position] || :left
end
component_html_classes() click to toggle source
# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 143
def component_html_classes
  ['navbar', type, position, expand_size]
end
expand_size() click to toggle source
# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 165
def expand_size
  "navbar-expand-#{@options[:expand_size] || :lg}" unless options[:collapsible] == false
end
navbar_toggle_button_html() click to toggle source
position() click to toggle source
# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 169
def position
  "#{position_type}-#{@options[:position]}" unless @options[:position].nil?
end
position_type() click to toggle source

fixed || sticky

# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 178
def position_type
  @options[:position_type] || 'fixed'
end
status() click to toggle source
# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 186
def status
  "bg-#{@options[:status]}" unless @options[:status].nil?
end
title() click to toggle source
# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 147
def title
  @title ||= if @brand.nil?
               brand(@options[:title]) unless @options[:title].nil?
             else
               @brand
             end
end
type() click to toggle source
# File lib/ui_bibz/ui/core/navigations/navbar.rb, line 182
def type
  "navbar-#{@options[:type] || 'light'}"
end