metanorma-standoc 1.10.2 → 1.10.4.1

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor/standoc/base.rb +13 -5
  3. data/lib/asciidoctor/standoc/blocks.rb +35 -31
  4. data/lib/asciidoctor/standoc/cleanup.rb +61 -0
  5. data/lib/asciidoctor/standoc/cleanup_block.rb +6 -3
  6. data/lib/asciidoctor/standoc/cleanup_reqt.rb +59 -14
  7. data/lib/asciidoctor/standoc/converter.rb +4 -0
  8. data/lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb +22 -21
  9. data/lib/asciidoctor/standoc/isodoc.rng +12 -0
  10. data/lib/asciidoctor/standoc/lists.rb +9 -6
  11. data/lib/asciidoctor/standoc/macros.rb +18 -0
  12. data/lib/asciidoctor/standoc/ref.rb +60 -56
  13. data/lib/asciidoctor/standoc/reqt.rb +39 -27
  14. data/lib/asciidoctor/standoc/reqt.rng +15 -4
  15. data/lib/asciidoctor/standoc/validate_section.rb +2 -1
  16. data/lib/isodoc/base.standard.xsl +6003 -0
  17. data/lib/isodoc/pdf_convert.rb +20 -0
  18. data/lib/metanorma-standoc.rb +1 -0
  19. data/lib/metanorma/standoc/processor.rb +5 -1
  20. data/lib/metanorma/standoc/version.rb +1 -1
  21. data/metanorma-standoc.gemspec +1 -1
  22. data/spec/asciidoctor/base_spec.rb +6 -0
  23. data/spec/asciidoctor/blocks_spec.rb +45 -25
  24. data/spec/asciidoctor/cleanup_sections_spec.rb +899 -864
  25. data/spec/asciidoctor/cleanup_spec.rb +136 -2
  26. data/spec/asciidoctor/macros_plantuml_spec.rb +165 -104
  27. data/spec/asciidoctor/macros_spec.rb +208 -0
  28. data/spec/asciidoctor/validate_spec.rb +4 -0
  29. data/spec/examples/datamodel/address_class_profile.adoc +1 -0
  30. data/spec/examples/datamodel/address_component_profile.adoc +1 -0
  31. data/spec/examples/datamodel/blank_definition_profile.adoc +1 -0
  32. data/spec/examples/datamodel/common_models_diagram.adoc +2 -1
  33. data/spec/examples/datamodel/top_down_diagram.adoc +2 -1
  34. data/spec/fixtures/datamodel_description_sections_tree.xml +327 -0
  35. data/spec/fixtures/test.xmi +9250 -0
  36. data/spec/metanorma/processor_spec.rb +50 -50
  37. data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +34 -34
  38. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +50 -50
  39. data/spec/vcr_cassettes/isobib_get_123.yml +11 -11
  40. data/spec/vcr_cassettes/isobib_get_123_1.yml +23 -23
  41. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +35 -35
  42. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
  43. data/spec/vcr_cassettes/isobib_get_124.yml +11 -11
  44. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  45. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
  46. metadata +8 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca8e0e987187b1a9c3e36246671b4c8566746c6178034c55e0cba34164f64bbf
4
- data.tar.gz: af58564b53587bff140ecec89f1ca9d2e051859befbcbabd9842ed3e84fda039
3
+ metadata.gz: 4de5b7f8779dae7c359b93ce364ffa7cc406156bf1437c7cdccb6595b7bd958a
4
+ data.tar.gz: c35902148b405e451af8487faff391b6eddbbd7b07cd2b6c8d565cd515e4515c
5
5
  SHA512:
6
- metadata.gz: e711720551cfcfe47d425fcd3172c5bc07eb727dc9f08e2f9fe02cfa4edd1f9bffe5587b9a4215f470951149cc36a970ca669e217226a52fa812c07fb70ee1c5
7
- data.tar.gz: acef9c690a20986928c0c26508787ba362022ee9970f35d9e9c4fe47c55aebf3a0dafac1e3d2c684bbecf602d0a750583948921bd65e04e791d462f20707448c
6
+ metadata.gz: 6e33b33321d6826a65257a3440c63218021d5d40b69fa58b268d0a2c5e8436aed951e05c7f44ab97c74b5ce916c25ad7040cc962cf38be15ee2ebaf0c6858529
7
+ data.tar.gz: f8f719f8062c3c71ebd2883617b984d7432134cb94da1be308e9ede34bf74def5be6267570c76ff9f248e628e443d6b71a60b9f71e1ba436b7c64eb2c2b25c13
@@ -62,6 +62,12 @@ module Asciidoctor
62
62
  IsoDoc::HtmlConvert.new(html_extract_attributes(node))
63
63
  end
64
64
 
65
+ def pdf_converter(node)
66
+ return nil if node.attr("no-pdf")
67
+
68
+ IsoDoc::Standoc::PdfConvert.new(doc_extract_attributes(node))
69
+ end
70
+
65
71
  def doc_extract_attributes(node)
66
72
  attrs = {
67
73
  script: node.attr("script"),
@@ -114,11 +120,11 @@ module Asciidoctor
114
120
  node.attr("mn-keep-asciimath") != "false"
115
121
  @fontheader = default_fonts(node)
116
122
  @files_to_delete = []
117
- if node.attr("docfile")
118
- @filename = File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "")
119
- else
120
- @filename = ""
121
- end
123
+ @filename = if node.attr("docfile")
124
+ File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "")
125
+ else
126
+ ""
127
+ end
122
128
  @localdir = Metanorma::Utils::localdir(node)
123
129
  @output_dir = outputdir node
124
130
  @no_isobib_cache = node.attr("no-isobib-cache")
@@ -156,6 +162,8 @@ module Asciidoctor
156
162
  nil, false, "#{@filename}.html")
157
163
  doc_converter(node).convert("#{@filename}.presentation.xml",
158
164
  nil, false, "#{@filename}.doc")
165
+ pdf_converter(node)&.convert("#{@filename}.presentation.xml",
166
+ nil, false, "#{@filename}.pdf")
159
167
  end
160
168
 
161
169
  def document(node)
@@ -10,15 +10,17 @@ module Asciidoctor
10
10
  end
11
11
 
12
12
  def id_unnum_attrs(node)
13
- attr_code( id: Metanorma::Utils::anchor_or_uuid(node),
13
+ attr_code(id: Metanorma::Utils::anchor_or_uuid(node),
14
14
  unnumbered: node.option?("unnumbered") ? "true" : nil,
15
15
  number: node.attr("number"),
16
- subsequence: node.attr("subsequence") )
16
+ subsequence: node.attr("subsequence"))
17
17
  end
18
18
 
19
19
  def formula_attrs(node)
20
- attr_code(id_unnum_attrs(node).merge(keep_attrs(node).merge(
21
- inequality: node.option?("inequality") ? "true" : nil)))
20
+ attr_code(id_unnum_attrs(node)
21
+ .merge(keep_attrs(node).merge(
22
+ inequality: node.option?("inequality") ? "true" : nil,
23
+ )))
22
24
  end
23
25
 
24
26
  def keep_attrs(node)
@@ -58,8 +60,8 @@ module Asciidoctor
58
60
  xml.figure **literal_attrs(node) do |f|
59
61
  figure_title(node, f)
60
62
  f.pre node.lines.join("\n"),
61
- **attr_code(id: Metanorma::Utils::anchor_or_uuid,
62
- alt: node.attr("alt"))
63
+ **attr_code(id: Metanorma::Utils::anchor_or_uuid,
64
+ alt: node.attr("alt"))
63
65
  end
64
66
  end
65
67
  end
@@ -95,20 +97,21 @@ module Asciidoctor
95
97
  end
96
98
 
97
99
  def svgmap_attrs(node)
