metanorma-standoc 3.1.4 → 3.1.6

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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isodoc/html/htmlstyle.css +27 -31
  3. data/lib/metanorma/standoc/base.rb +1 -1
  4. data/lib/metanorma/standoc/cleanup.rb +13 -1
  5. data/lib/metanorma/standoc/cleanup_boilerplate.rb +20 -11
  6. data/lib/metanorma/standoc/cleanup_section_names.rb +8 -8
  7. data/lib/metanorma/standoc/cleanup_terms_boilerplate.rb +5 -4
  8. data/lib/metanorma/standoc/converter.rb +2 -3
  9. data/lib/metanorma/standoc/front.rb +21 -60
  10. data/lib/metanorma/standoc/front_committee.rb +4 -2
  11. data/lib/metanorma/standoc/front_contributor.rb +12 -3
  12. data/lib/metanorma/standoc/front_ext.rb +50 -0
  13. data/lib/metanorma/standoc/isodoc.rng +44 -19
  14. data/lib/metanorma/standoc/macros.rb +1 -3
  15. data/lib/metanorma/standoc/ref.rb +14 -13
  16. data/lib/metanorma/standoc/ref_queue.rb +1 -1
  17. data/lib/metanorma/standoc/ref_sect.rb +9 -3
  18. data/lib/metanorma/standoc/regex.rb +6 -3
  19. data/lib/metanorma/standoc/utils.rb +16 -4
  20. data/lib/metanorma/standoc/validate.rb +1 -1
  21. data/lib/metanorma/standoc/validate_section.rb +12 -2
  22. data/lib/metanorma/standoc/validate_table.rb +3 -1
  23. data/lib/metanorma/standoc/version.rb +1 -1
  24. data/metanorma-standoc.gemspec +1 -0
  25. metadata +17 -12
  26. data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +0 -3
  27. data/lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb +0 -3
  28. data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +0 -8
  29. data/lib/asciidoctor/standoc/macros_plantuml.rb +0 -2
  30. data/lib/metanorma/standoc/datamodel/attributes_table_preprocessor.rb +0 -57
  31. data/lib/metanorma/standoc/datamodel/diagram_preprocessor.rb +0 -103
  32. data/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +0 -409
  33. data/lib/metanorma/standoc/macros_plantuml.rb +0 -143
  34. data/lib/metanorma/standoc/views/datamodel/model_representation.adoc.erb +0 -30
  35. data/lib/metanorma/standoc/views/datamodel/plantuml_representation.adoc.erb +0 -20
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
- <!-- VERSION v2.1.1 -->
3
+ <!-- VERSION v2.1.3 -->
4
4
 
5
5
  <!--
6
6
  ALERT: cannot have root comments, because of https://github.com/metanorma/metanorma/issues/437
@@ -123,6 +123,10 @@ the type attribute defaults to `review` for reviews</a:documentation>
123
123
  <a:documentation>Notes whose scope is the current block</a:documentation>
124
124
  </ref>
125
125
  </zeroOrMore>
126
+ <ref name="BlockSource">
127
+ <a:documentation>Bibliographic source for the information in the list.
128
+ Sources are currently only rendered in metanorma-plateau</a:documentation>
129
+ </ref>
126
130
  </define>
127
131
  <define name="OlBody">
128
132
  <optional>
@@ -140,6 +144,10 @@ the type attribute defaults to `review` for reviews</a:documentation>
140
144
  <a:documentation>Notes whose scope is the current block</a:documentation>
141
145
  </ref>
142
146
  </zeroOrMore>
147
+ <ref name="BlockSource">
148
+ <a:documentation>Bibliographic source for the information in the list.
149
+ Sources are currently only rendered in metanorma-plateau</a:documentation>
150
+ </ref>
143
151
  </define>
144
152
  <define name="OlAttributes">
145
153
  <a:documentation>NOTE: `start` attribute is not included by default, because of problems it raises with DOC output</a:documentation>
@@ -188,6 +196,10 @@ the type attribute defaults to `review` for reviews</a:documentation>
188
196
  <a:documentation>Notes whose scope is the current block</a:documentation>
189
197
  </ref>
190
198
  </zeroOrMore>
