Class: Railsboot::HeadingWithAnchorComponent

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

Instance Method Summary collapse

Instance Method Details

#anchor_htmlObject



2
3
4
# File 'app/components/railsboot/heading_with_anchor_component.rb', line 2

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

#anchor_idObject



6
7
8
# File 'app/components/railsboot/heading_with_anchor_component.rb', line 6

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

#before_renderObject



10
11
12
# File 'app/components/railsboot/heading_with_anchor_component.rb', line 10

def before_render
  @html_attributes[:id] = anchor_id
end

#callObject



14
15
16
17
18
# File 'app/components/railsboot/heading_with_anchor_component.rb', line 14

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