Skip to content

Commit

Permalink
Merge pull request #538 from metanorma/fix/metadata-recursive-hash
Browse files Browse the repository at this point in the history
Fix/metadata recursive hash
  • Loading branch information
opoudjis authored Oct 13, 2023
2 parents 684ce0e + 8cec6b2 commit 5f5285d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/isodoc/function/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
module IsoDoc
module Function
module Utils
Hash.include Metanorma::Utils::Hash
Array.include Metanorma::Utils::Array

def to_xml(node)
self.class.to_xml(node)
end
Expand Down Expand Up @@ -166,8 +169,8 @@ def populate_template(docxml, _format = nil)
.merge(@labels ? { labels: @labels } : {})
.merge(@meta.labels ? { labels: @meta.labels } : {})
.merge(fonts_options || {})
template = liquid(docxml)
template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h)
liquid(docxml).render(meta.stringify_all_keys
.transform_values { |v| empty2nil(v) })
.gsub("<", "<").gsub(">", ">").gsub("&", "&")
end

Expand Down
2 changes: 1 addition & 1 deletion lib/isodoc/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module IsoDoc
class Metadata
attr_accessor :fonts_options
attr_accessor :fonts_options, :labels

def ns(xpath)
Common::ns(xpath)
Expand Down
23 changes: 23 additions & 0 deletions spec/isodoc/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,27 @@
expect(metadata(c.info(Nokogiri::XML(input), nil)))
.to be_equivalent_to output
end

it "processes metadata with embedded objects" do
c = IsoDoc::Convert.new({})
c.convert_init(<<~INPUT, "test", false)
<iso-standard xmlns="http://riboseinc.com/isoxml">
INPUT
c.meta.labels = { hash: { key: [{ key1: 1 }, { key2: 2 }] } }
template = <<~OUTPUT
<xml> {{ labels["hash"] }} </xml>
OUTPUT
input = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
<bibdata type="standard">
</bibdata>
</iso-standard>
INPUT
output = <<~OUTPUT
<xml> {"key"=>[{"key1"=>1}, {"key2"=>2}]} </xml>
OUTPUT
c.info(Nokogiri::XML(input), nil)
expect(c.populate_template(template))
.to be_equivalent_to output
end
end

0 comments on commit 5f5285d

Please sign in to comment.