199
+ <ref name="BlockSource">
200
+ <a:documentation>Bibliographic source for the information in the list.
201
+ Sources are currently only rendered in metanorma-plateau</a:documentation>
202
+ </ref>
191
203
  </define>
192
204
  <define name="dt">
193
205
  <element name="dt">
@@ -443,14 +455,7 @@ normative or informative references, some split references into sections organiz
443
455
  </ref>
444
456
  </zeroOrMore>
445
457
  <zeroOrMore>
446
- <ref name="doc_bibitem">
447
- <a:documentation>Bibliographic item cited in the document</a:documentation>
448
- </ref>
449
- <zeroOrMore>
450
- <ref name="note">
451
- <a:documentation>Annotation of the bibliographic item</a:documentation>
452
- </ref>
453
- </zeroOrMore>
458
+ <ref name="ReferenceEntry"/>
454
459
  </zeroOrMore>
455
460
  <zeroOrMore>
456
461
  <ref name="references">
@@ -592,18 +597,21 @@ gives an explicit page orientation</a:documentation>
592
597
  </element>
593
598
  </optional>
594
599
  </define>
595
- </include>
596
- <!-- end overrides -->
597
- <define name="FnAttributes" combine="interleave">
598
- <ref name="RequiredId"/>
599
- <optional>
600
- <attribute name="hiddenref">
601
- <a:documentation>If true, number the footnote as normal, but suppress display of the footnote reference in the document body.
600
+ <define name="FnAttributes">
601
+ <ref name="RequiredId"/>
602
+ <optional>
603
+ <attribute name="hiddenref">
604
+ <a:documentation>If true, number the footnote as normal, but suppress display of the footnote reference in the document body.
602
605
  This is done if the footnote reference is already presented in some other form, e.g. within a figure image.</a:documentation>
603
- <data type="boolean"/>
606
+ <data type="boolean"/>
607
+ </attribute>
608
+ </optional>
609
+ <attribute name="reference">
610
+ <a:documentation>The number of the footnote, used to identify it visually</a:documentation>
604
611
  </attribute>
605
- </optional>
606
- </define>
612
+ </define>
613
+ </include>
614
+ <!-- end overrides -->
607
615
  <define name="TdAttributes" combine="interleave">
608
616
  <ref name="RequiredId"/>
609
617
  <optional>
@@ -841,6 +849,17 @@ titlecase, or lowercase</a:documentation>
841
849
  <value>informative</value>
842
850
  </choice>
843
851
  </define>
852
+ <define name="ReferenceEntry">
853
+ <a:documentation>Entry in bibliography</a:documentation>
854
+ <ref name="doc_bibitem">
855
+ <a:documentation>Bibliographic item cited in the document</a:documentation>
856
+ </ref>
857
+ <zeroOrMore>
858
+ <ref name="note">
859
+ <a:documentation>Annotation of the bibliographic item</a:documentation>
860
+ </ref>
861
+ </zeroOrMore>
862
+ </define>
844
863
  <define name="doc_bibitem">
845
864
  <a:documentation>Standardisation document representation of bibliographic entry</a:documentation>
846
865
  <element name="bibitem">
@@ -871,6 +890,12 @@ titlecase, or lowercase</a:documentation>
871
890
  </oneOrMore>
872
891
  </element>
873
892
  </define>
893
+ <define name="ParagraphFnBody" combine="interleave">
894
+ <ref name="BlockSource">
895
+ <a:documentation>Bibliographic source for the information in the paragraph
896
+ parargaph sources are currently only rendered in metanorma-plateau</a:documentation>
897
+ </ref>
898
+ </define>
874
899
  <define name="BasicBlock" combine="choice">
875
900
  <ref name="columnbreak"/>
876
901
  </define>
@@ -2,16 +2,14 @@ require "uuidtools"
2
2
  require "yaml"
3
3
  require "csv"
4
4
  require_relative "macros_inline"
5
- require_relative "macros_plantuml"
6
5
  require_relative "macros_terms"
7
6
  require_relative "macros_form"
8
7
  require_relative "macros_note"
9
8
  require_relative "macros_embed"
10
9
  require_relative "macros_link"
11
- require_relative "datamodel/attributes_table_preprocessor"
12
- require_relative "datamodel/diagram_preprocessor"
13
10
  require "metanorma-plugin-glossarist"