98
- attr_code( { id: node.id,
99
- unnumbered: node.option?("unnumbered") ? "true" : nil,
100
- number: node.attr("number"),
101
- subsequence: node.attr("subsequence") }.
102
- merge(keep_attrs(node)))
100
+ attr_code({ id: node.id,
101
+ unnumbered: node.option?("unnumbered") ? "true" : nil,
102
+ number: node.attr("number"),
103
+ subsequence: node.attr("subsequence") }
104
+ .merge(keep_attrs(node)))
103
105
  end
104
106
 
105
107
  def svgmap_example(node)
106
108
  noko do |xml|
107
109
  xml.svgmap **attr_code(svgmap_attrs(node).merge(
108
- src: node.attr("src"), alt: node.attr("alt"))) do |ex|
109
- figure_title(node, ex)
110
- ex << node.content
111
- end
110
+ src: node.attr("src"), alt: node.attr("alt"),
111
+ )) do |ex|
112
+ figure_title(node, ex)
113
+ ex << node.content
114
+ end
112
115
  end.join("\n")
113
116
  end
114
117
 
@@ -136,9 +139,10 @@ module Asciidoctor
136
139
  end.join("\n")
137
140
  end
138
141
 
139
- def figure_title(node, f)
142
+ def figure_title(node, out)
140
143
  return if node.title.nil?
141
- f.name { |name| name << node.title }
144
+
145
+ out.name { |name| name << node.title }
142
146
  end
143
147
 
144
148
  def figure_attrs(node)
@@ -149,15 +153,15 @@ module Asciidoctor
149
153
  noko do |xml|
150
154
  xml.figure **figure_attrs(node) do |f|
151
155
  figure_title(node, f)
152
- f.image **(image_attributes(node))
156
+ f.image **image_attributes(node)
153
157
  end
154
158
  end
155
159
  end
156
160
 
157
161
  def para_attrs(node)
158
162
  attr_code(keep_attrs(node)
159
- .merge(align: node.attr("align"),
160
- id: Metanorma::Utils::anchor_or_uuid(node)))
163
+ .merge(align: node.attr("align"),
164
+ id: Metanorma::Utils::anchor_or_uuid(node)))
161
165
  end
162
166
 
163
167
  def paragraph(node)
@@ -172,8 +176,8 @@ module Asciidoctor
172
176
 
173
177
  def quote_attrs(node)
174
178
  attr_code(keep_attrs(node)
175
- .merge(align: node.attr("align"),
176
- id: Metanorma::Utils::anchor_or_uuid(node)))
179
+ .merge(align: node.attr("align"),
180
+ id: Metanorma::Utils::anchor_or_uuid(node)))
177
181
  end
178
182
 
179
183
  def quote_attribution(node, out)
@@ -189,7 +193,7 @@ module Asciidoctor
189
193
 
190
194
  def quote(node)
191
195
  noko do |xml|
192
- xml.quote **(quote_attrs(node)) do |q|
196
+ xml.quote **quote_attrs(node) do |q|
193
197
  quote_attribution(node, q)
194
198
  wrap_in_para(node, q)
195
199
  end
@@ -197,18 +201,18 @@ module Asciidoctor
197
201
  end
198
202
 
199
203
  def listing_attrs(node)
200
- attr_code(keep_attrs(node).
201
- merge(lang: node.attr("language"),
202
- id: Metanorma::Utils::anchor_or_uuid(node),
203
- unnumbered: node.option?("unnumbered") ? "true" : nil,
204
- number: node.attr("number"),
205
- filename: node.attr("filename")))
204
+ attr_code(keep_attrs(node)
205
+ .merge(lang: node.attr("language"),
206
+ id: Metanorma::Utils::anchor_or_uuid(node),
207
+ unnumbered: node.option?("unnumbered") ? "true" : nil,
208
+ number: node.attr("number"),
209
+ filename: node.attr("filename")))
206
210
  end
207
211
 
208
212
  # NOTE: html escaping is performed by Nokogiri
