metanorma-utils 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91f96b7aa6ec3c7ee29649b93edc0dfc1b485ab5db05f6b5c8dcf4f3c38da3bb
4
- data.tar.gz: '080959b8d7c6057098cbf4cd6d22b6711f10ee122b85a833af16cfc352a1ccb1'
3
+ metadata.gz: b8316c849024c1d50c4187236c02c021c6ee1dae96d977e4634a4092f6143545
4
+ data.tar.gz: caf0a5aca6847cb91a43334f61eda55dd371ef205e175e88caf85433b47c7799
5
5
  SHA512:
6
- metadata.gz: 8702b7f309905c9add48241b1f6ca0a6bd11832171d0d7bdbfed97e61fad52dcb86e0eacb680ea3e888fee9f7b2c445b5790e62e4f90779b26152bed168b7880
7
- data.tar.gz: c218e92eda255cb5d0dd8351146f65eefb83f361d206d8e2d12b4bc4e076cdcb49826a349cf560847af91365b050c95ee13ee30c658f7d40d12bcae46d2d208e
6
+ metadata.gz: 5e87d1d6028e5ecd8f4518f8d02c43ca16f8aca81dc3a74b814631372e52b32a2df72313f5eb2304632faaf1248f65653cb4296366183e9e54b2c327f8abf17a
7
+ data.tar.gz: 98cc1f5cdaf5206072b7726fdd9771382aa754a03b7e1310113ea1ea6f80f082bb8596b700d620406ee24a6fc345de58d646291174fd0ba79549259393169547
data/lib/utils/main.rb CHANGED
@@ -78,26 +78,18 @@ module Metanorma
78
78
  hash
79
79
  end
80
80
 
81
- def svgmap_rewrite(xmldoc)
81
+ def svgmap_rewrite(xmldoc, localdir = "")
82
82
  xmldoc.xpath("//svgmap").each do |s|
83
- next unless s["src"]
84
- path = File.file?(s["src"]) ? s["src"] : @localdir + s["src"]
83
+ next unless src = s.at(".//image/@src")
84
+ path = File.file?(src) ? src : localdir + src
85
85
  File.file?(path) or next
86
86
  svg = Nokogiri::XML(File.read(path, encoding: "utf-8"))
87
87
  svgmap_rewrite1(s, svg, path)
88
- next if s.at(".//eref")
89
- svgmap_to_image(s, svg&.at(".//xmlns:image/@height")&.text, svg&.at(".//xmlns:image/@width")&.text)
88
+ next if s.at("./target/eref")
89
+ s.replace(s.at("./figure"))
90
90
  end
91
91
  end
92
92
 
93
- def svgmap_to_image(s, height, width)
94
- s.children.remove
95
- s.name = "img"
96
- s["mimetype"] = "image/svg+xml"
97
- s["height"] = height || "auto"
98
- s["width"] = width || "auto"
99
- end
100
-
101
93
  def svgmap_rewrite1(s, svg, path)
102
94
  targets = s.xpath("./target").each_with_object({}) do |t, m|
103
95
  x = t.at("./xref") and m[t["href"]] = "##{x['target']}"
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.0.2".freeze
3
+ VERSION = "1.0.3".freeze
4
4
  end
5
5
  end
data/spec/utils_spec.rb CHANGED
@@ -94,13 +94,19 @@ RSpec.describe Metanorma::Utils do
94
94
  <doctype>article</doctype>
95
95
  </ext>
96
96
  </bibdata>
