From f25d8c5ff0b35ad33c292019eb3bda6205a64fda Mon Sep 17 00:00:00 2001 From: Michael Sauter Date: Tue, 7 Nov 2023 21:14:26 +0100 Subject: [PATCH] Support XML files --- CHANGELOG.md | 4 ++++ build/docs/render.adoc | 4 ++-- cmd/render/decode.go | 3 +++ docs/render.adoc | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64dd3de..5a53240 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ listed in the changelog. ## [Unreleased] +### Added + +- Support for XML files ([#3](https://github.com/opendevstack/ods-pipeline-adoc/issues/3)) + ## [0.1.0] - 2023-11-06 Initial version. diff --git a/build/docs/render.adoc b/build/docs/render.adoc index 6c28725..d57c9c2 100644 --- a/build/docs/render.adoc +++ b/build/docs/render.adoc @@ -1,4 +1,4 @@ -The purpose of this task is to render a asciidoc template located in the repository into a PDF. In addition to just transforming the asciidoc file to PDF, the task is also able to render information gathered from YAML/JSON files (such as ODS Pipeline artifacts) into the asciidoc file before transforming it to PDF. +The purpose of this task is to render a asciidoc template located in the repository into a PDF. In addition to just transforming the asciidoc file to PDF, the task is also able to render information gathered from YAML/JSON/XML files (such as ODS Pipeline artifacts) into the asciidoc file before transforming it to PDF. The task expects a glob pattern pointing to one or more Go template files (given by parameter `template`). It renders each found Go template with data gathered from files matching the `data-sources` parameter, which defaults to `.ods/\*,.ods/repos/*/.ods/\*,.ods/artifacts/*/\*.json,.ods/artifacts/*/*.yaml`. The asciidoc template can then access data parsed from these files. For example, if file `.ods/artifacts/org.foo/some.json` contains: @@ -8,7 +8,7 @@ The task expects a glob pattern pointing to one or more Go template files (given The asciidoc template can access the value of the field `a` by referencing `{{.ods.artifacts.org_foo.some.a}}`. Note that any non-alphanumeric character in the file path is replaced with an underscore, and leading or trailing underscores are trimmed. -Note that only JSON and YAML formats are recognized as such. If a matching file does not end in either `.json` or `.y(a)ml`, its entire content is made available under the key `value`. For example, the glob pattern `*.log` might match the file `pipeline-run.log`, which would expose the content of the file as `pipeline_run.value` to the template. +Note that only YAML, JSON, and XML formats are recognized as such. If a matching file does not end in `.y(a)ml`, `.json` or `.xml`, its entire content is made available under the key `value`. For example, the glob pattern `*.log` might match the file `pipeline-run.log`, which would expose the content of the file as `pipeline_run.value` to the template. The Go template can make use of template functions provided by link:http://masterminds.github.io/sprig/[sprig], as well as the following helper functions: diff --git a/cmd/render/decode.go b/cmd/render/decode.go index 49b41b4..deed1ea 100644 --- a/cmd/render/decode.go +++ b/cmd/render/decode.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "encoding/xml" "errors" "io" "strings" @@ -58,6 +59,8 @@ func selectNewDecoderFunc(ext string) newDecoderFunc { return func(r io.Reader) decoder { return json.NewDecoder(r) } case ".yaml", ".yml": return func(r io.Reader) decoder { return &yamlDecoder{r} } + case ".xml": + return func(r io.Reader) decoder { return xml.NewDecoder(r) } } return func(r io.Reader) decoder { return &plainDecoder{r} } } diff --git a/docs/render.adoc b/docs/render.adoc index 90e3006..1759fc2 100644 --- a/docs/render.adoc +++ b/docs/render.adoc @@ -2,7 +2,7 @@ = ods-pipeline-adoc-render -The purpose of this task is to render a asciidoc template located in the repository into a PDF. In addition to just transforming the asciidoc file to PDF, the task is also able to render information gathered from YAML/JSON files (such as ODS Pipeline artifacts) into the asciidoc file before transforming it to PDF. +The purpose of this task is to render a asciidoc template located in the repository into a PDF. In addition to just transforming the asciidoc file to PDF, the task is also able to render information gathered from YAML/JSON/XML files (such as ODS Pipeline artifacts) into the asciidoc file before transforming it to PDF. The task expects a glob pattern pointing to one or more Go template files (given by parameter `template`). It renders each found Go template with data gathered from files matching the `data-sources` parameter, which defaults to `.ods/\*,.ods/repos/*/.ods/\*,.ods/artifacts/*/\*.json,.ods/artifacts/*/*.yaml`. The asciidoc template can then access data parsed from these files. For example, if file `.ods/artifacts/org.foo/some.json` contains: @@ -12,7 +12,7 @@ The task expects a glob pattern pointing to one or more Go template files (given The asciidoc template can access the value of the field `a` by referencing `{{.ods.artifacts.org_foo.some.a}}`. Note that any non-alphanumeric character in the file path is replaced with an underscore, and leading or trailing underscores are trimmed. -Note that only JSON and YAML formats are recognized as such. If a matching file does not end in either `.json` or `.y(a)ml`, its entire content is made available under the key `value`. For example, the glob pattern `*.log` might match the file `pipeline-run.log`, which would expose the content of the file as `pipeline_run.value` to the template. +Note that only YAML, JSON, and XML formats are recognized as such. If a matching file does not end in `.y(a)ml`, `.json` or `.xml`, its entire content is made available under the key `value`. For example, the glob pattern `*.log` might match the file `pipeline-run.log`, which would expose the content of the file as `pipeline_run.value` to the template. The Go template can make use of template functions provided by link:http://masterminds.github.io/sprig/[sprig], as well as the following helper functions: