metanorma-standoc 1.5.1 → 1.6.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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +62 -0
  3. data/lib/asciidoctor/standoc/base.rb +7 -2
  4. data/lib/asciidoctor/standoc/basicdoc.rng +23 -0
  5. data/lib/asciidoctor/standoc/cleanup.rb +32 -12
  6. data/lib/asciidoctor/standoc/cleanup_amend.rb +54 -0
  7. data/lib/asciidoctor/standoc/cleanup_block.rb +0 -2
  8. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +14 -0
  9. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +11 -3
  10. data/lib/asciidoctor/standoc/cleanup_inline.rb +62 -1
  11. data/lib/asciidoctor/standoc/cleanup_ref.rb +6 -5
  12. data/lib/asciidoctor/standoc/cleanup_section.rb +19 -3
  13. data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -2
  14. data/lib/asciidoctor/standoc/converter.rb +4 -2
  15. data/lib/asciidoctor/standoc/front.rb +9 -3
  16. data/lib/asciidoctor/standoc/front_contributor.rb +58 -18
  17. data/lib/asciidoctor/standoc/inline.rb +21 -31
  18. data/lib/asciidoctor/standoc/isodoc.rng +125 -58
  19. data/lib/asciidoctor/standoc/log.rb +10 -1
  20. data/lib/asciidoctor/standoc/macros.rb +44 -33
  21. data/lib/asciidoctor/standoc/ref.rb +39 -44
  22. data/lib/asciidoctor/standoc/ref_sect.rb +12 -5
  23. data/lib/asciidoctor/standoc/section.rb +11 -10
  24. data/lib/asciidoctor/standoc/table.rb +3 -2
  25. data/lib/asciidoctor/standoc/utils.rb +2 -1
  26. data/lib/asciidoctor/standoc/validate.rb +30 -18
  27. data/lib/asciidoctor/standoc/validate_section.rb +1 -1
  28. data/lib/asciidoctor/standoc/views/datamodel/model_representation.adoc.erb +10 -10
  29. data/lib/liquid/custom_blocks/key_iterator.rb +21 -0
  30. data/lib/liquid/custom_blocks/with_json_nested_context.rb +18 -0
  31. data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +19 -0
  32. data/lib/liquid/custom_filters/values.rb +7 -0
  33. data/lib/metanorma/standoc.rb +0 -5
  34. data/lib/metanorma/standoc/version.rb +20 -1
  35. data/metanorma-standoc.gemspec +4 -4
  36. data/spec/asciidoctor-standoc/base_spec.rb +248 -10
  37. data/spec/asciidoctor-standoc/blocks_spec.rb +263 -144
  38. data/spec/asciidoctor-standoc/cleanup_spec.rb +199 -50
  39. data/spec/asciidoctor-standoc/inline_spec.rb +132 -5
  40. data/spec/asciidoctor-standoc/isobib_cache_spec.rb +13 -27
  41. data/spec/asciidoctor-standoc/macros_json2text_spec.rb +10 -0
  42. data/spec/asciidoctor-standoc/macros_spec.rb +43 -23
  43. data/spec/asciidoctor-standoc/macros_yaml2text_spec.rb +6 -561
  44. data/spec/asciidoctor-standoc/refs_dl_spec.rb +5 -3
  45. data/spec/asciidoctor-standoc/refs_spec.rb +268 -57
  46. data/spec/asciidoctor-standoc/section_spec.rb +0 -1
  47. data/spec/asciidoctor-standoc/table_spec.rb +119 -113
  48. data/spec/asciidoctor-standoc/validate_spec.rb +27 -1
  49. data/spec/examples/codes_table.html +1365 -1365
  50. data/spec/fixtures/macros_datamodel/address_class_profile.xml +46 -46
  51. data/spec/fixtures/macros_datamodel/address_component_profile.xml +21 -21
  52. data/spec/fixtures/macros_datamodel/blank_definition_profile.xml +21 -21
  53. data/spec/spec_helper.rb +115 -109
  54. data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +781 -0
  55. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +54 -238
  56. data/spec/vcr_cassettes/isobib_get_123.yml +14 -60
  57. data/spec/vcr_cassettes/isobib_get_123_1.yml +24 -116
  58. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +361 -0
  59. data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -60
  60. data/spec/vcr_cassettes/isobib_get_124.yml +11 -57
  61. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  62. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +39 -37
  63. metadata +42 -11
  64. data/.github/workflows/macos.yml +0 -46
  65. data/.github/workflows/ubuntu.yml +0 -49
  66. data/.github/workflows/windows.yml +0 -53
  67. data/lib/asciidoctor/standoc/macros_yaml2text.rb +0 -165
  68. data/lib/metanorma/standoc/latexml_requirement.rb +0 -62
  69. data/lib/metanorma/standoc/requirement.rb +0 -13
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.1
4
+ version: 1.6.2
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-14 00:00:00.000000000 Z
11
+ date: 2020-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -67,19 +67,33 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.2.1
69
69
  - !ruby/object:Gem::Dependency