14
11
  require "metanorma-plugin-lutaml"
12
+ require "metanorma-plugin-plantuml"
15
13
 
16
14
  module Metanorma
17
15
  module Standoc
@@ -27,7 +27,7 @@ module Metanorma
27
27
  def isorefmatchescode(match, _item)
28
28
  code = analyse_ref_code(match[:code])
29
29
  yr = norm_year(match[:year])
30
- { code: match[:code], year: yr, match:,
30
+ { code: match[:code], year: yr, match:, fn: match[:fn],
31
31
  title: match[:text], usrlbl: match[:usrlbl] || code[:usrlabel],
32
32
  analyse_code: code, lang: @lang || :all }
33
33
  end
@@ -58,6 +58,14 @@ module Metanorma
58
58
  end
59
59
  end
60
60
 
61
+ def ref_fn(match, xml)
62
+ if match.names.include?("fn") && match[:fn]
63
+ xml.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
64
+ p << match[:fn].to_s
65
+ end
66
+ end
67
+ end
68
+
61
69
  def isorefmatches2_1(xml, match, code)
62
70
  xml.bibitem **attr_code(ref_attributes(match)) do |t|
63
71
  isorefrender1(t, match, code, "--")
@@ -65,11 +73,7 @@ module Metanorma
65
73
  d.on "--"
66
74
  end
67
75
  iso_publisher(t, match[:code])
68
- unless match[:fn].nil?
69
- t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
70
- p << match[:fn].to_s
71
- end
72
- end
76
+ ref_fn(match, t)
73
77
  end
74
78
  end
75
79
 
@@ -97,11 +101,7 @@ module Metanorma
97
101
  isorefrender1(t, match, code, year, " (all parts)")
98
102
  conditional_date(t, match, year == "--")
99
103
  iso_publisher(t, match[:code])
100
- if match.names.include?("fn") && match[:fn]
101
- t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
102
- p << match[:fn].to_s
103
- end
104
- end
104
+ ref_fn(match, t)
105
105
  t.extent type: "part" do |e|
106
106
  e.referenceFrom "all"
107
107
  end
@@ -137,6 +137,7 @@ module Metanorma
137
137
  /^\d+$|^\(.+\)$/.match?(code[:id]) or
138
138
  docnumber(t, code[:id]&.sub(/[:-](19|20)[0-9][0-9]$/, ""))
139
139
  conditional_date(t, yr_match || match, false)
140
+ ref_fn(match, t)
140
141
  end
141
142
  end
142
143
 
@@ -165,11 +166,11 @@ module Metanorma
165
166
  def refitem1code(_item, match)
166
167
  code = analyse_ref_code(match[:code])
167
168
  ((code[:id] && code[:numeric]) || code[:nofetch]) and
168
- return { code: nil, match:, analyse_code: code,
169
+ return { code: nil, match:, analyse_code: code, fn: match[:fn],
169
170
  hidden: code[:hidden] }
170
171
  { code: code[:id], analyse_code: code, localfile: code[:localfile],
171
172
  year: (m = refitem1yr(code[:id])) ? m[:year] : nil,
172
- title: match[:text], match:, hidden: code[:hidden],
173
+ title: match[:text], match:, hidden: code[:hidden], fn: match[:fn],
173
174
  usrlbl: match[:usrlbl] || code[:usrlabel], lang: @lang || :all }
174
175
  end
175
176
 
@@ -195,7 +195,7 @@ module Metanorma
195
195
  def smart_render_xml(xml, code, opts)
196
196
  xml.respond_to? :to_xml or return nil
197
197
  xml = Nokogiri::XML(xml.to_xml(lang: opts[:lang]))
198
- emend_biblio(xml, code, opts[:title], opts[:usrlbl])
198
+ emend_biblio(xml, code, opts)
199
199
  xml.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
200
200
  xml.traverse do |n|
201
201
  n.text? and n.replace(Metanorma::Utils::smartformat(n.text))
@@ -53,10 +53,11 @@ module Metanorma
53
53
  end
54
54
  end
55
55
 
56
- def emend_biblio(xml, code, title, usrlbl)
56
+ def emend_biblio(xml, code, opts)
57
57
  emend_biblio_id(xml, code)
58
- emend_biblio_title(xml, code, title)
59
- emend_biblio_usrlbl(xml, usrlbl)
58
+ emend_biblio_title(xml, code, opts[:title])
59
+ emend_biblio_usrlbl(xml, opts[:usrlbl])
60
+ emend_biblio_fn(xml, opts[:fn])
60
61
  end
61
62
 
62
63
  def emend_biblio_id(xml, code)
@@ -86,6 +87,11 @@ module Metanorma
86
87
  xml.at("/bibitem/docidentifier").next =
87
88
  "<docidentifier type='metanorma'>#{mn_code(usrlbl)}</docidentifier>"
88
89
  end
90
+
91
+ def emend_biblio_fn(xml, fnote)
92
+ fnote or return
93
+ xml.root << "<note type='Unpublished-Status'><p>#{fnote}</p></note>"
94
+ end
89
95
  end
90
96
  end
91
97
  end
@@ -53,7 +53,8 @@ module Metanorma
53
53
  ISO_REF =
54
54
  %r{^<ref\sid="(?<anchor>[^"]+)">
55
55
  \[(?<usrlbl>\(.+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
56
- (?::(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm
56
+ (?::(?<year>[0-9][0-9-]+))?\]</ref>,?\s*
57
+ (?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?\s*(?<text>.*)$}xm
57
58
 
58
59
  ISO_REF_NO_YEAR =
59
60
  %r{^<ref\sid="(?<anchor>[^"]+)">
@@ -70,10 +71,12 @@ module Metanorma
70
71
 
71
72
  # These regexes allow () inside usrlbl but not inside code
72
73
  NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
73
- \[(?<usrlbl>\(.+\))?(?<code>.+?)\]</ref>,?\s*(?<text>.*)$}xm
74
+ \[(?<usrlbl>\(.+\))?(?<code>.+?)\]</ref>,?\s*
75
+ (?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?(?<text>.*)$}xm
74
76
 
75
77
  NON_ISO_REF1 = %r{^<ref\sid="(?<anchor>[^"]+)">
76
- (?<usrlbl>\(.+\))?(?<code>.+?)</ref>,?\s*(?<text>.*)$}xm
78
+ (?<usrlbl>\(.+\))?(?<code>.+?)</ref>,?\s*
79
+ (?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>\s*)?(?<text>.*)$}xm
77
80
  end
