Sha256: 326f9b0a5832906b2d37f5cc6ba1d237e5b816cc17d8006f5450c6cbded5a795
Contents?: true
Size: 1.71 KB
Versions: 8
Compression:
Stored size: 1.71 KB
Contents
# frozen_string_literal: true module Bulmacomp # Make an html structure for a bulma breadcrumb # # @example Empty breadcrumb: # render Bulmacomp::BreadcrumbComponent.new() # # <nav class="breadcrumb" aria-label="breadcrumbs"> # <ul> # </ul> # </nav> # # @example Breadcrumb with elements: # elements = [link_to('one','#'), link_to('two','#')] # render Bulmacomp::BreadcrumbComponent.new(elements: elements) # <nav class="breadcrumb" aria-label="breadcrumbs"> # <ul> # <li><a href="#">one</a></li> # <li><a href="#">two</a></li> # </ul> # </nav> # # @example Breadcrump with yield: # render Bulmacomp::BreadcrumbComponent.new() do # <li><a href="#">Bulma</a></li> # end # # <nav class="breadcrumb" aria-label="breadcrumbs"> # <ul> # <li><a href="#">Bulma</a></li> # </ul> # </nav> class BreadcrumbComponent < ViewComponent::Base # @param [Hash] opts # options to generate content # @param [Array<String>] elements # array of elements to push into this breadcrumbs collection # @option opts [String] :* # each other key going as tag option, default is class: 'breadcrumb', aria_label: 'breadcrumbs' # @yield [optional] breadcrumb content def initialize(elements: [], **opts) super @elements = elements @opts = { class: 'breadcrumb', aria: { label: 'breadcrumbs' } }.merge(opts) end # @return [String] html_safe breadcrumb def call tag.nav tag.ul(ul_content), **@opts end # @return [Text], safe join of elements arguments and proc content def ul_content safe_join(@elements.map { |e| tag.li(e) }.<<(content)) end end end
Version data entries
8 entries across 8 versions & 1 rubygems