metanorma-standoc 1.5.2 → 1.5.3

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor/standoc/base_structured_text_preprocessor.rb +123 -0
  3. data/lib/asciidoctor/standoc/basicdoc.rng +31 -1
  4. data/lib/asciidoctor/standoc/cleanup.rb +1 -0
  5. data/lib/asciidoctor/standoc/cleanup_amend.rb +54 -0
  6. data/lib/asciidoctor/standoc/cleanup_block.rb +0 -2
  7. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +0 -3
  8. data/lib/asciidoctor/standoc/cleanup_inline.rb +6 -1
  9. data/lib/asciidoctor/standoc/cleanup_section.rb +1 -2
  10. data/lib/asciidoctor/standoc/converter.rb +3 -1
  11. data/lib/asciidoctor/standoc/front_contributor.rb +15 -7
  12. data/lib/asciidoctor/standoc/inline.rb +13 -1
  13. data/lib/asciidoctor/standoc/isodoc.rng +108 -8
  14. data/lib/asciidoctor/standoc/json2_text_preprocessor.rb +43 -0
  15. data/lib/asciidoctor/standoc/macros.rb +45 -33
  16. data/lib/asciidoctor/standoc/section.rb +8 -3
  17. data/lib/asciidoctor/standoc/table.rb +3 -2
  18. data/lib/asciidoctor/standoc/views/datamodel/model_representation.adoc.erb +10 -10
  19. data/lib/asciidoctor/standoc/yaml2_text_preprocessor.rb +43 -0
  20. data/lib/liquid/custom_blocks/key_iterator.rb +21 -0
  21. data/lib/liquid/custom_filters/values.rb +7 -0
  22. data/lib/metanorma/standoc/version.rb +1 -1
  23. data/metanorma-standoc.gemspec +1 -3
  24. data/spec/asciidoctor-standoc/blocks_spec.rb +254 -142
  25. data/spec/asciidoctor-standoc/cleanup_spec.rb +31 -31
  26. data/spec/asciidoctor-standoc/macros_json2text_spec.rb +10 -0
  27. data/spec/asciidoctor-standoc/macros_spec.rb +2 -0
  28. data/spec/asciidoctor-standoc/macros_yaml2text_spec.rb +5 -560
  29. data/spec/asciidoctor-standoc/section_spec.rb +0 -1
  30. data/spec/asciidoctor-standoc/table_spec.rb +112 -112
  31. data/spec/asciidoctor-standoc/validate_spec.rb +5 -1
  32. data/spec/examples/codes_table.html +1365 -1365
  33. data/spec/fixtures/macros_datamodel/address_class_profile.xml +46 -46
  34. data/spec/fixtures/macros_datamodel/address_component_profile.xml +21 -21
  35. data/spec/fixtures/macros_datamodel/blank_definition_profile.xml +21 -21
  36. data/spec/spec_helper.rb +110 -109
  37. data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +583 -0
  38. metadata +24 -3
  39. data/lib/asciidoctor/standoc/macros_yaml2text.rb +0 -165
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: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-27 00:00:00.000000000 Z
11
+ date: 2020-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: latexmath
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: byebug
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -362,11 +376,13 @@ files:
362
376
  - bin/rspec
363
377
  - docs/quickstart.adoc
364
378
  - lib/asciidoctor/standoc/base.rb
379
+ - lib/asciidoctor/standoc/base_structured_text_preprocessor.rb
365
380
  - lib/asciidoctor/standoc/basicdoc.rng
366
381
  - lib/asciidoctor/standoc/biblio.rng
367
382
  - lib/asciidoctor/standoc/blocks.rb
368
383
  - lib/asciidoctor/standoc/blocks_notes.rb
369
384
  - lib/asciidoctor/standoc/cleanup.rb
385
+ - lib/asciidoctor/standoc/cleanup_amend.rb
370
386
  - lib/asciidoctor/standoc/cleanup_block.rb
371
387
  - lib/asciidoctor/standoc/cleanup_boilerplate.rb
372
388
  - lib/asciidoctor/standoc/cleanup_footnotes.rb
