metanorma / metanorma-plugin-datastruct

Metanorma plugin that allows you to access static data structures like JSON, YAML, XML from a Metanorma document
BSD 2-Clause "Simplified" License
1 stars 1 forks source link

Support for YAML repeated nodes in Liquid #11

Closed manuelfuenmayor closed 3 years ago

manuelfuenmayor commented 3 years ago

In relation to https://github.com/ituob/service-publications-docs/issues/1

I'm getting Liquid error: internal on YAML files that contain repeated nodes.

Example:

---
groups:
  amateur: &general
    regex: O[F-J][:digit:][0-9A-Z]{3}[:upper:]{1}

  experimental: *general

being &general a node object, and *general the reference to that object.

ronaldtse commented 3 years ago

I think the problem here is the YAML parser not recognising repeated nodes? Or is the liquid filter not supporting that?

w00lf commented 3 years ago

ituob/service-publications-docs#1

Hi there @manuel489 can you please provide yaml2text, macro itself? It does not look like yaml error, it seems that you referencing not existing attribute

manuelfuenmayor commented 3 years ago

Hi @w00lf, sure. For example, taking the following yaml file:

#Finland
#Amateur stations and
#experimental stations:
#OF, OG, OH, OI or OJ followed by a digit and a group of not more than 4 characters, the last of which shall be a letter

groups:
  amateur: &general
    regex: O[F-J][:digit:][0-9A-Z]{3}[:upper:]{1}

  experimental: *general

a simple yaml2text macro would be:

[yaml2text,yaml_files/finland.yaml,data]
----
=== Findland

Amateur stations and experimental stations:: {{ data.groups.amateur.regex }}
----

This shows nothing in output. But if the yaml2text was nested into another yaml2text block, I get Liquid error: internal.

w00lf commented 3 years ago

@manuel489 fixed in https://github.com/metanorma/metanorma-plugin-datastruct/pull/12, released new version - 0.1.3, please update your gems

manuelfuenmayor commented 3 years ago

@w00lf, the issue is solved for simple yaml2text blocks, but I'm still getting Liquid error: internal on nested macros. For example:

[yaml2text,yaml_files/nicaragua.yaml,data]
----
=== Nicaragua

Amateur stations:: {{ data.groups.amateur.regex }}

[yaml2text,yaml_files/niger.yaml,data_two]
---
=== Niger

Amateur stations:: {{ data_two.groups.amateur.regex }}

Experimental:: {{ data_two.groups.experimental }}
---
----

Output: Capture1

This is necessary to loop through many yaml2text blocks. (As required in: 1154-RR.25.1 -- ituob/service-publications-docs#1.)

Thanks!

w00lf commented 3 years ago

@w00lf, the issue is solved for simple yaml2text blocks, but I'm still getting Liquid error: internal on nested macros. For example:

[yaml2text,yaml_files/nicaragua.yaml,data]
----
=== Nicaragua

Amateur stations:: {{ data.groups.amateur.regex }}

[yaml2text,yaml_files/niger.yaml,data_two]
---
=== Niger

Amateur stations:: {{ data_two.groups.amateur.regex }}

Experimental:: {{ data_two.groups.experimental }}
---
----

Output: Capture1

This is necessary to loop through many yaml2text blocks. (As required in: 1154-RR.25.1 -- ituob/service-publications-docs#1.)

Thanks!

@manuel489 fixed nested repeated node support, released version 0.1.4

ronaldtse commented 3 years ago

Thanks @w00lf !

manuelfuenmayor commented 3 years ago

@w00lf, I have updated to 0.1.4, but the issue still persists...

[yaml2text,yaml_files/country_names.yaml,file]
----
{% assign lang = "en" %}

{% assign filenames = "cote-divoire, croatia, cuba, curacao, cyprus, czech, denmark, djibouti, dominica, 
dominican-republic, ecuador, egypt, el-salvador, ethiopia, fiji, finland, gabon, haiti, hungary, india, 
indonesia, iran, iraq, ireland, israel, italy, jamaica, jordan, kenya, kiribati, korea, kuwait, kyrgyz, lao, 
latvia, lebanon, lesotho, libya, liechtenstein, lithuania, luxembourg, madagascar, malawi, maldives, 
mauritania, mauritius, micronesia, monaco, morocco, mozambique, myanmar, namibia, 
nauru, nepal, netherlands, nicaragua, niger" | split: ", " %}

{% for filename in filenames %}

{% assign country_name = file.data[filename][lang] %}

[yaml2text,yaml_files/{{ filename }}.yaml,data]
---

=== {{ country_name }}

---
{% endfor %}
----

Output: capture1

Related files: repeated_nodes.zip

w00lf commented 3 years ago

@manuel489 foudn another place where this one was used - https://github.com/metanorma/metanorma-standoc/pull/475 After this PR is merged and a new release of metnorma all should be fixed

manuelfuenmayor commented 3 years ago

Issue is fixed now. Thanks @w00lf ! Closing.