Class: Railsboot::HeadingWithAnchorComponent

Inherits:
HeadingComponent
  • Object
show all
Defined in:
app/components/railsboot/heading_with_anchor_component.rb

Overview

ViewComponent: renders the heading with anchor block.

Instance Method Summary collapse

Instance Method Details

#anchor_htmlObject



4
5
6
# File 'app/components/railsboot/heading_with_anchor_component.rb', line 4

def anchor_html
  link_to "", "##{anchor_id}", class: "heading-anchor", 'aria-label': "Anchor", data: { anchor_icon: "#", turbo: "false" }
end

#anchor_idObject



8
9
10
# File 'app/components/railsboot/heading_with_anchor_component.rb', line 8

def anchor_id
  ActionView::Base.full_sanitizer.sanitize(content).parameterize(separator: "_")
end

#before_renderObject



12
13
14
# File 'app/components/railsboot/heading_with_anchor_component.rb', line 12

def before_render
  @html_attributes[:id] = anchor_id
end

#callObject



16
17
18
19
20
# File 'app/components/railsboot/heading_with_anchor_component.rb', line 16

def call
  render Railsboot::HeadingComponent.new(**@html_attributes) do
    ERB::Util.html_escape(content).concat(anchor_html.to_s.html_safe)
  end
end