97
- <sections><svgmap id="_d5b5049a-dd53-4ea0-bc6f-e8773bd59052"><target href="mn://action_schema"><xref target="ref1">Computer</xref></target></svgmap>
98
- <svgmap id="_4072bdcb-5895-4821-b636-5795b96787cb" src="action_schemaexpg1.svg"><target href="mn://action_schema"><xref target="ref1">Computer</xref></target><target href="http://www.example.com"><link target="http://www.example.com">Phone</link></target></svgmap>
99
- <svgmap id="_60dadf08-48d4-4164-845c-b4e293e00abd" src="action_schemaexpg2.svg" alt="Workmap"><target href="href1.htm"><xref target="ref1">Computer</xref></target><target href="mn://basic_attribute_schema"><link target="http://www.example.com">Phone</link></target><target href="mn://support_resource_schema"><eref type="express" bibitemid="express_action_schema" citeas=""><localityStack><locality type="anchor"><referenceFrom>action_schema.basic</referenceFrom></locality></localityStack>Coffee</eref></target></svgmap></sections>
97
+ <sections>
98
+ <svgmap id="_d5b5049a-dd53-4ea0-bc6f-e8773bd59052"><target href="mn://action_schema"><xref target="ref1">Computer</xref></target></svgmap>
99
+ <svgmap id="_4072bdcb-5895-4821-b636-5795b96787cb">
100
+ <figure><image src="action_schemaexpg1.svg"/></figure>
101
+ <target href="mn://action_schema"><xref target="ref1">Computer</xref></target><target href="http://www.example.com"><link target="http://www.example.com">Phone</link></target>
102
+ </svgmap>
103
+ <svgmap id="_60dadf08-48d4-4164-845c-b4e293e00abd">
104
+ <figure><image src="action_schemaexpg2.svg" alt="Workmap"/></figure>
105
+ <target href="href1.htm"><xref target="ref1">Computer</xref></target><target href="mn://basic_attribute_schema"><link target="http://www.example.com">Phone</link></target><target href="mn://support_resource_schema"><eref type="express" bibitemid="express_action_schema" citeas=""><localityStack><locality type="anchor"><referenceFrom>action_schema.basic</referenceFrom></locality></localityStack>Coffee</eref></target></svgmap></sections>
100
106
  </standard-document>
101
107
  INPUT
102
108
  Metanorma::Utils.svgmap_rewrite(xmldoc)
103
- expect(xmldoc.to_xml).to be_equivalent_to <<~OUTPUT
109
+ expect(xmlpp(xmldoc.to_xml)).to be_equivalent_to xmlpp(<<~OUTPUT)
104
110
  <standard-document type="semantic" version="1.8.2">
105
111
  <bibdata type="standard">
106
112
  <title language="en" format="text/plain">Document title</title>
@@ -120,8 +126,14 @@ RSpec.describe Metanorma::Utils do
120
126
  </ext>
121
127
  </bibdata>
122
128
  <sections><svgmap id="_d5b5049a-dd53-4ea0-bc6f-e8773bd59052"><target href="mn://action_schema"><xref target="ref1">Computer</xref></target></svgmap>
123
- <img id="_4072bdcb-5895-4821-b636-5795b96787cb" src="action_schemaexpg1.svg" mimetype="image/svg+xml" height="315" width="368"/>
124
- <svgmap id="_60dadf08-48d4-4164-845c-b4e293e00abd" src="action_schemaexpg2.svg" alt="Workmap"><target href="mn://support_resource_schema"><eref type="express" bibitemid="express_action_schema" citeas=""><localityStack><locality type="anchor"><referenceFrom>action_schema.basic</referenceFrom></locality></localityStack>Coffee</eref></target></svgmap></sections>
129
+ <figure>
130
+ <image src='action_schemaexpg1.svg'/>
131
+ </figure>
132
+ <svgmap id='_60dadf08-48d4-4164-845c-b4e293e00abd'>
133
+ <figure>
134
+ <image src='action_schemaexpg2.svg' alt='Workmap'/>
135
+ </figure>
136
+ <target href="mn://support_resource_schema"><eref type="express" bibitemid="express_action_schema" citeas=""><localityStack><locality type="anchor"><referenceFrom>action_schema.basic</referenceFrom></locality></localityStack>Coffee</eref></target></svgmap></sections>
125
137
  </standard-document>
126
138
  OUTPUT
127
139
  expect(xmlpp(File.read("action_schemaexpg1.svg", encoding: "utf-8").sub(%r{<image .*</image>}m, ""))).to be_equivalent_to <<~OUTPUT
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.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: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sterile