78
81
  end
79
82
  end
@@ -43,9 +43,11 @@ module Metanorma
43
43
  %(id = "_#{UUIDTools::UUID.random_create}")
44
44
  end
45
45
 
46
- def csv_split(text, delim = ";")
47
- Metanorma::Utils::csv_split(@c.decode(text), delim)
48
- .map { |x| @c.encode(x, :basic, :hexadecimal) }
46
+ def csv_split(text, delim = ";", encode: true)
47
+ ret = Metanorma::Utils::csv_split(@c.decode(text), delim)
48
+ encode and
49
+ ret.map! { |x| @c.encode(x, :basic, :hexadecimal) }
50
+ ret
49
51
  end
50
52
 
51
53
  # quoted strings: key="va,lue",
@@ -154,7 +156,17 @@ module Metanorma
154
156
  #{text}
155
157
  ADOC
156
158
  c = Asciidoctor.convert(doc, backend: flavour, header_footer: true)
157
- Nokogiri::XML(c).at("//xmlns:sections")
159
+ ret = Nokogiri::XML(c).at("//xmlns:sections")
160
+ separate_numbering_footnotes(ret)
161
+ end
162
+
163
+ # separate numbering of externally sourced footnotes
164
+ # from that of current doc
165
+ def separate_numbering_footnotes(docxml)
166
+ docxml.xpath("//xmlns:fn").each do |f|
167
+ f["reference"] = "_#{UUIDTools::UUID.random_create}_#{f['reference']}"
168
+ end
169
+ docxml
158
170
  end
159
171
 
160
172
  def asciimath_key(sym)
@@ -28,7 +28,7 @@ module Metanorma
28
28
  math_validate(doc)
29
29
  fatalerrors = @log.abort_messages
30
30
  fatalerrors.empty? or
