Module: Metanorma::Mirror::Output::HtmlRenderers::SectionRenderers
- Included in:
- Metanorma::Mirror::Output::HtmlRenderer
- Defined in:
- lib/metanorma/mirror/output/html_renderers/section_renderers.rb
Class Method Summary collapse
Instance Method Summary collapse
- #render_annex(node, depth: 0) ⇒ Object
- #render_clause(node, depth: 0) ⇒ Object
- #render_content_section(node, depth: 0) ⇒ Object
- #render_definitions(node, depth: 0) ⇒ Object
- #render_floating_title(node, depth: 0) ⇒ Object
- #render_heading(doc, level, attrs) ⇒ Object
- #render_references(node, depth: 0) ⇒ Object
- #render_terms(node, depth: 0) ⇒ Object
Class Method Details
.register(registry) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/metanorma/mirror/output/html_renderers/section_renderers.rb', line 8 def self.register(registry) registry.register_node_handler("clause", instance_method(:render_clause)) registry.register_node_handler("annex", instance_method(:render_annex)) registry.register_node_handler("content_section", instance_method(:render_content_section)) registry.register_node_handler("abstract", instance_method(:render_content_section)) registry.register_node_handler("foreword", instance_method(:render_content_section)) registry.register_node_handler("introduction", instance_method(:render_content_section)) registry.register_node_handler("acknowledgements", instance_method(:render_content_section)) registry.register_node_handler("terms", instance_method(:render_terms)) registry.register_node_handler("definitions", instance_method(:render_definitions)) registry.register_node_handler("references", instance_method(:render_references)) registry.register_node_handler("floating_title", instance_method(:render_floating_title)) end |
Instance Method Details
#render_annex(node, depth: 0) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/metanorma/mirror/output/html_renderers/section_renderers.rb', line 55 def render_annex(node, depth: 0) title = node.attrs["title"] HtmlRenderers.build do |doc| attrs = { class: "mn-annex" } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.section(attrs) do if title heading_attrs = { class: "mn-annex__title" } heading_attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.h2(heading_attrs) { doc.text title } end HtmlRenderers.(doc, render_children(node, depth: depth + 1)) end end end |
#render_clause(node, depth: 0) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/metanorma/mirror/output/html_renderers/section_renderers.rb', line 33 def render_clause(node, depth: 0) title = node.attrs["title"] number = node.attrs["number"] || @numbering[node.attrs["id"]] HtmlRenderers.build do |doc| attrs = { class: "mn-clause" } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.section(attrs) do if title heading_attrs = { class: "mn-clause__title" } heading_attrs[:id] = node.attrs["id"] if node.attrs["id"] render_heading(doc, depth + 2, heading_attrs) do doc.text "#{number} " if number doc.text title end end HtmlRenderers.(doc, render_children(node, depth: depth + 1)) end end end |
#render_content_section(node, depth: 0) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/metanorma/mirror/output/html_renderers/section_renderers.rb', line 73 def render_content_section(node, depth: 0) title = node.attrs["title"] css_class = "mn-#{node.type}" HtmlRenderers.build do |doc| attrs = { class: css_class } attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.section(attrs) do if title heading_attrs = { class: "#{css_class}__title" } heading_attrs[:id] = node.attrs["id"] if node.attrs["id"] doc.h2(heading_attrs) { doc.text title } end HtmlRenderers.(doc, render_children(node, depth:)) end end end |
#render_definitions(node, depth: 0) ⇒ Object
95 96 97 |
# File 'lib/metanorma/mirror/output/html_renderers/section_renderers.rb', line 95 def render_definitions(node, depth: 0) render_content_section(node, depth:) end |
#render_floating_title(node, depth: 0) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/metanorma/mirror/output/html_renderers/section_renderers.rb', line 103 def render_floating_title(node, depth: 0) title = node.attrs["title"] heading_depth = node.attrs["depth"] || 2 return "" unless title HtmlRenderers.build do |doc| attrs = { class: "mn-floating-title" } attrs[:id] = node.attrs["id"] if node.attrs["id"] render_heading(doc, heading_depth, attrs) { doc.text title } end end |
#render_heading(doc, level, attrs) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/metanorma/mirror/output/html_renderers/section_renderers.rb', line 116 def render_heading(doc, level, attrs, &) case level.to_i when 3 then doc.h3(attrs, &) when 4 then doc.h4(attrs, &) when 5 then doc.h5(attrs, &) when 6 then doc.h6(attrs, &) else doc.h2(attrs, &) end end |
#render_references(node, depth: 0) ⇒ Object
99 100 101 |
# File 'lib/metanorma/mirror/output/html_renderers/section_renderers.rb', line 99 def render_references(node, depth: 0) render_content_section(node, depth:) end |
#render_terms(node, depth: 0) ⇒ Object
91 92 93 |
# File 'lib/metanorma/mirror/output/html_renderers/section_renderers.rb', line 91 def render_terms(node, depth: 0) render_content_section(node, depth:) end |