70
- name: relaton
70
+ name: metanorma-plugin-datastruct
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: relaton-cli
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 1.2.0
89
+ version: 1.5.0
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 1.2.0
96
+ version: 1.5.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: relaton-iev
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +178,20 @@ dependencies:
164
178
  - - ">="
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: latexmath
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
167
195
  - !ruby/object:Gem::Dependency
168
196
  name: byebug
169
197
  requirement: !ruby/object:Gem::Requirement
@@ -343,9 +371,7 @@ extensions: []
343
371
  extra_rdoc_files: []
344
372
  files:
345
373
  - ".gitattributes"
346
- - ".github/workflows/macos.yml"
347
- - ".github/workflows/ubuntu.yml"
348
- - ".github/workflows/windows.yml"
374
+ - ".github/workflows/rake.yml"
349
375
  - ".gitignore"
350
376
  - ".hound.yml"
351
377
  - ".oss-guides.rubocop.yml"
@@ -367,6 +393,7 @@ files:
367
393
  - lib/asciidoctor/standoc/blocks.rb
368
394
  - lib/asciidoctor/standoc/blocks_notes.rb
369
395
  - lib/asciidoctor/standoc/cleanup.rb
396
+ - lib/asciidoctor/standoc/cleanup_amend.rb
370
397
  - lib/asciidoctor/standoc/cleanup_block.rb
371
398
  - lib/asciidoctor/standoc/cleanup_boilerplate.rb
372
399
  - lib/asciidoctor/standoc/cleanup_footnotes.rb
@@ -386,7 +413,6 @@ files:
386
413
  - lib/asciidoctor/standoc/log.rb
387
414
  - lib/asciidoctor/standoc/macros.rb
388
415
  - lib/asciidoctor/standoc/macros_plantuml.rb
389
- - lib/asciidoctor/standoc/macros_yaml2text.rb
390
416
  - lib/asciidoctor/standoc/ref.rb
391
417
  - lib/asciidoctor/standoc/ref_sect.rb
392
418
  - lib/asciidoctor/standoc/reqt.rb
@@ -398,11 +424,13 @@ files:
398
424
  - lib/asciidoctor/standoc/validate_section.rb
399
425
  - lib/asciidoctor/standoc/views/datamodel/model_representation.adoc.erb
400
426
  - lib/asciidoctor/standoc/views/datamodel/plantuml_representation.adoc.erb
427
+ - lib/liquid/custom_blocks/key_iterator.rb
428
+ - lib/liquid/custom_blocks/with_json_nested_context.rb
429
+ - lib/liquid/custom_blocks/with_yaml_nested_context.rb
430
+ - lib/liquid/custom_filters/values.rb
401
431
  - lib/metanorma-standoc.rb
402
432
  - lib/metanorma/standoc.rb
403
- - lib/metanorma/standoc/latexml_requirement.rb
404
433
  - lib/metanorma/standoc/processor.rb
405
- - lib/metanorma/standoc/requirement.rb
406
434
  - lib/metanorma/standoc/version.rb
407
435
  - metanorma-standoc.gemspec
408
436
  - spec/asciidoctor-standoc/base_spec.rb
@@ -413,6 +441,7 @@ files:
413
441
  - spec/asciidoctor-standoc/inline_spec.rb
414
442
  - spec/asciidoctor-standoc/isobib_cache_spec.rb
415
443
  - spec/asciidoctor-standoc/lists_spec.rb
444
+ - spec/asciidoctor-standoc/macros_json2text_spec.rb
416
445
  - spec/asciidoctor-standoc/macros_spec.rb
417
446
  - spec/asciidoctor-standoc/macros_yaml2text_spec.rb
418
447
  - spec/asciidoctor-standoc/refs_dl_spec.rb
@@ -486,9 +515,11 @@ files:
486
515
  - spec/fixtures/macros_datamodel/top_down_diagram.xml
487
516
  - spec/metanorma/processor_spec.rb
488
517
  - spec/spec_helper.rb
518
+ - spec/support/shared_examples/structured_data_2_text_preprocessor.rb
489
519
  - spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml
490
520
  - spec/vcr_cassettes/isobib_get_123.yml
491
521
  - spec/vcr_cassettes/isobib_get_123_1.yml
522
+ - spec/vcr_cassettes/isobib_get_123_1_fr.yml
492
523
  - spec/vcr_cassettes/isobib_get_123_2001.yml
493
524
  - spec/vcr_cassettes/isobib_get_124.yml
494
525
  - spec/vcr_cassettes/rfcbib_get_rfc8341.yml
