vectory 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/vectory/svg.rb +7 -3
- data/lib/vectory/svg_document.rb +4 -4
- data/lib/vectory/svg_mapping.rb +33 -22
- data/lib/vectory/version.rb +1 -1
- data/vectory.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 66b15c386fa1dcdd0fc02473b9062f3eca19ed5b1bc40f2facec9577a4495fd4
|
|
4
|
+
data.tar.gz: d5bc9be14ab660ddbbba77548a205a472eb4215bb848c57d5e3d980205159da4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9e802267d5860c496738492218e4fd8260ff9c84546d63c11254d170f14ee1c8c9bebd24a943b24e8bcd5c7013db8a3d55844aba286d06f5959a717fe289da34
|
|
7
|
+
data.tar.gz: 53747660f38c403952debd623ad81dbce990e51fa8098d63480762c3de40531cc2602b903c943c91e01f9678433b6340b77529345ad487f53b4fb2c04ca4bfe6
|
data/Gemfile
CHANGED
|
@@ -9,6 +9,7 @@ gem "canon", "~> 0.1.7"
|
|
|
9
9
|
gem "connection_pool", "~> 2.0"
|
|
10
10
|
gem "openssl", "~> 3.0"
|
|
11
11
|
gem "rake"
|
|
12
|
+
gem "nokogiri" # dev-only: exercises SvgMapping's duck-typed document-object input (metanorma passes Nokogiri docs)
|
|
12
13
|
gem "rspec"
|
|
13
14
|
gem "rubocop"
|
|
14
15
|
gem "rubocop-performance"
|
data/lib/vectory/svg.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "leptris"
|
|
4
4
|
require "postsvg"
|
|
5
5
|
|
|
6
6
|
module Vectory
|
|
@@ -55,7 +55,7 @@ module Vectory
|
|
|
55
55
|
private
|
|
56
56
|
|
|
57
57
|
def svg_root
|
|
58
|
-
doc =
|
|
58
|
+
doc = Leptris::XML.parse(content)
|
|
59
59
|
doc.at_xpath("//svg:svg", "svg" => SVG_NS) || doc.at_xpath("//svg")
|
|
60
60
|
end
|
|
61
61
|
|
|
@@ -77,7 +77,11 @@ module Vectory
|
|
|
77
77
|
def content=(content)
|
|
78
78
|
# non-root node inserts the xml tag which breaks markup when placed in
|
|
79
79
|
# another xml document
|
|
80
|
-
document =
|
|
80
|
+
document = begin
|
|
81
|
+
Leptris::XML.parse(content).root
|
|
82
|
+
rescue Leptris::XML::ParseError
|
|
83
|
+
nil
|
|
84
|
+
end
|
|
81
85
|
unless document
|
|
82
86
|
raise ParsingError, "Could not parse '#{content&.slice(0, 30)}'"
|
|
83
87
|
end
|
data/lib/vectory/svg_document.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "leptris"
|
|
2
2
|
|
|
3
3
|
module Vectory
|
|
4
4
|
# Represents and processes an SVG document within XML.
|
|
@@ -21,7 +21,7 @@ module Vectory
|
|
|
21
21
|
class << self
|
|
22
22
|
# Updates ID references in CSS style statements within a document.
|
|
23
23
|
#
|
|
24
|
-
# @param document [
|
|
24
|
+
# @param document [Leptris::XML::Document] The SVG document
|
|
25
25
|
# @param ids [Array<String>] IDs to update
|
|
26
26
|
# @param suffix [Integer, String] The suffix to apply (integers are zero-padded)
|
|
27
27
|
# @return [void]
|
|
@@ -56,7 +56,7 @@ module Vectory
|
|
|
56
56
|
|
|
57
57
|
# Updates ID attributes in SVG elements.
|
|
58
58
|
#
|
|
59
|
-
# @param document [
|
|
59
|
+
# @param document [Leptris::XML::Document] The SVG document
|
|
60
60
|
# @param ids [Array<String>] IDs to update
|
|
61
61
|
# @param suffix [Integer, String] The suffix to apply (integers are zero-padded)
|
|
62
62
|
# @return [void]
|
|
@@ -76,7 +76,7 @@ module Vectory
|
|
|
76
76
|
#
|
|
77
77
|
# @param content [String] SVG XML content
|
|
78
78
|
def initialize(content)
|
|
79
|
-
@document =
|
|
79
|
+
@document = Leptris::XML.parse(content)
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
# Returns the processed SVG content as XML string.
|
data/lib/vectory/svg_mapping.rb
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "leptris"
|
|
4
|
+
|
|
1
5
|
module Vectory
|
|
2
6
|
# Processes SVG mapping in XML documents.
|
|
3
7
|
#
|
|
@@ -7,6 +11,11 @@ module Vectory
|
|
|
7
11
|
# - Applying ID suffixes for uniqueness in multi-document scenarios
|
|
8
12
|
# - Simplifying svgmap structure for final output
|
|
9
13
|
#
|
|
14
|
+
# The document is processed on a leptris tree: pass XML content, or any
|
|
15
|
+
# document object responding to #to_xml (serialized once on entry).
|
|
16
|
+
# #call returns the processed Leptris document; callers working on
|
|
17
|
+
# their own DOM (e.g. Nokogiri) re-serialize and graft the result back.
|
|
18
|
+
#
|
|
10
19
|
# == ID Suffixing
|
|
11
20
|
#
|
|
12
21
|
# SVG IDs are suffixed in two stages to ensure uniqueness:
|
|
@@ -30,7 +39,7 @@ module Vectory
|
|
|
30
39
|
class SvgMapping
|
|
31
40
|
# Namespace helper for XML namespace handling
|
|
32
41
|
class Namespace
|
|
33
|
-
# @param xmldoc [
|
|
42
|
+
# @param xmldoc [Leptris::XML::Document] The XML document
|
|
34
43
|
def initialize(xmldoc)
|
|
35
44
|
@namespace = xmldoc.root.namespace
|
|
36
45
|
end
|
|
@@ -61,7 +70,7 @@ module Vectory
|
|
|
61
70
|
# @param path [String] Path to the XML file
|
|
62
71
|
# @return [Vectory::SvgMapping] New mapping instance
|
|
63
72
|
def self.from_path(path)
|
|
64
|
-
new(
|
|
73
|
+
new(File.read(path))
|
|
65
74
|
end
|
|
66
75
|
|
|
67
76
|
# Creates an SvgMapping from an XML string.
|
|
@@ -69,25 +78,27 @@ module Vectory
|
|
|
69
78
|
# @param xml [String] XML content
|
|
70
79
|
# @return [Vectory::SvgMapping] New mapping instance
|
|
71
80
|
def self.from_xml(xml)
|
|
72
|
-
new(
|
|
81
|
+
new(xml)
|
|
73
82
|
end
|
|
74
83
|
|
|
75
84
|
# Initializes a new SvgMapping processor.
|
|
76
85
|
#
|
|
77
|
-
# @param doc [
|
|
86
|
+
# @param doc [String, #to_xml] XML content, or a document object
|
|
87
|
+
# (serialized once on entry)
|
|
78
88
|
# @param local_directory [String] Directory for resolving relative file paths
|
|
79
89
|
# @param id_suffix [String, nil] Optional suffix derived from document/container
|
|
80
90
|
# identity. Applied before the index suffix to provide cross-document
|
|
81
91
|
# uniqueness. Example: "_ISO_17301-1_2016"
|
|
82
92
|
def initialize(doc, local_directory = "", id_suffix: nil)
|
|
83
|
-
|
|
93
|
+
xml = doc.respond_to?(:to_xml) ? doc.to_xml : doc
|
|
94
|
+
@doc = Leptris::XML.parse(xml)
|
|
84
95
|
@local_directory = local_directory
|
|
85
96
|
@id_suffix = id_suffix
|
|
86
97
|
end
|
|
87
98
|
|
|
88
99
|
# Processes all svgmap elements in the document.
|
|
89
100
|
#
|
|
90
|
-
# @return [
|
|
101
|
+
# @return [Leptris::XML::Document] The processed document
|
|
91
102
|
def call
|
|
92
103
|
@namespace = Namespace.new(@doc)
|
|
93
104
|
|
|
@@ -109,7 +120,7 @@ module Vectory
|
|
|
109
120
|
|
|
110
121
|
# Processes a single svgmap element.
|
|
111
122
|
#
|
|
112
|
-
# @param svgmap [
|
|
123
|
+
# @param svgmap [Leptris::XML::Element] The svgmap element to process
|
|
113
124
|
# @param index [Integer] Position of this svgmap in the document (0-indexed)
|
|
114
125
|
def process_svgmap(svgmap, index)
|
|
115
126
|
image = extract_image_tag(svgmap)
|
|
@@ -125,19 +136,19 @@ module Vectory
|
|
|
125
136
|
|
|
126
137
|
# Extracts the image element (SVG inline or image with src) from svgmap.
|
|
127
138
|
#
|
|
128
|
-
# @param svgmap [
|
|
129
|
-
# @return [
|
|
139
|
+
# @param svgmap [Leptris::XML::Element] The svgmap element
|
|
140
|
+
# @return [Leptris::XML::Element, nil] The image/svg element or nil
|
|
130
141
|
def extract_image_tag(svgmap)
|
|
131
|
-
image = svgmap.
|
|
142
|
+
image = svgmap.at_xpath(@namespace.ns(".//image"))
|
|
132
143
|
return image if image && image["src"] && !image["src"].empty?
|
|
133
144
|
|
|
134
|
-
svgmap.
|
|
145
|
+
svgmap.at_xpath(".//m:svg", "m" => SVG_NS)
|
|
135
146
|
end
|
|
136
147
|
|
|
137
148
|
# Generates processed SVG content for an svgmap.
|
|
138
149
|
#
|
|
139
|
-
# @param image [
|
|
140
|
-
# @param svgmap [
|
|
150
|
+
# @param image [Leptris::XML::Element] The image/svg element
|
|
151
|
+
# @param svgmap [Leptris::XML::Element] The parent svgmap element
|
|
141
152
|
# @param index [Integer] Index suffix to apply
|
|
142
153
|
# @return [String, nil] Processed SVG content or nil if invalid
|
|
143
154
|
def generate_content(image, svgmap, index)
|
|
@@ -153,7 +164,7 @@ module Vectory
|
|
|
153
164
|
|
|
154
165
|
# Builds an SvgDocument from an image element.
|
|
155
166
|
#
|
|
156
|
-
# @param image [
|
|
167
|
+
# @param image [Leptris::XML::Element] The image element
|
|
157
168
|
# @return [Vectory::SvgDocument, nil] The SVG document or nil if invalid
|
|
158
169
|
def build_svg_document(image)
|
|
159
170
|
vector = build_vector(image)
|
|
@@ -164,7 +175,7 @@ module Vectory
|
|
|
164
175
|
|
|
165
176
|
# Builds a Vector from an image element.
|
|
166
177
|
#
|
|
167
|
-
# @param image [
|
|
178
|
+
# @param image [Leptris::XML::Element] The image element
|
|
168
179
|
# @return [Vectory::Vector, nil] The vector or nil if invalid
|
|
169
180
|
def build_vector(image)
|
|
170
181
|
return Vectory::Svg.from_content(image.to_xml) if image.name == "svg"
|
|
@@ -182,7 +193,7 @@ module Vectory
|
|
|
182
193
|
|
|
183
194
|
# Builds a mapping from target hrefs to their link targets.
|
|
184
195
|
#
|
|
185
|
-
# @param svgmap [
|
|
196
|
+
# @param svgmap [Leptris::XML::Element] The svgmap element
|
|
186
197
|
# @return [Hash{String => String}] Mapping of href to target
|
|
187
198
|
def from_targets_to_links_map(svgmap)
|
|
188
199
|
targets = svgmap.xpath(@namespace.ns("./target"))
|
|
@@ -199,13 +210,13 @@ module Vectory
|
|
|
199
210
|
|
|
200
211
|
# Extracts link target from a target element.
|
|
201
212
|
#
|
|
202
|
-
# @param target_tag [
|
|
213
|
+
# @param target_tag [Leptris::XML::Element] The target element
|
|
203
214
|
# @return [String, nil] The link target or nil
|
|
204
215
|
def link_target(target_tag)
|
|
205
|
-
xref = target_tag.
|
|
216
|
+
xref = target_tag.at_xpath(@namespace.ns("./xref"))
|
|
206
217
|
return "##{xref['target']}" if xref
|
|
207
218
|
|
|
208
|
-
link = target_tag.
|
|
219
|
+
link = target_tag.at_xpath(@namespace.ns("./link"))
|
|
209
220
|
return unless link
|
|
210
221
|
|
|
211
222
|
link["target"]
|
|
@@ -214,11 +225,11 @@ module Vectory
|
|
|
214
225
|
# Simplifies svgmap after processing.
|
|
215
226
|
# Removes svgmap wrapper if no more target elements with eref.
|
|
216
227
|
#
|
|
217
|
-
# @param svgmap [
|
|
228
|
+
# @param svgmap [Leptris::XML::Element] The svgmap element
|
|
218
229
|
def simplify_svgmap(svgmap)
|
|
219
|
-
return if svgmap.
|
|
230
|
+
return if svgmap.at_xpath(@namespace.ns("./target/eref"))
|
|
220
231
|
|
|
221
|
-
svgmap.replace(svgmap.
|
|
232
|
+
svgmap.replace(svgmap.at_xpath(@namespace.ns("./figure")))
|
|
222
233
|
end
|
|
223
234
|
end
|
|
224
235
|
end
|
data/lib/vectory/version.rb
CHANGED
data/vectory.gemspec
CHANGED
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
spec.add_dependency "emfsvg", "~> 0.1", ">= 0.1.2"
|
|
31
31
|
spec.add_dependency "image_size", ">= 3.2.0"
|
|
32
32
|
spec.add_dependency "marcel", "~> 1.0"
|
|
33
|
-
spec.add_dependency "
|
|
33
|
+
spec.add_dependency "leptris", "~> 1.9.361.1"
|
|
34
34
|
spec.add_dependency "postsvg", "~> 0.3"
|
|
35
35
|
spec.add_dependency "thor", "~> 1.0"
|
|
36
36
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vectory
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-10-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -73,19 +73,19 @@ dependencies:
|
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
74
|
version: '1.0'
|
|
75
75
|
- !ruby/object:Gem::Dependency
|
|
76
|
-
name:
|
|
76
|
+
name: leptris
|
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
|
78
78
|
requirements:
|
|
79
79
|
- - "~>"
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
|
-
version:
|
|
81
|
+
version: 1.9.361.1
|
|
82
82
|
type: :runtime
|
|
83
83
|
prerelease: false
|
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements:
|
|
86
86
|
- - "~>"
|
|
87
87
|
- !ruby/object:Gem::Version
|
|
88
|
-
version:
|
|
88
|
+
version: 1.9.361.1
|
|
89
89
|
- !ruby/object:Gem::Dependency
|
|
90
90
|
name: postsvg
|
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|