Class: Mato::AnchorBuilder

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

Constant Summary collapse

DEFAULT_ANCHOR_ICON_ELEMENT =

assumes use of font-awesome specify it as “<span aria-hidden="true" class="octicon octicon-link"></span>” if you use octicon

'<i class="fa fa-link"></i>'
CSS_CLASS_NAME =
"anchor"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(anchor_icon_element = DEFAULT_ANCHOR_ICON_ELEMENT) ⇒ AnchorBuilder

Returns a new instance of AnchorBuilder.



17
18
19
20
# File 'lib/mato/anchor_builder.rb', line 17

def initialize(anchor_icon_element = DEFAULT_ANCHOR_ICON_ELEMENT)
  @anchor_icon_element = anchor_icon_element
  @id_map = {}
end

Instance Attribute Details

#anchor_icon_elementObject (readonly)

Returns the value of attribute anchor_icon_element.



14
15
16
# File 'lib/mato/anchor_builder.rb', line 14

def anchor_icon_element
  @anchor_icon_element
end

#contextObject (readonly)

Returns the value of attribute context.



15
16
17
# File 'lib/mato/anchor_builder.rb', line 15

def context
  @context
end

Instance Method Details

#make_anchor_element(hx) ⇒ Object

Parameters:

  • hx (Nokogiri::XML::Node)


23
24
25
26
# File 'lib/mato/anchor_builder.rb', line 23

def make_anchor_element(hx)
  id = make_anchor_id(hx)
  %{<a id="#{id}" href="##{id}" aria-hidden="true" class="#{CSS_CLASS_NAME}">#{anchor_icon_element}</a>}
end

#make_anchor_id(hx) ⇒ Object



28
29
30
31
# File 'lib/mato/anchor_builder.rb', line 28

def make_anchor_id(hx)
  prefix = make_anchor_id_prefix(hx.inner_text)
  "#{prefix}#{make_anchor_id_suffix(prefix)}"
end