Module: Metanorma::Mirror::Handlers::Svgmap

Defined in:
lib/metanorma/mirror/handlers/svgmap.rb

Overview

SVG image map: a wrapped figure plus the href-overwriting targets that bind the SVG's own links to document anchors. Duck-typed over SafeAttr reads — zero model constants.

Constant Summary collapse

REFERENCE_KINDS =
i[xref link eref].freeze

Class Method Summary collapse

Class Method Details

.call(element, context:) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/metanorma/mirror/handlers/svgmap.rb', line 12

def self.call(element, context:)
  attrs = {
    id: SafeAttr.read(element, :id),
    semx_id: SafeAttr.read(element, :semx_id),
    links: link_map(element),
  }.compact
  content = figure_content(element, context)
  Handlers.build_node("svgmap", attrs: attrs, content: content)
end

.figure_content(element, context) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/metanorma/mirror/handlers/svgmap.rb', line 22

def self.figure_content(element, context)
  content = []
  Array(SafeAttr.read(element, :figure)).each do |fig|
    context.registry.handle(fig, context: context).append_to(content)
  end
  content
end


30
31
32
33
34
35
36
37
# File 'lib/metanorma/mirror/handlers/svgmap.rb', line 30

def self.link_map(element)
  links = {}
  Array(SafeAttr.read(element, :target)).each do |target|
    href = SafeAttr.read(target, :href)
    links[href] = reference_of(target) if href && !href.empty?
  end
  links.empty? ? nil : links
end

.reference_of(carrier) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/metanorma/mirror/handlers/svgmap.rb', line 39

def self.reference_of(carrier)
  REFERENCE_KINDS.each do |kind|
    ref = SafeAttr.read(carrier, kind)
    next if ref.nil?

    return SafeAttr.read(ref, :target) ||
        SafeAttr.read(ref, :bibitemid)
  end
  nil
end