@@ -1,46 +0,0 @@
1
- # Auto-generated by Cimas: Do not edit it manually!
2
- # See https://github.com/metanorma/cimas
3
- name: macos
4
-
5
- on:
6
- push:
7
- branches: [ master ]
8
- pull_request:
9
- paths-ignore:
10
- - .github/workflows/ubuntu.yml
11
- - .github/workflows/windows.yml
12
-
13
- jobs:
14
- test-macos:
15
- name: Test on Ruby ${{ matrix.ruby }} macOS
16
- runs-on: macos-latest
17
- continue-on-error: ${{ matrix.experimental }}
18
- strategy:
19
- fail-fast: false
20
- matrix:
21
- ruby: [ '2.6', '2.5', '2.4' ]
22
- experimental: [false]
23
- include:
24
- - ruby: '2.7'
25
- experimental: true
26
- steps:
27
- - uses: actions/checkout@master
28
- - name: Use Ruby
29
- uses: actions/setup-ruby@v1
30
- with:
31
- ruby-version: ${{ matrix.ruby }}
32
- - name: Install LaTeXML
33
- run: |
34
- brew install libxml2 cpanminus
35
- env PATH=$(brew --prefix libxml2)/bin:$PATH \
36
- cpanm --notest XML::LibXSLT@1.96 git://github.com/brucemiller/LaTeXML.git@9a0e7dc5
37
- - name: Install PlantUML
38
- run: |
39
- brew install plantuml
40
- - name: Update gems
41
- run: |
42
- sudo gem install bundler --force
43
- bundle install --jobs 4 --retry 3
44
- - name: Run specs
45
- run: |
46
- env PATH=$(brew --prefix perl)/bin:$PATH bundle exec rake
@@ -1,49 +0,0 @@
1
- # Auto-generated by Cimas: Do not edit it manually!
2
- # See https://github.com/metanorma/cimas
3
- name: ubuntu
4
-
5
- on:
6
- push:
7
- branches: [ master ]
8
- pull_request:
9
- paths-ignore:
10
- - .github/workflows/macos.yml
11
- - .github/workflows/windows.yml
12
-
13
- jobs:
14
- test-linux:
15
- name: Test on Ruby ${{ matrix.ruby }} Ubuntu
16
- runs-on: ubuntu-latest
17
- continue-on-error: ${{ matrix.experimental }}
18
- strategy:
19
- fail-fast: false
20
- matrix:
21
- ruby: [ '2.6', '2.5', '2.4' ]
22
- experimental: [false]
23
- include:
24
- - ruby: '2.7'
25
- experimental: true
26
- steps:
27
- - uses: actions/checkout@master
28
- - name: Use Ruby
29
- uses: actions/setup-ruby@v1
30
- with:
31
- ruby-version: ${{ matrix.ruby }}
32
- - name: Update gems
33
- run: |
34
- gem install bundler
35
- bundle install --jobs 4 --retry 3
36
- - name: Install LaTeXML
37
- run: |
38
- sudo snap install latexml --edge
39
- echo "::add-path::/snap/bin"
40
- - name: Install PlantUML
41
- uses: nick-invision/retry@v1
42
- with:
43
- polling_interval_seconds: 5
44
- timeout_minutes: 5
45
- max_attempts: 3
46
- command: sudo apt-get update -y && sudo bash -c "curl -L https://github.com/metanorma/plantuml-install/raw/master/ubuntu.sh | bash"
47
- - name: Run specs
48
- run: |
49
- bundle exec rake
@@ -1,53 +0,0 @@
1
- # Auto-generated by Cimas: Do not edit it manually!
2
- # See https://github.com/metanorma/cimas
3
- name: windows
4
-
5
- on:
6
- push:
7
- branches: [ master ]
8
- pull_request:
9
- paths-ignore:
10
- - .github/workflows/macos.yml
11
- - .github/workflows/ubuntu.yml
12
-
13
- jobs:
14
- test-windows:
15
- name: Test on Ruby ${{ matrix.ruby }} Windows
16
- runs-on: windows-latest
17
- continue-on-error: ${{ matrix.experimental }}
18
- strategy:
19
- fail-fast: false
20
- matrix:
21
- ruby: [ '2.6', '2.5', '2.4' ]
22
- experimental: [false]
23
- include:
24
- - ruby: '2.7'
25
- experimental: true
26
- steps:
27
- - uses: actions/checkout@master
28
- - name: Use Ruby
29
- uses: actions/setup-ruby@v1
30
- with:
31
- ruby-version: ${{ matrix.ruby }}
32
- - name: Install MN Windows dependencies
33
- shell: pwsh
34
- run: |
35
- choco install --no-progress plantuml make sed gnuwin32-coreutils.install grep
36
- - name: Update gems
37
- shell: pwsh
38
- run: |
39
- gem install bundler
40
- bundle config --local path vendor/bundle
41
- bundle install --jobs 4 --retry 3
42
- - name: Install LaTeXML
43
- shell: cmd
44
- run: |
45
- cinst -y latexml
46
- refreshenv
47
- set PATH=C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;%PATH%
48
- where latexmlmath
49
- - name: Run specs
50
- shell: pwsh
51
- run: |
52
- $env:Path = "C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;$env:Path"
53
- bundle exec rake
@@ -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