@@ -382,11 +398,11 @@ files:
382
398
  - lib/asciidoctor/standoc/front_contributor.rb
383
399
  - lib/asciidoctor/standoc/inline.rb
384
400
  - lib/asciidoctor/standoc/isodoc.rng
401
+ - lib/asciidoctor/standoc/json2_text_preprocessor.rb
385
402
  - lib/asciidoctor/standoc/lists.rb
386
403
  - lib/asciidoctor/standoc/log.rb
387
404
  - lib/asciidoctor/standoc/macros.rb
388
405
  - lib/asciidoctor/standoc/macros_plantuml.rb
389
- - lib/asciidoctor/standoc/macros_yaml2text.rb
390
406
  - lib/asciidoctor/standoc/ref.rb
391
407
  - lib/asciidoctor/standoc/ref_sect.rb
392
408
  - lib/asciidoctor/standoc/reqt.rb
@@ -398,6 +414,9 @@ files:
398
414
  - lib/asciidoctor/standoc/validate_section.rb
399
415
  - lib/asciidoctor/standoc/views/datamodel/model_representation.adoc.erb
400
416
  - lib/asciidoctor/standoc/views/datamodel/plantuml_representation.adoc.erb
417
+ - lib/asciidoctor/standoc/yaml2_text_preprocessor.rb
418
+ - lib/liquid/custom_blocks/key_iterator.rb
419
+ - lib/liquid/custom_filters/values.rb
401
420
  - lib/metanorma-standoc.rb
402
421
  - lib/metanorma/standoc.rb
403
422
  - lib/metanorma/standoc/latexml_requirement.rb
@@ -413,6 +432,7 @@ files:
413
432
  - spec/asciidoctor-standoc/inline_spec.rb
414
433
  - spec/asciidoctor-standoc/isobib_cache_spec.rb
415
434
  - spec/asciidoctor-standoc/lists_spec.rb
435
+ - spec/asciidoctor-standoc/macros_json2text_spec.rb
416
436
  - spec/asciidoctor-standoc/macros_spec.rb
417
437
  - spec/asciidoctor-standoc/macros_yaml2text_spec.rb
418
438
  - spec/asciidoctor-standoc/refs_dl_spec.rb
@@ -486,6 +506,7 @@ files:
486
506
  - spec/fixtures/macros_datamodel/top_down_diagram.xml
487
507
  - spec/metanorma/processor_spec.rb
488
508
  - spec/spec_helper.rb
509
+ - spec/support/shared_examples/structured_data_2_text_preprocessor.rb
489
510
  - spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml
490
511
  - spec/vcr_cassettes/isobib_get_123.yml
491
512
  - spec/vcr_cassettes/isobib_get_123_1.yml
