metanorma-document 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +231 -53
  3. data/README.adoc +59 -18
  4. data/data/stylesheets/components/bibliography.css +2 -2
  5. data/data/stylesheets/components/inline.css +11 -12
  6. data/docs/html-renderer.adoc +261 -0
  7. data/lib/metanorma/document/version.rb +1 -1
  8. data/lib/metanorma/html/base_renderer.rb +210 -257
  9. data/lib/metanorma/html/bipm_renderer.rb +0 -1
  10. data/lib/metanorma/html/cc_renderer.rb +0 -1
  11. data/lib/metanorma/html/drops/admonition_drop.rb +26 -0
  12. data/lib/metanorma/html/drops/block_element_drop.rb +20 -0
  13. data/lib/metanorma/html/drops/example_drop.rb +35 -0
  14. data/lib/metanorma/html/drops/figure_drop.rb +53 -0
  15. data/lib/metanorma/html/drops/formula_drop.rb +44 -0
  16. data/lib/metanorma/html/drops/note_drop.rb +32 -0
  17. data/lib/metanorma/html/drops/sourcecode_drop.rb +37 -0
  18. data/lib/metanorma/html/drops.rb +7 -0
  19. data/lib/metanorma/html/iec_renderer.rb +0 -1
  20. data/lib/metanorma/html/ieee_renderer.rb +0 -1
  21. data/lib/metanorma/html/ietf_renderer.rb +0 -1
  22. data/lib/metanorma/html/iho_renderer.rb +0 -1
  23. data/lib/metanorma/html/iso_renderer.rb +77 -209
  24. data/lib/metanorma/html/itu_renderer.rb +0 -1
  25. data/lib/metanorma/html/ogc_renderer.rb +5 -6
  26. data/lib/metanorma/html/oiml_renderer.rb +0 -1
  27. data/lib/metanorma/html/pdfa_renderer.rb +0 -1
  28. data/lib/metanorma/html/ribose_renderer.rb +0 -1
  29. data/lib/metanorma/html/standard_renderer.rb +63 -82
  30. data/lib/metanorma/html/templates/_admonition.html.liquid +4 -0
  31. data/lib/metanorma/html/templates/_doc_title.html.liquid +1 -1
  32. data/lib/metanorma/html/templates/_example.html.liquid +3 -0
  33. data/lib/metanorma/html/templates/_figure.html.liquid +6 -0
  34. data/lib/metanorma/html/templates/_formula.html.liquid +6 -0
  35. data/lib/metanorma/html/templates/_iso_doc_title.html.liquid +2 -2
  36. data/lib/metanorma/html/templates/_note.html.liquid +3 -0
  37. data/lib/metanorma/html/templates/_sourcecode.html.liquid +4 -0
  38. data/lib/metanorma/html.rb +0 -1
  39. metadata +16 -3
  40. data/lib/metanorma/html/component_registry.rb +0 -37
@@ -5,7 +5,6 @@ module Metanorma
5
5
  # Renders BipmDocument components to HTML.
6
6
  # Extends IsoRenderer with BIPM-specific branding (institutional navy, scientific precision).
7
7
  class BipmRenderer < IsoRenderer
8
- registers_doc_type Metanorma::BipmDocument::Root
9
8
 
10
9
  def flavor_publishers(_doc_id)
11
10
  ["BIPM"]
@@ -5,7 +5,6 @@ module Metanorma
5
5
  # Renders CcDocument (CalConnect) components to HTML.
6
6
  # Extends IsoRenderer with CalConnect branding.
7
7
  class CcRenderer < IsoRenderer
8
- registers_doc_type Metanorma::CcDocument::Root
9
8
 
10
9
  def flavor_publishers(_doc_id)
