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::CLASS_MAP, BaseRenderer::LOGO_DIR, BaseRenderer::METANORMA_LOGO, BaseRenderer::TEMPLATE_CACHE

Instance Attribute Summary

Attributes inherited from BaseRenderer

#footnote_collector, #index_term_collector

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRenderer

#assemble_document, #build_footer, #build_header, #build_publisher_logos, #build_reader_controls, #build_scripts, #build_styles, #build_toc_html, #check_presentation_markers, #detect_publishers, #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, #to_html, #toc_entries, #validate_presentation_xml!

Constructor Details

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

Class Method Details

.doc_typesObject



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

def doc_types
  @doc_types ||= []
  if superclass <= IsoRenderer && superclass != IsoRenderer
    superclass.doc_types + @doc_types
  else
    @doc_types.dup
  end
end

.registers_doc_type(klass) ⇒ Object



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

def registers_doc_type(klass)
  @doc_types ||= []
  @doc_types << klass
end

Instance Method Details

#extract_display_title(bibdata) ⇒ Object



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

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.



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/metanorma/html/iso_renderer.rb', line 175

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 { |d|
    lang = safe_attr(d, :language)
    lang == "en" if lang
  }
  return en_dt.value.to_s if en_dt && 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.



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/metanorma/html/iso_renderer.rb', line 149

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

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

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

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

#flavor_publisher_nameObject



33
34
35
# File 'lib/metanorma/html/iso_renderer.rb', line 33

def flavor_publisher_name
  "ISO"
end

#flavor_publishers(_doc_id) ⇒ Object

— Public hooks for flavor customization —



29
30
31
# File 'lib/metanorma/html/iso_renderer.rb', line 29

def flavor_publishers(_doc_id)
  ["ISO"]
end

#formatted_doc_id(bibdata) ⇒ Object

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



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/metanorma/html/iso_renderer.rb', line 133

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



37
38
39
# File 'lib/metanorma/html/iso_renderer.rb', line 37

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

#render(node, **opts) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/metanorma/html/iso_renderer.rb', line 70

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

#render_inline_element(element) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/metanorma/html/iso_renderer.rb', line 101

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



110
111
112
113
114
115
# File 'lib/metanorma/html/iso_renderer.rb', line 110

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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/metanorma/html/iso_renderer.rb', line 42

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