@@ -1,165 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ostruct'
4
-
5
- module Asciidoctor
6
- module Standoc
7
- class YamlBlockStruct < OpenStruct
8
- def to_a
9
- @table.to_h.keys
10
- end
11
-
12
- def values
13
- @table.to_h.values
14
- end
15
-
16
- def each
17
- return to_a.each unless block_given?
18
-
19
- to_a.each do |key|
20
- yield(key)
21
- end
22
- end
23
- end
24
-
25
- class YamlContextRenderer
26
- attr_reader :context_object, :context_name
27
-
28
- def initialize(context_object:, context_name:)
29
- @context_object = context_object
30
- @context_name = context_name
31
- end
32
-
33
- def respond_to_missing?(name)
34
- respond_to?(name)
35
- end
36
-
37
- def method_missing(name, *_args)
38
- return context_object if name.to_s == context_name
39
-
40
- super
41
- end
42
-
43
- def render(template)
44
- ERB.new(template).result(binding)
45
- end
46
- end
47
-
48
- class Yaml2TextPreprocessor < Asciidoctor::Extensions::Preprocessor
49
- BLOCK_START_REGEXP = /\{(.+?)\.\*,(.+),(.+)\}/
50
- BLOCK_END_REGEXP = /\A\{[A-Z]+\}\z/
51
- # search document for block `yaml2text`
52
- # after that take template from block and read file into this template
53
- # example:
54
- # [yaml2text,foobar.yaml]
55
- # ----
56
- # === {item.name}
57
- # {item.desc}
58
- #
59
- # {item.symbol}:: {item.symbol_def}
60
- # ----
61
- #
62
- # with content of `foobar.yaml` file equal to:
63
- # - name: spaghetti
64
- # desc: wheat noodles of 9mm diameter
65
- # symbol: SPAG
66
- # symbol_def: the situation is message like spaghetti at a kid's
67
- #
68
- # will produce:
69
- # === spaghetti
70
- # wheat noodles of 9mm diameter
71
- #
72
- # SPAG:: the situation is message like spaghetti at a kid's meal
73
- def process(document, reader)
74
- input_lines = reader.readlines.to_enum
75
- Reader.new(processed_lines(document, input_lines))
76
- end
77
-
78
- private
79
-
80
- def processed_lines(document, input_lines)
81
- result = []
82
- current_macro_line_num = 0
83
- loop do
84
- line = input_lines.next
85
- current_macro_line_num += 1
86
- if yaml_block_match = line.match(/^\[yaml2text,(.+?),(.+?)\]/)
87
- mark = input_lines.next
88
- current_yaml_block = []
89
- while (yaml_block_line = input_lines.next) != mark
90
- current_yaml_block.push(yaml_block_line)
91
- end
92
- result.push(*read_yaml_and_parse_template(current_yaml_block,
93
- document,
94
- yaml_block_match,
95
- current_macro_line_num))
96
- else
97
- result.push(line)
98
- end
99
- end
100
- result
101
- end
102
-
103
- def read_yaml_and_parse_template(current_yaml_block, document, yaml_block_match, current_macro_line_num)
104
- content = nested_open_struct_from_yaml(yaml_block_match[1], document)
105
- parse_blocks_recursively(lines: current_yaml_block,
106
- attributes: content,
107
- context_name: yaml_block_match[2])
108
- rescue StandardError => exception
109
- document
110
- .logger
111
- .warn("Failed to parse yaml2text block on line #{current_macro_line_num}: #{exception.message}")
112
- []
113
- end
114
-
115
- def nested_open_struct_from_yaml(file_path, document)
116
- docfile_directory = File.dirname(document.attributes['docfile'] || '.')
117
- yaml_file_path = document
118
- .path_resolver
119
- .system_path(file_path, docfile_directory)
120
- content = YAML.safe_load(File.read(yaml_file_path))
121
- # Load content as json, then parse with JSON as nested open_struct
122
- JSON.parse(content.to_json, object_class: YamlBlockStruct)
123
- end
124
-
125
- def parse_blocks_recursively(lines:,
126
- attributes:,
127
- context_name:)
128
- lines = lines.to_enum
129
- result = []
130
- loop do
131
- line = lines.next
132
- if line.match?(BLOCK_START_REGEXP)
133
- line.gsub!(BLOCK_START_REGEXP,
134
- '<% \1.each&.with_index do |\2,index| %>')
135
- end
136
-
137
- if line.strip.match?(BLOCK_END_REGEXP)
138
- line.gsub!(BLOCK_END_REGEXP, '<% end %>')
139
- end
140
- line.gsub!(/{\s*if\s*([^}]+)}/, '<% if \1 %>')
141
- line.gsub!(/{\s*?end\s*?}/, '<% end %>')
142
- line = line
143
- .gsub(/{(.+?[^}]*)}/, '<%= \1 %>')
144
- .gsub(/[a-z\.]+\#/, 'index')
145
- result.push(line)
146
- end
147
- result = parse_context_block(context_lines: result,
148
- context_items: attributes,
149
- context_name: context_name)
150
- result
151
- end
152
-
153
- def parse_context_block(context_lines:,
154
- context_items:,
155
- context_name:)
156
- renderer = YamlContextRenderer
157
- .new(
158
- context_object: context_items,
159
- context_name: context_name
160
- )
161
- renderer.render(context_lines.join("\n")).split("\n")
162
- end
163
- end
164
- end
165
- end