Class: Railsboot::Navbar::BrandComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/navbar/brand_component.rb

Overview

ViewComponent: renders the brand block.

Instance Method Summary collapse

Constructor Details

#initialize(tag: "a", **html_attributes) ⇒ BrandComponent

Returns a new instance of BrandComponent.

Parameters:

  • tag (String) (defaults to: "a")

    the tag option

  • html_attributes (Hash)

    additional HTML attributes applied to the rendered element

Options Hash (**html_attributes):

  • :class (String)

    additional CSS classes, merged with the component's own classes

  • :tag (String)

    HTML tag to render for the element



8
9
10
11
12
13
14
15
16
17
# File 'app/components/railsboot/navbar/brand_component.rb', line 8

def initialize(tag: "a", **html_attributes)
  @tag = tag
  @html_attributes = html_attributes

  @html_attributes[:tag] = @tag
  @html_attributes[:class] = class_names(
    "navbar-brand",
    html_attributes.delete(:class)
  )
end

Instance Method Details

#callString

Renders the brand block as a BaseComponent with the
configured tag and HTML attributes, wrapping the provided content.

Returns:

  • (String)

    the rendered HTML



22
23
24
# File 'app/components/railsboot/navbar/brand_component.rb', line 22

def call
  render(Railsboot::BaseComponent.new(**@html_attributes)) { content }
end