Module: Expressir::Express::HyperlinkFormatter

Defined in:
lib/expressir/express/hyperlink_formatter.rb

Overview

Formatter module - format references as hyperlinks

Examples:

Include into Formatter subclass

formatter = Class.new(Expressir::Express::Formatter) do
  include Expressir::Express::HyperlinkFormatter
end

Instance Method Summary collapse

Instance Method Details

#format_references_simple_reference(node) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/expressir/express/hyperlink_formatter.rb', line 17

def format_references_simple_reference(node)
  return node.id unless node.base_path

  # find closest node with path
  current_node = node
  while !current_node.path
    current_node = current_node.parent
  end

  # skip if this reference and target node are in the same node with path
  node_base_path_parts = node.base_path.split(".")
  current_node_path_parts = current_node.path.split(".")
  return node.id if node_base_path_parts[0..1] == current_node_path_parts[0..1]

  "{{{<<express:#{node.base_path},#{node.id}>>}}}"
end