metanorma-standoc 1.5.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +66 -0
- data/README.adoc +1 -3
- data/lib/asciidoctor/standoc/base.rb +6 -1
- data/lib/asciidoctor/standoc/basicdoc.rng +23 -0
- data/lib/asciidoctor/standoc/cleanup.rb +79 -12
- data/lib/asciidoctor/standoc/cleanup_amend.rb +54 -0
- data/lib/asciidoctor/standoc/cleanup_block.rb +41 -6
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +14 -0
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +11 -3
- data/lib/asciidoctor/standoc/cleanup_inline.rb +11 -2
- data/lib/asciidoctor/standoc/cleanup_ref.rb +3 -4
- data/lib/asciidoctor/standoc/cleanup_section.rb +1 -2
- data/lib/asciidoctor/standoc/converter.rb +6 -2
- data/lib/asciidoctor/standoc/front.rb +9 -3
- data/lib/asciidoctor/standoc/front_contributor.rb +58 -18
- data/lib/asciidoctor/standoc/inline.rb +21 -31
- data/lib/asciidoctor/standoc/isodoc.rng +135 -58
- data/lib/asciidoctor/standoc/lists.rb +4 -2
- data/lib/asciidoctor/standoc/macros.rb +59 -33
- data/lib/asciidoctor/standoc/ref.rb +41 -46
- data/lib/asciidoctor/standoc/ref_sect.rb +12 -5
- data/lib/asciidoctor/standoc/section.rb +11 -10
- data/lib/asciidoctor/standoc/table.rb +3 -2
- data/lib/asciidoctor/standoc/views/datamodel/model_representation.adoc.erb +10 -10
- data/lib/liquid/custom_blocks/key_iterator.rb +21 -0
- data/lib/liquid/custom_blocks/with_json_nested_context.rb +18 -0
- data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +19 -0
- data/lib/liquid/custom_filters/values.rb +7 -0
- data/lib/metanorma/standoc.rb +0 -5
- data/lib/metanorma/standoc/version.rb +20 -1
- data/metanorma-standoc.gemspec +5 -4
- data/spec/asciidoctor-standoc/base_spec.rb +246 -9
- data/spec/asciidoctor-standoc/blocks_spec.rb +255 -143
- data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +1498 -0
- data/spec/asciidoctor-standoc/cleanup_spec.rb +409 -1572
- data/spec/asciidoctor-standoc/inline_spec.rb +128 -4
- data/spec/asciidoctor-standoc/isobib_cache_spec.rb +6 -20
- data/spec/asciidoctor-standoc/lists_spec.rb +10 -1
- data/spec/asciidoctor-standoc/macros_json2text_spec.rb +10 -0
- data/spec/asciidoctor-standoc/macros_lutaml_spec.rb +80 -0
- data/spec/asciidoctor-standoc/macros_spec.rb +36 -0
- data/spec/asciidoctor-standoc/macros_yaml2text_spec.rb +6 -561
- data/spec/asciidoctor-standoc/refs_dl_spec.rb +2 -2
- data/spec/asciidoctor-standoc/refs_spec.rb +266 -55
- data/spec/asciidoctor-standoc/section_spec.rb +0 -1
- data/spec/asciidoctor-standoc/table_spec.rb +112 -112
- data/spec/asciidoctor-standoc/validate_spec.rb +5 -1
- data/spec/examples/codes_table.html +1365 -1365
- data/spec/fixtures/macros_datamodel/address_class_profile.xml +46 -46
- data/spec/fixtures/macros_datamodel/address_component_profile.xml +21 -21
- data/spec/fixtures/macros_datamodel/blank_definition_profile.xml +21 -21
- data/spec/fixtures/test.exp +121 -0
- data/spec/spec_helper.rb +142 -108
- data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +781 -0
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +50 -234
- data/spec/vcr_cassettes/isobib_get_123.yml +13 -59
- data/spec/vcr_cassettes/isobib_get_123_1.yml +23 -115
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +361 -0
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +11 -57
- data/spec/vcr_cassettes/isobib_get_124.yml +13 -59
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +50 -36
- metadata +59 -11
- data/.github/workflows/macos.yml +0 -46
- data/.github/workflows/ubuntu.yml +0 -49
- data/.github/workflows/windows.yml +0 -53
- data/lib/asciidoctor/standoc/macros_yaml2text.rb +0 -165
- data/lib/metanorma/standoc/latexml_requirement.rb +0 -62
- 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.
|
4
|
+
version: 1.6.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-
|
11
|
+
date: 2020-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -67,19 +67,47 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.2.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
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: metanorma-plugin-lutaml
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: relaton-cli
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - "~>"
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.
|
103
|
+
version: 1.5.0
|
76
104
|
type: :runtime
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.
|
110
|
+
version: 1.5.0
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: relaton-iev
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +192,20 @@ dependencies:
|
|
164
192
|
- - ">="
|
165
193
|
- !ruby/object:Gem::Version
|
166
194
|
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: latexmath
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
167
209
|
- !ruby/object:Gem::Dependency
|
168
210
|
name: byebug
|
169
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -343,9 +385,7 @@ extensions: []
|
|
343
385
|
extra_rdoc_files: []
|
344
386
|
files:
|
345
387
|
- ".gitattributes"
|
346
|
-
- ".github/workflows/
|
347
|
-
- ".github/workflows/ubuntu.yml"
|
348
|
-
- ".github/workflows/windows.yml"
|
388
|
+
- ".github/workflows/rake.yml"
|
349
389
|
- ".gitignore"
|
350
390
|
- ".hound.yml"
|
351
391
|
- ".oss-guides.rubocop.yml"
|
@@ -367,6 +407,7 @@ files:
|
|
367
407
|
- lib/asciidoctor/standoc/blocks.rb
|
368
408
|
- lib/asciidoctor/standoc/blocks_notes.rb
|
369
409
|
- lib/asciidoctor/standoc/cleanup.rb
|
410
|
+
- lib/asciidoctor/standoc/cleanup_amend.rb
|
370
411
|
- lib/asciidoctor/standoc/cleanup_block.rb
|
371
412
|
- lib/asciidoctor/standoc/cleanup_boilerplate.rb
|
372
413
|
- lib/asciidoctor/standoc/cleanup_footnotes.rb
|
@@ -386,7 +427,6 @@ files:
|
|
386
427
|
- lib/asciidoctor/standoc/log.rb
|
387
428
|
- lib/asciidoctor/standoc/macros.rb
|
388
429
|
- lib/asciidoctor/standoc/macros_plantuml.rb
|
389
|
-
- lib/asciidoctor/standoc/macros_yaml2text.rb
|
390
430
|
- lib/asciidoctor/standoc/ref.rb
|
391
431
|
- lib/asciidoctor/standoc/ref_sect.rb
|
392
432
|
- lib/asciidoctor/standoc/reqt.rb
|
@@ -398,21 +438,26 @@ files:
|
|
398
438
|
- lib/asciidoctor/standoc/validate_section.rb
|
399
439
|
- lib/asciidoctor/standoc/views/datamodel/model_representation.adoc.erb
|
400
440
|
- lib/asciidoctor/standoc/views/datamodel/plantuml_representation.adoc.erb
|
441
|
+
- lib/liquid/custom_blocks/key_iterator.rb
|
442
|
+
- lib/liquid/custom_blocks/with_json_nested_context.rb
|
443
|
+
- lib/liquid/custom_blocks/with_yaml_nested_context.rb
|
444
|
+
- lib/liquid/custom_filters/values.rb
|
401
445
|
- lib/metanorma-standoc.rb
|
402
446
|
- lib/metanorma/standoc.rb
|
403
|
-
- lib/metanorma/standoc/latexml_requirement.rb
|
404
447
|
- lib/metanorma/standoc/processor.rb
|
405
|
-
- lib/metanorma/standoc/requirement.rb
|
406
448
|
- lib/metanorma/standoc/version.rb
|
407
449
|
- metanorma-standoc.gemspec
|
408
450
|
- spec/asciidoctor-standoc/base_spec.rb
|
409
451
|
- spec/asciidoctor-standoc/blocks_spec.rb
|
452
|
+
- spec/asciidoctor-standoc/cleanup_sections_spec.rb
|
410
453
|
- spec/asciidoctor-standoc/cleanup_spec.rb
|
411
454
|
- spec/asciidoctor-standoc/datamodel/attributes_table_preprocessor_spec.rb
|
412
455
|
- spec/asciidoctor-standoc/datamodel/diagram_preprocessor_spec.rb
|
413
456
|
- spec/asciidoctor-standoc/inline_spec.rb
|
414
457
|
- spec/asciidoctor-standoc/isobib_cache_spec.rb
|
415
458
|
- spec/asciidoctor-standoc/lists_spec.rb
|
459
|
+
- spec/asciidoctor-standoc/macros_json2text_spec.rb
|
460
|
+
- spec/asciidoctor-standoc/macros_lutaml_spec.rb
|
416
461
|
- spec/asciidoctor-standoc/macros_spec.rb
|
417
462
|
- spec/asciidoctor-standoc/macros_yaml2text_spec.rb
|
418
463
|
- spec/asciidoctor-standoc/refs_dl_spec.rb
|
@@ -484,11 +529,14 @@ files:
|
|
484
529
|
- spec/fixtures/macros_datamodel/blank_definition_profile.xml
|
485
530
|
- spec/fixtures/macros_datamodel/common_models_diagram.xml
|
486
531
|
- spec/fixtures/macros_datamodel/top_down_diagram.xml
|
532
|
+
- spec/fixtures/test.exp
|
487
533
|
- spec/metanorma/processor_spec.rb
|
488
534
|
- spec/spec_helper.rb
|
535
|
+
- spec/support/shared_examples/structured_data_2_text_preprocessor.rb
|
489
536
|
- spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml
|
490
537
|
- spec/vcr_cassettes/isobib_get_123.yml
|
491
538
|
- spec/vcr_cassettes/isobib_get_123_1.yml
|
539
|
+
- spec/vcr_cassettes/isobib_get_123_1_fr.yml
|
492
540
|
- spec/vcr_cassettes/isobib_get_123_2001.yml
|
493
541
|
- spec/vcr_cassettes/isobib_get_124.yml
|
494
542
|
- spec/vcr_cassettes/rfcbib_get_rfc8341.yml
|
data/.github/workflows/macos.yml
DELETED
@@ -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
|