Sha256: 19002a33177aaf9efad752fb76b5119859b65f7eccef06e7bf598faeebfdded9

Contents?: true

Size: 1.84 KB

Versions: 43

Compression:

Stored size: 1.84 KB

Contents


format :html do
  # Options
  # @param opts [Hash]
  # @option opts [String, Hash<name, href>] brand
  # @option opts [String] class
  # @option opts [Boolean] no_collapse
  # @option opts [:left, :right] toggle_align
  def navbar id, opts={}
    nav_opts = opts[:navbar_opts] || {}
    nav_opts[:class] ||= opts[:class]
    add_class nav_opts,
              "navbar navbar-dark bg-#{opts.delete(:navbar_type) || 'primary'}"
    content = yield
    if opts[:no_collapse]
      navbar_nocollapse content, nav_opts
    else
      navbar_responsive id, content, opts, nav_opts
    end
  end

  def navbar_nocollapse content, nav_opts
    # content = wrap_with(:div, content)
    wrap_with :nav, content, nav_opts
  end

  def navbar_responsive id, content, opts, nav_opts
    opts[:toggle_align] ||= :right
    wrap_with :nav, nav_opts do
      [
        navbar_header(opts[:brand]),
        navbar_toggle(id, opts[:toggle_align]),
        wrap_with(:div, class: "collapse navbar-collapse",
                  id: "navbar-collapse-#{id}") { content }
      ]
    end
  end

  def navbar_header brand
    return "" unless brand
    if brand.is_a? String
      "<span class='navbar-brand'>#{brand}</span>"
    else
      link = brand[:href] || "#"
      "<a class='navbar-brand' href='#{link}#'>#{brand[:name]}</a>"
    end
  end

  def navbar_toggle id, align
    content ||= %(<span class="navbar-toggler-icon"></span>)
    <<-HTML
      <button class="navbar-toggler navbar-toggler-#{align}" type="button" data-toggle="collapse" data-target="#navbar-collapse-#{id}" aria-controls="navbar-collapse-#{id}" aria-expanded="false" aria-label="Toggle navigation">
          #{content}
      </button>
    HTML
  end

  def breadcrumb items
    wrap_with :ol, class: "breadcrumb" do
      items.map do |item|
        wrap_with :li, item, class: "breadcrumb-item"
      end.join
    end
  end
end

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
card-mod-bootstrap-0.11.0 set/all/bootstrap/navbar.rb
card-1.100.0 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.99.6 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.99.5 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.99.4 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.99.3 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.99.2 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.99.1 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.99.0 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.98.3 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.98.2 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.98.1 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.98.0 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.97.0.1 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.97.0 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.96.8 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.96.7 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.96.6 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.96.5 mod/bootstrap/set/all/bootstrap/navbar.rb
card-1.96.4 mod/bootstrap/set/all/bootstrap/navbar.rb