Class: Mato::HtmlFilters::SectionAnchor

Inherits:
Object
  • Object
show all
Defined in:
lib/mato/html_filters/section_anchor.rb

Constant Summary collapse

HX_PATTERN =
'h1,h2,h3,h4,h5,h6'

Instance Method Summary collapse

Constructor Details

#initialize(anchor_icon_element = AnchorBuilder::DEFAULT_ANCHOR_ICON_ELEMENT) ⇒ SectionAnchor

Returns a new instance of SectionAnchor.



11
12
13
# File 'lib/mato/html_filters/section_anchor.rb', line 11

def initialize(anchor_icon_element = AnchorBuilder::DEFAULT_ANCHOR_ICON_ELEMENT)
  @anchor_icon_element = anchor_icon_element
end

Instance Method Details

#call(doc) ⇒ Object

Parameters:

  • doc (Nokogiri::HTML::DocumentFragment)


16
17
18
19
20
21
22
# File 'lib/mato/html_filters/section_anchor.rb', line 16

def call(doc)
  anchor_builder = AnchorBuilder.new(@anchor_icon_element)

  doc.css(HX_PATTERN).each do |hx|
    hx.children = anchor_builder.make_anchor_element(hx) + hx.children.to_html
  end
end