11
10
  ["CalConnect"]
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Html
5
+ module Drops
6
+ class AdmonitionDrop < BlockElementDrop
7
+ def self.from_model(admonition, renderer:)
8
+ type = renderer.safe_attr(admonition, :type) || "note"
9
+ id = renderer.safe_attr(admonition, :id)
10
+
11
+ content_html = renderer.capture_output do
12
+ admonition.paragraphs&.each { |para| renderer.render_paragraph(para) }
13
+ end
14
+
15
+ new(
16
+ id: id,
17
+ type: type,
18
+ label_html: renderer.escape_html(type.capitalize),
19
+ content_html: content_html,
20
+ css_class: "admonition #{type}",
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Html
5
+ module Drops
6
+ class BlockElementDrop < Liquid::Drop
7
+ attr_reader :id, :type, :label_html, :content_html, :css_class
8
+
9
+ def initialize(attrs = {})
10
+ attrs.each { |k, v| instance_variable_set(:"@#{k}", v) }
11
+ end
12
+
13
+ # Subclasses override to build from model + RendererContext
14
+ def self.from_model(_model, renderer:)
15
+ raise NotImplementedError, "#{name} must implement .from_model"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Html
5
+ module Drops
6
+ class ExampleDrop < BlockElementDrop
7
+ def self.from_model(example, renderer:)
8
+ id = renderer.safe_attr(example, :id)
9
+ label = renderer.extract_block_label(example, "EXAMPLE")
10
+
11
+ content_html = renderer.capture_output do
12
+ if example.paragraphs && !example.paragraphs.empty?
13
+ example.paragraphs.each { |para| renderer.render_paragraph(para) }
14
+ end
15
+ example.ul&.each { |ul| renderer.render_unordered_list(ul) }
16
+ example.ol&.each { |ol| renderer.render_ordered_list(ol) }
17
+ example.dl&.each { |dl| renderer.render_definition_list(dl) }
18
+ example.sourcecode&.each { |sc| renderer.render_sourcecode(sc) }
19
+ example.table&.each { |t| renderer.render_table(t) }
20
+ example.figure&.each { |f| renderer.render_figure(f) }
21
+ example.quote&.each { |q| renderer.render_quote(q) }
22
+ example.formula&.each { |f| renderer.render_formula(f) }
23
+ end
24
+
25
+ new(
26
+ id: id,
27
+ label_html: renderer.escape_html(label),
28
+ content_html: content_html,
29
+ css_class: "example",
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Html
5
+ module Drops
6
+ class FigureDrop < BlockElementDrop
7
+ attr_reader :image_html, :caption_html, :key_html, :sub_figures_html
8
+
9
+ def self.from_model(figure, renderer:)
10
+ id = renderer.safe_attr(figure, :id)
11
+ fig_name = renderer.safe_attr(figure, :fmt_name) || renderer.safe_attr(figure, :name)
12
+ if id && fig_name
13
+ renderer.register_figure_entry(id: id, text: renderer.extract_plain_text(fig_name))
14
+ end
15
+
16
+ image_html = renderer.capture_output do
17
+ if figure.image
18
+ renderer.render_image(figure.image)
19
+ elsif renderer.safe_attr(figure, :source)
20
+ src = renderer.safe_attr(figure, :source)
21
+ @output << %(<img src="#{renderer.escape_html(src)}" />)
22
+ end
23
+ end
24
+
25
+ caption_html = if fig_name || renderer.safe_attr(figure, :name)
26
+ renderer.capture_output do
27
+ el = renderer.safe_attr(figure, :fmt_name) || figure.name
28
+ renderer.render_inline_element(el)
29
+ end
30
+ end
31
+
32
+ sub_figures_html = renderer.capture_output do
33
+ figure.figure&.each { |sub| renderer.render_figure(sub) }
34
+ end
35
+
36
+ key_html = renderer.capture_output do
37
+ renderer.safe_attr(figure, :note)&.each { |n| renderer.render_note(n) }
38
+ renderer.safe_attr(figure, :dl)&.then { |dl| renderer.render_definition_list(dl) }
39
+ end
40
+
41
+ new(
42
+ id: id,
43
+ image_html: image_html,
44
+ caption_html: caption_html,
45
+ key_html: key_html,
46
+ sub_figures_html: sub_figures_html,
47
+ css_class: "figure",
48
+ )
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Html
5
+ module Drops
6
+ class FormulaDrop < BlockElementDrop
7
+ attr_reader :stem_html, :where_html, :number_html
8
+
9
+ def self.from_model(formula, renderer:)
10
+ id = renderer.safe_attr(formula, :id)
11
+
12
+ stem_html = renderer.capture_output do
13
+ renderer.render_stem_content(formula.stem) if formula.stem
14
+ end
15
+
16
+ where_html = renderer.capture_output do
17
+ if formula.key
18
+ if formula.key.dl
19
+ @output = renderer.capture_output {}
20
+ # "where" label rendered in template, just render the dl
21
+ renderer.render_definition_list(formula.key.dl)
22
+ end
23
+ formula.key.p&.each { |para| renderer.render_paragraph(para) }
24
+ end
25
+ formula.dl&.then { |dl| renderer.render_definition_list(dl) }
26
+ end
27
+
28
+ name_el = renderer.safe_attr(formula, :fmt_name) || renderer.safe_attr(formula, :name)
29
+ number_html = if name_el
30
+ renderer.capture_output { renderer.render_inline_element(name_el) }
31
+ end
32
+
33
+ new(
34
+ id: id,
35
+ stem_html: stem_html,
36
+ where_html: where_html,
37
+ number_html: number_html,
38
+ css_class: "formula",
39
+ )
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Html
5
+ module Drops
6
+ class NoteDrop < BlockElementDrop
7
+ def self.from_model(note, renderer:)
8
+ id = renderer.safe_attr(note, :id)
9
+ label = renderer.extract_block_label(note, "NOTE")
10
+
11
+ content_html = renderer.capture_output do
12
+ if note.content && !note.content.empty?
13
+ note.content.each { |para| renderer.render_paragraph(para) }
14
+ else
15
+ renderer.render_mixed_inline(note)
16
+ end
17
+ note.ul&.each { |ul| renderer.render_unordered_list(ul) }
18
+ note.ol&.each { |ol| renderer.render_ordered_list(ol) }
19
+ note.dl&.then { |dl| renderer.render_definition_list(dl) }
20
+ end
21
+
22
+ new(
23
+ id: id,
24
+ label_html: renderer.escape_html(label),
25
+ content_html: content_html,
26
+ css_class: "note-block",
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Html
5
+ module Drops
6
+ class SourcecodeDrop < BlockElementDrop
7
+ attr_reader :lang, :name_html, :code_html
8
+
9
+ def self.from_model(sc, renderer:)
10
+ id = renderer.safe_attr(sc, :id)
11
+ lang = renderer.safe_attr(sc, :lang)
12
+
13
+ name_html = if sc.name
14
+ renderer.capture_output { renderer.render_inline_element(sc.name) }
15
+ end
16
+
17
+ code_text = if sc.body&.content
18
+ sc.body.content
19
+ elsif sc.content
20
+ sc.content
21
+ else
22
+ ""
23
+ end
24
+ raw_text = code_text.gsub("&lt;", "<").gsub("&gt;", ">").gsub("&amp;", "&").gsub("&quot;", "\"")
25
+
26
+ new(
27
+ id: id,
28
+ lang: lang,
29
+ name_html: name_html,
30
+ code_html: renderer.escape_html(raw_text),
31
+ css_class: "sourcecode",
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -4,6 +4,13 @@ module Metanorma
4
4
  module Html
5
5
  module Drops
6
6
  autoload :FootnoteDrop, "metanorma/html/drops/footnote_drop"
7
+ autoload :BlockElementDrop, "metanorma/html/drops/block_element_drop"
8
+ autoload :NoteDrop, "metanorma/html/drops/note_drop"
9
+ autoload :AdmonitionDrop, "metanorma/html/drops/admonition_drop"
10
+ autoload :ExampleDrop, "metanorma/html/drops/example_drop"
11
+ autoload :SourcecodeDrop, "metanorma/html/drops/sourcecode_drop"
12
+ autoload :FormulaDrop, "metanorma/html/drops/formula_drop"
13
+ autoload :FigureDrop, "metanorma/html/drops/figure_drop"
7
14
  end
8
15
  end
9
16
  end
@@ -4,7 +4,6 @@ module Metanorma
4
4
  module Html
5
5
  # IEC brand: #0061a9 blue from logo
6
6
  class IecRenderer < IsoRenderer
7
- registers_doc_type Metanorma::IecDocument::Root
8
7
 
9
8
  def flavor_publishers(_doc_id)
10
9
  ["IEC"]
@@ -5,7 +5,6 @@ module Metanorma
5
5
  # Renders IeeeDocument components to HTML.
6
6
  # Extends IsoRenderer with IEEE branding.
7
7
  class IeeeRenderer < IsoRenderer
8
- registers_doc_type Metanorma::IeeeDocument::Root
9
8
 
10
9
  def flavor_publishers(_doc_id)
11
10
  ["IEEE"]
@@ -5,7 +5,6 @@ module Metanorma
5
5
  # Renders IetfDocument components to HTML.
6
6
  # Extends IsoRenderer with IETF/RFC branding.
7
7
  class IetfRenderer < IsoRenderer
8
- registers_doc_type Metanorma::IetfDocument::Root
9
8
 
10
9
  def flavor_publishers(_doc_id)
11
10
  ["IETF"]
@@ -4,7 +4,6 @@ module Metanorma
4
4
  module Html
5
5
  # IHO brand: #00AAA9 teal + #05164D navy + #FEDC5B gold from logo
6
6
  class IhoRenderer < IsoRenderer
7
- registers_doc_type Metanorma::IhoDocument::Root
8
7
 
9
8
  def flavor_publishers(_doc_id)
10
9
  ["IHO"]