209
213
  def listing(node)
210
214
  fragment = ::Nokogiri::XML::Builder.new do |xml|
211
- xml.sourcecode **(listing_attrs(node)) do |s|
215
+ xml.sourcecode **listing_attrs(node) do |s|
212
216
  figure_title(node, s)
213
217
  s << node.content
214
218
  end
@@ -219,7 +223,7 @@ module Asciidoctor
219
223
 
220
224
  def pass(node)
221
225
  noko do |xml|
222
- xml.passthrough **attr_code(formats:
226
+ xml.passthrough **attr_code(formats:
223
227
  node.attr("format") || "metanorma") do |p|
224
228
  p << HTMLEntities.new.encode(node.content, :basic, :hexadecimal)
225
229
  end
@@ -62,6 +62,7 @@ module Asciidoctor
62
62
  bibdata_cleanup(xmldoc)
63
63
  svgmap_cleanup(xmldoc)
64
64
  boilerplate_cleanup(xmldoc)
65
+ toc_cleanup(xmldoc)
65
66
  smartquotes_cleanup(xmldoc)
66
67
  variant_cleanup(xmldoc)
67
68
  para_cleanup(xmldoc)
@@ -84,6 +85,30 @@ module Asciidoctor
84
85
  end
85
86
 
86
87
  def smartquotes_cleanup1(xmldoc)
88
+ uninterrupt_quotes_around_xml(xmldoc)
89
+ dumb2smart_quotes(xmldoc)
90
+ end
91
+
92
+ # "abc<tag/>", def => "abc",<tag/> def
93
+ def uninterrupt_quotes_around_xml(xmldoc)
94
+ xmldoc.xpath("//*[following::text()[1]"\
95
+ "[starts-with(., '\"') or starts-with(., \"'\")]]")
96
+ .each do |x|
97
+ next if !x.ancestors("pre, tt, sourcecode, stem, figure").empty?
98
+ uninterrupt_quotes_around_xml1(x)
99
+ end
100
+ end
101
+
102
+ def uninterrupt_quotes_around_xml1(elem)
103
+ prev = elem.at(".//preceding::text()[1]") or return
104
+ /\S$/.match?(prev.text) or return
105
+ foll = elem.at(".//following::text()[1]")
106
+ m = /^(["'][[:punct:]]*)(\s|$)/.match(HTMLEntities.new.decode(foll&.text)) or return
107
+ foll.content = foll.text.sub(/^(["'][[:punct:]]*)/, "")
108
+ prev.content = "#{prev.text}#{m[1]}"
109
+ end
110
+
111
+ def dumb2smart_quotes(xmldoc)
87
112
  (xmldoc.xpath("//*[child::text()]") - xmldoc.xpath(IGNORE_DUMBQUOTES))
88
113
  .each do |x|
89
114
  x.children.each do |n|
@@ -166,6 +191,42 @@ module Asciidoctor
166
191
  end
167
192
  end
168
193
  end
194
+
195
+ def toc_cleanup(xmldoc)
196
+ xmldoc.xpath("//p[toc]").each do |x|
197
+ x.xpath("./toc").reverse.each do |t|
198
+ x.next = t
199
+ end
200
+ x.remove if x.text.strip.empty?
201
+ end
202
+ xmldoc.xpath("//toc").each { |t| toc_cleanup1(t, xmldoc) }
203
+ end
204
+
205
+ def toc_index(toc, xmldoc)
206
+ depths = toc.xpath("./toc-xpath").each_with_object({}) do |x, m|
207
+ m[x.text] = x["depth"]
208
+ end
209
+ depths.keys.each_with_object([]) do |key, arr|
210
+ xmldoc.xpath(key).each do |x|
211
+ arr << { text: x.children.to_xml, depth: depths[key].to_i,
212
+ target: x.xpath("(./ancestor-or-self::*/@id)[last()]")[0].text,
213
+ line: x.line }
214
+ end
215
+ end.sort_by { |a| a[:line] }
216
+ end
217
+
218
+ def toc_cleanup1(toc, xmldoc)
219
+ depth = 1
220
+ ret = ""
221
+ toc_index(toc, xmldoc).each do |x|
222
+ if depth > x[:depth] then ret += "</ul></li>" * (depth - x[:depth])
223
+ elsif depth < x[:depth] then ret += "<li><ul>" * (x[:depth] - depth)
224
+ end
225
+ ret += "<li><xref target='#{x[:target]}'>#{x[:text]}</xref></li>"
226
+ depth = x[:depth]
227
+ end
228
+ toc.children = "<ul>#{ret}</ul>"
229
+ end
169
230
  end
170
231
  end
171
232
  end
@@ -7,8 +7,11 @@ module Asciidoctor
7
7
  def para_cleanup(xmldoc)
8
8
  ["//p[not(ancestor::bibdata)]", "//ol[not(ancestor::bibdata)]",
9
9
  "//ul[not(ancestor::bibdata)]", "//quote[not(ancestor::bibdata)]",
10
- "//note[not(ancestor::bibitem or ancestor::table or ancestor::bibdata)]"
11
- ].each { |w| inject_id(xmldoc, w) }
10
+ "//note[not(ancestor::bibitem or ancestor::table or ancestor::bibdata)]"].each do |w|
11
+ inject_id(
12
+ xmldoc, w
13
+ )
14
+ end
12
15
  end
13
16
 
14
17
  def inject_id(xmldoc, path)
@@ -205,7 +208,7 @@ module Asciidoctor
205
208
  def safe_noko(text, doc)
206
209
  Nokogiri::XML::Text.new(text, doc).to_xml(
207
210
  encoding: "US-ASCII",
208
- save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
211
+ save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION,
209
212
  )
210
213
  end
211
214
 
@@ -1,40 +1,41 @@
1
1
  module Asciidoctor
2
2
  module Standoc
3
3
  module Cleanup
4
- def requirement_cleanup(reqt)
5
- requirement_descriptions(reqt)
6
- requirement_inherit(reqt)
4
+ def requirement_cleanup(xmldoc)
5
+ requirement_metadata(xmldoc)
6
+ requirement_descriptions(xmldoc)
7
+ requirement_inherit(xmldoc)
7
8
  end
8
9
 
9
- def requirement_inherit(reqt)
10
- reqt.xpath("//requirement | //recommendation | //permission")
11
- .each do |r|
10
+ REQRECPER = "//requirement | //recommendation | //permission".freeze
11
+
12
+ def requirement_inherit(xmldoc)
13
+ xmldoc.xpath(REQRECPER).each do |r|
12
14
  ins = r.at("./classification") ||
13
15
  r.at("./description | ./measurementtarget | ./specification | "\
14
16
  "./verification | ./import | ./description | ./requirement | "\
15
- "./recommendation | ./permission")
17
+ "./recommendation | ./permission | ./component")
16
18
  r.xpath("./*//inherit").each { |i| ins.previous = i }
17
19
  end
18
20
  end
19
21
 
20
- def requirement_descriptions(reqt)
21
- reqt.xpath("//requirement | //recommendation | //permission")
22
- .each do |r|
22
+ def requirement_descriptions(xmldoc)
23
+ xmldoc.xpath(REQRECPER).each do |r|
23
24
  r.children.each do |e|
24
25
  unless e.element? && (reqt_subpart(e.name) ||
25
26
  %w(requirement recommendation permission).include?(e.name))
26
- t = Nokogiri::XML::Element.new("description", reqt)
27
+ t = Nokogiri::XML::Element.new("description", r)
27
28
  e.before(t)
28
29
  t.children = e.remove
29
30
  end
30
31
  end
31
- requirement_cleanup1(r)
32
+ requirement_description_cleanup1(r)
32
33
  end
33
34
  end
34
35
 
35
- def requirement_cleanup1(reqt)
36
+ def requirement_description_cleanup1(reqt)
36
37
  while d = reqt.at("./description[following-sibling::*[1]"\
37
- "[self::description]]")
38
+ "[self::description]]")
38
39
  n = d.next.remove
39
40
  d << n.children
40
41
  end
@@ -42,6 +43,50 @@ module Asciidoctor
42
43
  r.replace("\n")
43
44
  end
44
45
  end
46
+
47
+ def requirement_metadata(xmldoc)
48
+ xmldoc.xpath(REQRECPER).each do |r|
49
+ dl = r&.at("./dl[@metadata = 'true']")&.remove or next
50
+ requirement_metadata1(r, dl)
51
+ end
52
+ end
53
+
54
+ def requirement_metadata1(reqt, dlist)
55
+ unless ins = reqt.at("./title")
56
+ reqt.children.first.previous = " "
57
+ ins = reqt.children.first
58
+ end
59
+ %w(label subject inherit).each do |a|
60
+ ins = reqt_dl_to_elems(ins, reqt, dlist, a)
61
+ end
62
+ reqt_dl_to_classif(ins, reqt, dlist)
63
+ end
64
+
65
+ def reqt_dl_to_elems(ins, reqt, dlist, name)
66
+ if a = reqt.at("./#{name}[last()]")
67
+ ins = a
68
+ end
69
+ dlist.xpath("./dt[text()='#{name}']").each do |e|
70
+ val = e.at("./following::dd/p") || e.at("./following::dd")
71
+ val.name = name
72
+ ins.next = val
73
+ ins = ins.next
74
+ end
75
+ ins
76
+ end
77
+
78
+ def reqt_dl_to_classif(ins, reqt, dlist)
79
+ if a = reqt.at("./classification[last()]")
80
+ ins = a
81
+ end
82
+ dlist.xpath("./dt[text()='classification']").each do |e|
83
+ val = e.at("./following::dd/p") || e.at("./following::dd")
84
+ req_classif_parse(val.text).each do |r|
85
+ ins.next = "<classification><tag>#{r[0]}</tag>"\
86
+ "<value>#{r[1]}</value></classification>"
87
+ end
88
+ end
89
+ end
45
90
  end
46
91
  end
47
92
  end
@@ -27,6 +27,7 @@ module Asciidoctor
27
27
  preprocessor Metanorma::Plugin::Datastruct::Yaml2TextPreprocessor
28
28
  preprocessor Metanorma::Plugin::Lutaml::LutamlPreprocessor
29
29
  preprocessor Metanorma::Plugin::Lutaml::LutamlUmlAttributesTablePreprocessor
30
+ preprocessor Metanorma::Plugin::Lutaml::LutamlUmlDatamodelDescriptionPreprocessor
30
31
  inline_macro Asciidoctor::Standoc::AltTermInlineMacro
31
32
  inline_macro Asciidoctor::Standoc::DeprecatedTermInlineMacro
32
33
  inline_macro Asciidoctor::Standoc::DomainTermInlineMacro
@@ -47,6 +48,9 @@ module Asciidoctor
47
48
  inline_macro Asciidoctor::Standoc::FormTextareaMacro
48
49
  inline_macro Asciidoctor::Standoc::FormSelectMacro
49
50
  inline_macro Asciidoctor::Standoc::FormOptionMacro
51
+ inline_macro Asciidoctor::Standoc::ToCInlineMacro
52
+ inline_macro Metanorma::Plugin::Lutaml::LutamlFigureInlineMacro
53
+ block_macro Metanorma::Plugin::Lutaml::LutamlDiagramBlockMacro
50
54
  block Asciidoctor::Standoc::ToDoAdmonitionBlock
51
55
  treeprocessor Asciidoctor::Standoc::ToDoInlineAdmonitionBlock
52
56
  block Asciidoctor::Standoc::PlantUMLBlockMacro
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'erb'
4
- require 'asciidoctor/standoc/datamodel/plantuml_renderer'
3
+ require "erb"
4
+ require "asciidoctor/standoc/datamodel/plantuml_renderer"
5
5
 
6
6
  module Asciidoctor
7
7
  module Standoc
8
8
  module Datamodel
9
9
  class DiagramPreprocessor < Asciidoctor::Extensions::Preprocessor
10
- BLOCK_START_REGEXP = /\{(.+?)\.\*,(.+),(.+)\}/
11
- BLOCK_END_REGEXP = /\A\{[A-Z]+\}\z/
12
- MARCO_REGEXP = /\[datamodel_diagram,([^,]+),?(.+)?\]/
13
- TEMPLATES_PATH = File.expand_path('../views/datamodel', __dir__).freeze
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
14
  # search document for block `datamodel_diagram`
15
15
  # read include derectives that goes after that in block and transform
16
16
  # into plantuml block
@@ -33,7 +33,7 @@ module Asciidoctor
33
33
  end
34
34
 
35
35
  def parse_datamodel_marco(yaml_path, include_path, document)
36
- include_path ||= File.join(File.dirname(yaml_path), '..', 'models')
36
+ include_path ||= File.join(File.dirname(yaml_path), "..", "models")
37
37
  include_path = yaml_relative_path(include_path, document)
38
38
  yaml_relative_to_doc_path = yaml_relative_path(yaml_path, document)
39
39
  view_hash = YAML.safe_load(File.read(yaml_relative_to_doc_path))
@@ -43,7 +43,7 @@ module Asciidoctor
43
43
  end
44
44
 
45
45
  def yaml_relative_path(file_path, document)
46
- docfile = document.attributes['docfile'] || '.'
46
+ docfile = document.attributes["docfile"] || "."
47
47
  docfile_directory = File.dirname(docfile)
48
48
  document.path_resolver.system_path(file_path, docfile_directory)
49
49
  end
@@ -51,11 +51,11 @@ module Asciidoctor
51
51
  def import_format(include_path, import_name, values)
52
52
  include_content = File.read(File.join(
53
53
  include_path,
54
- "#{import_name}.yml"
55
- ))
54
+ "#{import_name}.yml",
55
+ ))
56
56
  content = YAML.safe_load(include_content)
57
57
  if values
58
- content['skipSection'] = values['skipSection']
58
+ content["skipSection"] = values["skipSection"]
59
59
  end
60
60
  content
61
61
  end
@@ -63,36 +63,37 @@ module Asciidoctor
63
63
  def format_import_directives(imports, include_path)
64
64
  imports
65
65
  .each_with_object({}) do |(import_name, values), res|
66
- full_model_name = import_name.split('/').join
66
+ full_model_name = import_name.split("/").join
67
67
  content = import_format(include_path, import_name, values)
68
- res[content['name'] || full_model_name] = content
68
+ res[content["name"] || full_model_name] = content
69
69
  end.compact
70
70
  end
71
71
 
72
72
  def prepare_view_hash(view_hash, all_imports)
73
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, 'class'))
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")),
79
80
  )
80
81
  end
81
82
 
82
83
  def model_type(imports, type)
83
84
  imports
84
85
  .select do |_name, elem|
85
- elem['modelType'] == type
86
+ elem["modelType"] == type
86
87
  end
87
88
  end
88
89
 
89
90
  def plantuml_representations(view_hash, view_path, include_path)
90
91
  yaml_directory = File.dirname(view_path)
91
- all_imports = format_import_directives(view_hash['imports'],
92
+ all_imports = format_import_directives(view_hash["imports"],
92
93
  include_path)
93
94
  prepare_view_hash(view_hash, all_imports)
94
95
  Asciidoctor::Datamodel::PlantumlRenderer
95
- .new(view_hash, File.join(yaml_directory, '..'))
96
+ .new(view_hash, File.join(yaml_directory, ".."))
96
97
  .render
97
98
  .split("\n")
98
99
  end