Class: Metanorma::Html::IsoRenderer

Inherits:
StandardRenderer show all
Defined in:
lib/metanorma/html/iso_renderer.rb

Overview

Renders IsoDocument components to HTML. Extends StandardRenderer with ISO-specific cover page, boilerplate, foreword, introduction, annex formatting, and ISO term entries.

Constant Summary

Constants inherited from BaseRenderer

BaseRenderer::LOGO_DIR, BaseRenderer::METANORMA_LOGO, BaseRenderer::SPAN_ROLE_CLASSES, BaseRenderer::TEMPLATE_CACHE, BaseRenderer::TEMPLATE_CACHE_MUTEX

Instance Attribute Summary

Attributes inherited from BaseRenderer

#footnote_collector, #index_term_collector

Instance Method Summary collapse

Methods inherited from BaseRenderer

#assemble_document, #build_footer, #build_header, #build_publisher_logos, #build_scripts, #build_styles, #build_toc_html, #check_presentation_markers, #extract_plain_text, #extract_primary_doc_id, #flavor_css_module, #flavor_font_url, #flavor_js_module, #generate_full_document, #header_title_text, #html_title, #initialize, #language, #load_logo_svg, #register_figure_entry, #register_table_entry, #register_toc_entry, #render_liquid, #renderer_context, #to_html, #toc_entries, #validate_presentation_xml!

Constructor Details

This class inherits a constructor from Metanorma::Html::BaseRenderer

Instance Method Details

#extract_display_title(bibdata) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/metanorma/html/iso_renderer.rb', line 101

def extract_display_title(bibdata)
  titles = bibdata.titles
  return nil unless titles

  en_title = bibdata.title_for("en")
  result = en_title&.to_s
  return result if result && !result.empty?

  if titles.is_a?(Metanorma::IsoDocument::Metadata::TitleCollection) && !titles.items.empty?
    raw = titles.items.find { |t| t.language == "en" } || titles.items.first
    return raw.value.to_s if raw&.value
  end
  nil
end

#extract_doctype(bibdata) ⇒ Object

Extract document type from ext.doctype.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/metanorma/html/iso_renderer.rb', line 160

def extract_doctype(bibdata)
  return nil unless bibdata.respond_to?(:ext)

  ext = bibdata.ext
  return nil unless ext

  doctypes = ext.doctype
  return nil unless doctypes && !doctypes.empty?

  # Prefer English-language doctype
  en_dt = doctypes.find do |d|
    lang = safe_attr(d, :language)
    lang == "en" if lang
  end
  return en_dt.value.to_s if en_dt&.value

  # Fallback: first doctype
  dt = doctypes.first
  val = dt&.value.to_s
  val.strip.empty? ? nil : val
end

#extract_stage(bibdata) ⇒ Object

Extract English stage text, deduplicating duplicate language variants.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/metanorma/html/iso_renderer.rb', line 133

def extract_stage(bibdata)
  return nil unless bibdata.status&.stage

  stages = Array(bibdata.status.stage)
  return nil if stages.empty?

  # Prefer English-language stage
  en_stage = stages.find do |s|
    lang = safe_attr(s, :language)
    lang == "en" if lang
  end
  return Array(en_stage.value).join.strip if en_stage&.value

  # Fallback: first non-empty, deduplicated
  seen = Set.new
  stage_text = stages.filter_map do |s|
    val = Array(s.value).join.strip
    down = val.downcase
    next if seen.include?(down)

    seen << down
    val.empty? ? nil : val
  end.compact.join(" ")
  stage_text.empty? ? nil : stage_text
end

#flavor_publisher_nameObject



17
18
19
# File 'lib/metanorma/html/iso_renderer.rb', line 17

def flavor_publisher_name
  "ISO"
end

#flavor_publishers(_doc_id) ⇒ Object

— Public hooks for flavor customization —



13
14
15
# File 'lib/metanorma/html/iso_renderer.rb', line 13

def flavor_publishers(_doc_id)
  ["ISO"]
end

#formatted_doc_id(bibdata) ⇒ Object

Format doc identifier with publisher prefix (e.g. “OGC 00-027”).



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/metanorma/html/iso_renderer.rb', line 117