31
- clean_abort("\n\nFATAL ERRROS:\n\n#{fatalerrors.join("\n\n")}", doc)
31
+ clean_abort("\n\nFATAL ERRORS:\n\n#{fatalerrors.join("\n\n")}", doc)
32
32
  end
33
33
 
34
34
  MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
@@ -31,11 +31,21 @@ module Metanorma
31
31
  @log.add("Style", node, w)
32
32
  end
33
33
 
34
+ def reject_metanorma_extension
35
+ ->(node) {
36
+ node.ancestors.detect do |x|
37
+ x.name == "metanorma-extension"
38
+ end
39
+ }
40
+ end
41
+
34
42
  def asset_title_style(root)
35
- root.xpath("//figure[image][not(name)]").each do |node|
43
+ root.xpath("//figure[image][not(name)]")
44
+ .reject(&reject_metanorma_extension).each do |node|
36
45
  style_warning(node, "Figure should have title", nil)
37
46
  end
38
- root.xpath("//table[not(name)]").each do |node|
47
+ root.xpath("//table[not(name)]")
48
+ .reject(&reject_metanorma_extension).each do |node|
39
49
  style_warning(node, "Table should have title", nil)
40
50
  end
41
51
  end
@@ -15,7 +15,8 @@ module Metanorma
15
15
  end
16
16
 
17
17
  def empty_table_validate(doc)
18
- doc.xpath("//table[not(.//tr)]").each do |t|
18
+ doc.xpath("//table[not(.//tr)]").reject(&reject_metanorma_extension)
19
+ .each do |t|
19
20
  @log.add("Table", t, "Empty table", severity: 0)
20
21
  end
21
22
  end
@@ -30,6 +31,7 @@ module Metanorma
30
31
  end
31
32
 
32
33
  def maxrowcols_validate(table, maxcols, mode: "row_cols")
34
+ reject_metanorma_extension.call(table) and return
33
35
  case mode
34
36
  when "row_cols"
35
37
  maxrowcols_validate0(table, maxcols, "*", mode)
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "3.1.4".freeze
22
+ VERSION = "3.1.6".freeze
23
23
  end
24
24
  end
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "metanorma", ">= 1.6.0"
37
37
  spec.add_dependency "metanorma-plugin-glossarist", "~> 0.2.3"
38
38
  spec.add_dependency "metanorma-plugin-lutaml", "~> 0.7.31"
39
+ spec.add_dependency "metanorma-plugin-plantuml", "~> 1.0.0"
39
40
  spec.add_dependency "metanorma-utils", "~> 1.11.0"
40
41
  spec.add_dependency "ruby-jing"
41
42
  # relaton-cli not just relaton, to avoid circular reference in metanorma
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-standoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.4
4
+ version: 3.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-18 00:00:00.000000000 Z
11
+ date: 2025-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.7.31
125
+ - !ruby/object:Gem::Dependency
126
+ name: metanorma-plugin-plantuml
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.0.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.0.0
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: metanorma-utils
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -447,9 +461,6 @@ files:
447
461
  - lib/asciidoctor/standoc/cleanup_toc.rb
448
462
  - lib/asciidoctor/standoc/cleanup_xref.rb
449
463
  - lib/asciidoctor/standoc/converter.rb
450
- - lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb
451
- - lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb
452
- - lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb
453
464
  - lib/asciidoctor/standoc/deprecated.rb
454
465
  - lib/asciidoctor/standoc/front.rb
455
466
  - lib/asciidoctor/standoc/front_contributor.rb
@@ -458,7 +469,6 @@ files:
458
469
  - lib/asciidoctor/standoc/macros.rb
459
470
  - lib/asciidoctor/standoc/macros_form.rb
460
471
  - lib/asciidoctor/standoc/macros_note.rb
461
- - lib/asciidoctor/standoc/macros_plantuml.rb
462
472
  - lib/asciidoctor/standoc/macros_terms.rb
463
473
  - lib/asciidoctor/standoc/ref.rb
464
474
  - lib/asciidoctor/standoc/ref_sect.rb
@@ -515,12 +525,10 @@ files:
515
525
  - lib/metanorma/standoc/cleanup_toc.rb
516
526
  - lib/metanorma/standoc/cleanup_xref.rb
517
527
  - lib/metanorma/standoc/converter.rb
