Module: Metanorma::Html::Concerns::PresentationValidation

Included in:
BaseRenderer
Defined in:
lib/metanorma/html/concerns/presentation_validation.rb

Overview

Presentation-XML validation mixed into BaseRenderer. HTML generation requires Presentation XML input — semantic XML does not contain the formatting data needed for HTML — so the document is checked for presentation markers before rendering begins.

Instance Method Summary collapse

Instance Method Details

#check_presentation_markers(node) ⇒ Object

Name kept for API stability (public renderer API); the boolean return predates the Naming/PredicateMethod convention. rubocop:disable Naming/PredicateMethod



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/metanorma/html/concerns/presentation_validation.rb', line 24

def check_presentation_markers(node)
  return false unless node
  return false if node.is_a?(String)

  if node.is_a?(Lutaml::Model::Serializable)
    node_attrs = node.class.attributes
    if node_attrs.key?(:type) && node.type == "presentation"
      return true
    end
    if node_attrs.key?(:fmt_title) && node.fmt_title
      return true
    end
    if node_attrs.key?(:displayorder) && node.displayorder
      return true
    end

    %i[preface sections annex bibliography].each do |attr|
      next unless node_attrs.key?(attr)

      val = node.public_send(attr)
      next unless val

      Array(val).each { |v| return true if check_presentation_markers(v) }
    end

    node.each_mixed_content do |child|
      next if child.is_a?(String)
      return true if check_presentation_markers(child)
    end
  end

  false
end

#validate_presentation_xml!Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
# File 'lib/metanorma/html/concerns/presentation_validation.rb', line 11

def validate_presentation_xml!
  has_presentation = check_presentation_markers(@document)
  return if has_presentation

  raise ArgumentError,
        "HTML generation requires Presentation XML input. " \
        "Semantic XML does not contain formatting data needed for HTML. " \
        "Use a '.presentation.xml' file instead."
end