def formatted_doc_id(bibdata)
  identifiers = bibdata.doc_identifier
  return nil unless identifiers && !identifiers.empty?

  raw_id = extract_text_value(identifiers.first).to_s.strip
  return nil if raw_id.empty?

  pub = flavor_publisher_name
  if pub && !raw_id.start_with?(pub)
    "#{pub} #{raw_id}"
  else
    raw_id
  end
end

#publisher_logo_mapObject



21
22
23
# File 'lib/metanorma/html/iso_renderer.rb', line 21

def publisher_logo_map
  { "ISO" => "iso-logo.svg" }
end

#render(node) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/metanorma/html/iso_renderer.rb', line 54

def render(node, **)
  case node
  when Metanorma::IsoDocument::Root
    render_document(node, **)
  when Metanorma::IsoDocument::Sections::IsoPreface
    render_preface(node, **)
  when Metanorma::IsoDocument::Sections::IsoSections
    render_sections(node, **)
  when Metanorma::IsoDocument::Sections::IsoClauseSection
    render_clause(node, **)
  when Metanorma::IsoDocument::Sections::IsoAnnexSection
    render_annex(node, **)
  when Metanorma::IsoDocument::Sections::IsoTermsSection
    render_terms_section(node, **)
  when Metanorma::IsoDocument::Sections::IsoForewordSection
    render_foreword(node, **)
  when Metanorma::IsoDocument::Sections::IsoAbstractSection
    render_abstract(node, **)
  when Metanorma::IsoDocument::Terms::IsoTerm
    render_term(node, **)
  when Metanorma::IsoDocument::Terms::TermNote
    render_term_note(node, **)
  when Metanorma::IsoDocument::Terms::TermExample
    render_term_example(node, **)
  when Metanorma::IsoDocument::Boilerplate
    render_boilerplate(node, **)
  else
    super
  end
end

#render_inline_element(element) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/metanorma/html/iso_renderer.rb', line 85

def render_inline_element(element)
  case element
  when Metanorma::IsoDocument::Terms::TermOrigin
    render_term_origin(element)
  else
    super
  end
end

#render_term_origin(element) ⇒ Object



94
95
96
97
98
99
# File 'lib/metanorma/html/iso_renderer.rb', line 94

def render_term_origin(element)
  text = extract_text_value(element)
  return unless text

  @output << "<span class=\"term-source\">#{escape_html(text)}</span>"
end

#themeObject

ISO brand: #e3000f red from logo



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
# File 'lib/metanorma/html/iso_renderer.rb', line 26

def theme
  @theme ||= Theme.new.tap do |t|
    t.primary        = "#b3000c"
    t.accent         = "#e3000f"
    t.accent_deep    = "#b3000c"
    t.gradient       = "linear-gradient(135deg, #8a0009 0%, #b3000c 50%, #e3000f 100%)"
    t.primary_light  = "#fef0f1"
    t.accent_light   = "#fde8ea"
    t.warm           = "#1a1a1a"
    t.warm_light     = "#f5f5f5"
    t.header_background = "linear-gradient(135deg, #8a0009 0%, #b3000c 40%, #e3000f 100%)"
    t.cover_background  = "linear-gradient(175deg, #5a0006 0%, #8a0009 25%, #b3000c 50%, #e3000f 80%, #ff4d4d 100%)"
    t.cover_before_bg   = "background: radial-gradient(ellipse at 25% 20%, rgba(255,77,77,0.15) 0%, transparent 50%), radial-gradient(ellipse at 75% 80%, rgba(26,26,26,0.1) 0%, transparent 40%)"
    t.cover_after_bg    = "height: 3px; background: linear-gradient(90deg, transparent, #e3000f, #1a1a1a, transparent)"
    t.progress_bar_color = "#e3000f"
    t.note_border     = "#e3000f"
    t.note_bg         = "#fde8ea"
    t.note_color      = "#e3000f"
    t.example_border  = "#b3000c"
    t.example_bg      = "#fef0f1"
    t.example_color   = "#b3000c"
    t.admonition_border = "#1a1a1a"
    t.admonition_color  = "#1a1a1a"
    t.footer_border_color = "#e3000f"
    t.cover_separator_color = "rgba(227,0,15,0.25)"
  end
end