518
- - lib/metanorma/standoc/datamodel/attributes_table_preprocessor.rb
519
- - lib/metanorma/standoc/datamodel/diagram_preprocessor.rb
520
- - lib/metanorma/standoc/datamodel/plantuml_renderer.rb
521
528
  - lib/metanorma/standoc/front.rb
522
529
  - lib/metanorma/standoc/front_committee.rb
523
530
  - lib/metanorma/standoc/front_contributor.rb
531
+ - lib/metanorma/standoc/front_ext.rb
524
532
  - lib/metanorma/standoc/front_organisation.rb
525
533
  - lib/metanorma/standoc/init.rb
526
534
  - lib/metanorma/standoc/inline.rb
@@ -534,7 +542,6 @@ files:
534
542
  - lib/metanorma/standoc/macros_inline.rb
535
543
  - lib/metanorma/standoc/macros_link.rb
536
544
  - lib/metanorma/standoc/macros_note.rb
537
- - lib/metanorma/standoc/macros_plantuml.rb
538
545
  - lib/metanorma/standoc/macros_terms.rb
539
546
  - lib/metanorma/standoc/merge_bibitems.rb
540
547
  - lib/metanorma/standoc/processor.rb
@@ -561,8 +568,6 @@ files:
561
568
  - lib/metanorma/standoc/validate_table.rb
562
569
  - lib/metanorma/standoc/validate_term.rb
563
570
  - lib/metanorma/standoc/version.rb
564
- - lib/metanorma/standoc/views/datamodel/model_representation.adoc.erb
565
- - lib/metanorma/standoc/views/datamodel/plantuml_representation.adoc.erb
566
571
  - metanorma-standoc.gemspec
567
572
  homepage: https://github.com/metanorma/metanorma-standoc
568
573
  licenses:
@@ -1,3 +0,0 @@
1
- require "asciidoctor/standoc/deprecated"
2
- require "metanorma/standoc/datamodel/attributes_table_preprocessor"
3
-
@@ -1,3 +0,0 @@
1
- require "asciidoctor/standoc/deprecated"
2
- require "metanorma/standoc/datamodel/diagram_preprocessor"
3
-
@@ -1,8 +0,0 @@
1
- require "asciidoctor/standoc/deprecated"
2
- require "metanorma/standoc/datamodel/plantuml_renderer"
3
-
4
- module Asciidoctor
5
- module Datamodel
6
- PlantumlRenderer = Metanorma::Datamodel::PlantumlRenderer
7
- end
8
- end
@@ -1,2 +0,0 @@
1
- require "asciidoctor/standoc/deprecated"
2
- require "metanorma/standoc/macros_plantuml"
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "erb"
4
-
5
- module Metanorma
6
- module Standoc
7
- module Datamodel
8
- class AttributesTablePreprocessor < Asciidoctor::Extensions::Preprocessor
9
- BLOCK_START_REGEXP = /\{(.+?)\.\*,(.+),(.+)\}/
10
- BLOCK_END_REGEXP = /\A\{[A-Z]+\}\z/
11
- MARCO_REGEXP = /\[datamodel_attributes_table,([^,]+),?(.+)?\]/
12
- TEMPLATES_PATH = File.expand_path("../views/datamodel", __dir__).freeze
13
- # search document for block `datamodel_attributes_table`
14
- # read include derectives that goes after that in block and transform
15
- # into yaml2text blocks
16
- def process(document, reader)
17
- input_lines = reader.lines.to_enum
18
- Asciidoctor::PreprocessorReader.new(document, processed_lines(document, input_lines))
19
- end
20
-
21
- private
22
-
23
- def processed_lines(document, input_lines)
24
- input_lines.each_with_object([]) do |line, result|
25
- if match = line.match(MARCO_REGEXP)
26
- yaml_path = match[1]
27
- result.push(*parse_marco(yaml_path, document))
28
- else
29
- result.push(line)
30
- end
31
- end
32
- end
33
-
34
- def parse_marco(yaml_path, document)
35
- model_representation(yaml_relative_path(yaml_path, document))
36
- .split("\n")
37
- end
38
-
39
- def model_representation(model_path)
40
- template = File.read(File.join(
41
- TEMPLATES_PATH,
42
- "model_representation.adoc.erb",
43
- ))
44
- file_name = File.basename(model_path).gsub(/\.ya?ml/, "")
45
- ERB
46
- .new(template)
47
- .result(binding)
48
- end
49
-
50
- def yaml_relative_path(file_path, document)
51
- directory = File.dirname(document.attributes["docfile"] || ".")
52
- document.path_resolver.system_path(file_path, directory)
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,103 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "erb"
4
- require "metanorma/standoc/datamodel/plantuml_renderer"
5
-
6
- module Metanorma
7
- module Standoc
8
- module Datamodel
9
- class DiagramPreprocessor < Asciidoctor::Extensions::Preprocessor
10
- BLOCK_START_REGEXP = /\{(.+?)\.\*,(.+),(.+)\}/.freeze
11
- BLOCK_END_REGEXP = /\A\{[A-Z]+\}\z/.freeze
12
- MARCO_REGEXP = /\[datamodel_diagram,([^,]+),?(.+)?\]/.freeze
13
- TEMPLATES_PATH = File.expand_path("../views/datamodel", __dir__).freeze
14
- # search document for block `datamodel_diagram`
15
- # read include derectives that goes after that in block and transform
16
- # into plantuml block
17
- def process(document, reader)
18
- input_lines = reader.lines.to_enum
19
- Asciidoctor::PreprocessorReader.new(document, processed_lines(document, input_lines))
20
- end
21
-
22
- private
23
-
24
- def processed_lines(document, input_lines)
25
- input_lines.each_with_object([]) do |line, result|
26
- if match = line.match(MARCO_REGEXP)
27
- result
28
- .push(*parse_datamodel_marco(match[1], match[2], document))
29
- else
30
- result.push(line)
31
- end
32
- end
33
- end
34
-
35
- def parse_datamodel_marco(yaml_path, include_path, document)
36
- include_path ||= File.join(File.dirname(yaml_path), "..", "models")
37
- include_path = yaml_relative_path(include_path, document)
38
- yaml_relative_to_doc_path = yaml_relative_path(yaml_path, document)
39
- view_hash = YAML.safe_load(File.read(yaml_relative_to_doc_path))
40
- plantuml_representations(view_hash,
41
- yaml_relative_to_doc_path,
42
- include_path)
43
- end
44
-
45
- def yaml_relative_path(file_path, document)
46
- docfile = document.attributes["docfile"] || "."
47
- docfile_directory = File.dirname(docfile)
48
- document.path_resolver.system_path(file_path, docfile_directory)
49
- end
50
-
51
- def import_format(include_path, import_name, values)
52
- include_content = File.read(File.join(
53
- include_path,
54
- "#{import_name}.yml",
55
- ))
56
- content = YAML.safe_load(include_content)
57
- if values
58
- content["skipSection"] = values["skipSection"]
59
- end
60
- content
61
- end
62
-
63
- def format_import_directives(imports, include_path)
64
- imports
65
- .each_with_object({}) do |(import_name, values), res|
66
- full_model_name = import_name.split("/").join
67
- content = import_format(include_path, import_name, values)
68
- res[content["name"] || full_model_name] = content
69
- end.compact
70
- end
71
-
72
- def prepare_view_hash(view_hash, all_imports)
73
- view_hash.merge!(
74
- "classes" => model_type(all_imports, "class"),
75
- "enums" => model_type(all_imports, "enum"),
76
- "relations" => view_hash["relations"] || [],
77
- "fidelity" => (view_hash["fidelity"] || {})
78
- .merge!("classes" => model_type(all_imports,
79
- "class")),
80
- )
81
- end
82
-
83
- def model_type(imports, type)
84
- imports
85
- .select do |_name, elem|
86
- elem["modelType"] == type
87
- end
88
- end
89
-
90
- def plantuml_representations(view_hash, view_path, include_path)
91
- yaml_directory = File.dirname(view_path)
92
- all_imports = format_import_directives(view_hash["imports"],
93
- include_path)
94
- prepare_view_hash(view_hash, all_imports)
95
- Metanorma::Datamodel::PlantumlRenderer
96
- .new(view_hash, File.join(yaml_directory, ".."))
97
- .render
98
- .split("\n")
99
- end
100
- end
101
- end
102
- end
103
- end