lutaml-model 0.8.169 → 0.8.170
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/bench/baselines/main_mml.json +30 -0
- data/bench/baselines/main_niso.json +23 -0
- data/bench/baselines/main_sts.json +30 -0
- data/bench/baselines/main_unitsml.json +9 -0
- data/bench/baselines/main_xmi.json +30 -0
- data/docs/namespace-management.adoc +27 -0
- data/lib/compat/opal/lutaml_model_boot.rb +1 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/decisions/decision_engine.rb +1 -0
- data/lib/lutaml/xml/decisions/rules/attribute_qualified_prefix_rule.rb +57 -0
- data/lib/lutaml/xml/decisions/rules.rb +2 -0
- data/lib/lutaml/xml/declaration_planner.rb +22 -2
- data/lib/lutaml/xml/leptris/native_emission.rb +36 -0
- data/lib/lutaml/xml/leptris/plan_serializer.rb +26 -0
- data/spec/lutaml/xml/constructed_namespace_prefix_spec.rb +110 -0
- metadata +9 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dd7b915692eee1912259db7da0a88cc7864f803d6b4351462d1d4c876d02a6ec
|
|
4
|
+
data.tar.gz: 8a706f651a1e7986924a3e9a66d80f861d2d52557ad7df25020b64638ce52d66
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d9de4cf6473267fbe06c5b3b3b96020666ab597514d7a44a2f081a23a432b93cb3c4bf89f32b7cbfe057f4e9882eefcf687b2f1dfcbdd8de30c0ac3219589201
|
|
7
|
+
data.tar.gz: 6a022ad30b74a4c6f5211ff2f1d484399492df597c68a3ab9efdd61e42b889577795b3b4e14dd00b90c0eb9ab84afe7730baa513cea9f307e4c498d718cc13d4
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"complex1-46KB": {
|
|
3
|
+
"avg_time": 0.03743817400000656,
|
|
4
|
+
"min_time": 0.03580255499998941,
|
|
5
|
+
"max_time": 0.037985226000003536,
|
|
6
|
+
"allocations": 51133,
|
|
7
|
+
"ips": 26.71070442697939
|
|
8
|
+
},
|
|
9
|
+
"complex4-50KB": {
|
|
10
|
+
"avg_time": 0.05052796100000497,
|
|
11
|
+
"min_time": 0.04987352499999531,
|
|
12
|
+
"max_time": 0.05090635400000565,
|
|
13
|
+
"allocations": 71910,
|
|
14
|
+
"ips": 19.791022242118608
|
|
15
|
+
},
|
|
16
|
+
"size1000-245KB": {
|
|
17
|
+
"avg_time": 0.29998471433333407,
|
|
18
|
+
"min_time": 0.2930994010000063,
|
|
19
|
+
"max_time": 0.30605089399999486,
|
|
20
|
+
"allocations": 406451,
|
|
21
|
+
"ips": 3.33350318272827
|
|
22
|
+
},
|
|
23
|
+
"complex3-567KB": {
|
|
24
|
+
"avg_time": 0.4159978183333332,
|
|
25
|
+
"min_time": 0.414953170000004,
|
|
26
|
+
"max_time": 0.41766153099999315,
|
|
27
|
+
"allocations": 587536,
|
|
28
|
+
"ips": 2.403858760621466
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"metrology-4KB": {
|
|
3
|
+
"avg_time": 0.011824453333337223,
|
|
4
|
+
"min_time": 0.011421979000004967,
|
|
5
|
+
"max_time": 0.012430414000007772,
|
|
6
|
+
"allocations": 7544,
|
|
7
|
+
"ips": 84.57050586691008
|
|
8
|
+
},
|
|
9
|
+
"bmj-49KB": {
|
|
10
|
+
"avg_time": 0.10275671466666363,
|
|
11
|
+
"min_time": 0.10232797499999435,
|
|
12
|
+
"max_time": 0.10314825199999689,
|
|
13
|
+
"allocations": 72378,
|
|
14
|
+
"ips": 9.731724133492762
|
|
15
|
+
},
|
|
16
|
+
"pnas-152KB": {
|
|
17
|
+
"avg_time": 0.46011452899999955,
|
|
18
|
+
"min_time": 0.4572272639999966,
|
|
19
|
+
"max_time": 0.4658364209999917,
|
|
20
|
+
"allocations": 259437,
|
|
21
|
+
"ips": 2.173371925840666
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"feature-doc-23KB": {
|
|
3
|
+
"avg_time": 0.07566020366666255,
|
|
4
|
+
"min_time": 0.074541666000016,
|
|
5
|
+
"max_time": 0.0764295470000036,
|
|
6
|
+
"allocations": 32998,
|
|
7
|
+
"ips": 13.21698794792725
|
|
8
|
+
},
|
|
9
|
+
"tbx-nisosts-101KB": {
|
|
10
|
+
"avg_time": 0.219973534666669,
|
|
11
|
+
"min_time": 0.21835066099998812,
|
|
12
|
+
"max_time": 0.2225604799999985,
|
|
13
|
+
"allocations": 134786,
|
|
14
|
+
"ips": 4.546001415649038
|
|
15
|
+
},
|
|
16
|
+
"iso-13849-1MB": {
|
|
17
|
+
"avg_time": 7.808285298999995,
|
|
18
|
+
"min_time": 7.748742658999987,
|
|
19
|
+
"max_time": 7.903863881000007,
|
|
20
|
+
"allocations": 1733464,
|
|
21
|
+
"ips": 0.1280690909344808
|
|
22
|
+
},
|
|
23
|
+
"din-iso-1.1MB": {
|
|
24
|
+
"avg_time": 0.9531642093333138,
|
|
25
|
+
"min_time": 0.9456722399999649,
|
|
26
|
+
"max_time": 0.9604461779999838,
|
|
27
|
+
"allocations": 883501,
|
|
28
|
+
"ips": 1.0491371688194684
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ea251": {
|
|
3
|
+
"avg_time": 0.26108460200000155,
|
|
4
|
+
"min_time": 0.2576839820000032,
|
|
5
|
+
"max_time": 0.2658058270000083,
|
|
6
|
+
"allocations": 183152,
|
|
7
|
+
"ips": 3.8301760898177903
|
|
8
|
+
},
|
|
9
|
+
"medium": {
|
|
10
|
+
"avg_time": 0.6549090059999875,
|
|
11
|
+
"min_time": 0.6454114659999846,
|
|
12
|
+
"max_time": 0.6686907289999908,
|
|
13
|
+
"allocations": 474403,
|
|
14
|
+
"ips": 1.5269296815869702
|
|
15
|
+
},
|
|
16
|
+
"citygml": {
|
|
17
|
+
"avg_time": 0.7382608636666722,
|
|
18
|
+
"min_time": 0.7349978900000167,
|
|
19
|
+
"max_time": 0.7414869970000098,
|
|
20
|
+
"allocations": 586804,
|
|
21
|
+
"ips": 1.3545347575833357
|
|
22
|
+
},
|
|
23
|
+
"large": {
|
|
24
|
+
"avg_time": 6.100064923666669,
|
|
25
|
+
"min_time": 5.998476953000022,
|
|
26
|
+
"max_time": 6.217400171000008,
|
|
27
|
+
"allocations": 4531263,
|
|
28
|
+
"ips": 0.1639326814572513
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -73,6 +73,33 @@ When using namespaces with `uri_aliases`, the system maintains a mapping between
|
|
|
73
73
|
When round-tripping, the original URI (alias or canonical) is preserved regardless of the `prefix:` option.
|
|
74
74
|
====
|
|
75
75
|
|
|
76
|
+
==== Constructed-Model Wire Form
|
|
77
|
+
|
|
78
|
+
Models built programmatically (never parsed) choose their root spelling from the namespace declaration itself. A namespace that declares `attribute_form_default :qualified` serializes in prefix form — W3C attributes never inherit the default namespace, so a document whose attributes are namespace-qualified is inherently a prefixed document, and the root carries its `prefix_default` accordingly. Namespaces with unqualified attributes (the W3C default) serialize in default-namespace form.
|
|
79
|
+
|
|
80
|
+
[source,ruby]
|
|
81
|
+
----
|
|
82
|
+
class WordNamespace < Lutaml::Xml::Namespace
|
|
83
|
+
uri "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
|
|
84
|
+
prefix_default "w"
|
|
85
|
+
element_form_default :qualified
|
|
86
|
+
attribute_form_default :qualified # every attribute carries w:
|
|
87
|
+
end
|
|
88
|
+
# Constructed serialization: <w:document xmlns:w="..."> - the same
|
|
89
|
+
# form the parsed-and-reserialized output keeps.
|
|
90
|
+
|
|
91
|
+
class CustomPropsNamespace < Lutaml::Xml::Namespace
|
|
92
|
+
uri "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
|
|
93
|
+
prefix_default "custprops"
|
|
94
|
+
element_form_default :qualified # attributes stay unqualified (W3C default)
|
|
95
|
+
end
|
|
96
|
+
# Constructed serialization: <Properties xmlns="..."> - the
|
|
97
|
+
# default-xmlns document style; foreign-namespace children keep their
|
|
98
|
+
# declared prefixes.
|
|
99
|
+
----
|
|
100
|
+
|
|
101
|
+
The `prefix:` serialization options above still override this choice: `prefix: false` forces the default form, `prefix: true` and prefix strings force prefix form.
|
|
102
|
+
|
|
76
103
|
==== Examples
|
|
77
104
|
|
|
78
105
|
[source,ruby]
|
|
@@ -521,6 +521,7 @@ require "lutaml/model/schema/xml_compiler/registry_generator"
|
|
|
521
521
|
require "lutaml/model/schema/xml_compiler/spec_builder"
|
|
522
522
|
require "lutaml/model/schema/xml_compiler/supported_data_types"
|
|
523
523
|
require "lutaml/model/services/type/validator"
|
|
524
|
+
require "lutaml/xml/decisions/rules/attribute_qualified_prefix_rule"
|
|
524
525
|
require "lutaml/xml/decisions/rules/attribute_usage_rule"
|
|
525
526
|
require "lutaml/xml/decisions/rules/default_preference_rule"
|
|
526
527
|
require "lutaml/xml/decisions/rules/element_form_default_rule"
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -56,6 +56,7 @@ module Lutaml
|
|
|
56
56
|
Rules::ExplicitOptionRule.new,
|
|
57
57
|
Rules::NamespaceScopeRule.new,
|
|
58
58
|
Rules::AttributeUsageRule.new,
|
|
59
|
+
Rules::AttributeQualifiedPrefixRule.new,
|
|
59
60
|
Rules::ElementFormDefaultRule.new,
|
|
60
61
|
Rules::DefaultPreferenceRule.new, # Must be last (catch-all)
|
|
61
62
|
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xml
|
|
5
|
+
module Decisions
|
|
6
|
+
module Rules
|
|
7
|
+
# Priority 4.4: attribute-qualifying namespaces spell prefixed.
|
|
8
|
+
#
|
|
9
|
+
# A namespace that declares attribute_form_default :qualified
|
|
10
|
+
# produces an inherently prefixed document: W3C attributes never
|
|
11
|
+
# inherit the default namespace, so every attribute already
|
|
12
|
+
# carries the prefix, and the coherent spelling prefixes the
|
|
13
|
+
# root too. Namespaces with unqualified attributes (the W3C
|
|
14
|
+
# default) keep the default-xmlns document style.
|
|
15
|
+
#
|
|
16
|
+
# This is the constructed-model counterpart of the parsed path's
|
|
17
|
+
# Priority 1 format preservation: a WordprocessingML-style part
|
|
18
|
+
# (w:document with w:val attributes) serializes prefixed whether
|
|
19
|
+
# it was parsed or built, while a custom-properties-style part
|
|
20
|
+
# (bare fmtid/pid/name attributes) serializes in default-xmlns
|
|
21
|
+
# form in both lanes (lutaml-model#1124).
|
|
22
|
+
#
|
|
23
|
+
# IMPORTANT: This rule does NOT override input format preservation
|
|
24
|
+
# (Priority 1). It only applies when no input format exists
|
|
25
|
+
# (programmatically created models).
|
|
26
|
+
class AttributeQualifiedPrefixRule < DecisionRule
|
|
27
|
+
def priority
|
|
28
|
+
4.4
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def applies?(context)
|
|
32
|
+
return false unless context.has_namespace?
|
|
33
|
+
|
|
34
|
+
ns_class = context.namespace_class
|
|
35
|
+
return false unless ns_class
|
|
36
|
+
return false if ns_class.prefix_default.to_s.empty?
|
|
37
|
+
return false unless ns_class.attribute_form_default == :qualified
|
|
38
|
+
|
|
39
|
+
# If input format exists, FormatPreservationRule (Priority 1)
|
|
40
|
+
# handles it
|
|
41
|
+
context.preserved_input_format.nil?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def decide(context)
|
|
45
|
+
ns_class = context.namespace_class
|
|
46
|
+
Decision.prefix(
|
|
47
|
+
prefix: ns_class.prefix_default,
|
|
48
|
+
namespace_class: ns_class,
|
|
49
|
+
reason: "Priority 4.4: attribute_form_default :qualified - " \
|
|
50
|
+
"inherently prefixed document, root spells prefixed",
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -27,6 +27,8 @@ module Lutaml
|
|
|
27
27
|
autoload :AttributeUsageRule, "#{__dir__}/rules/attribute_usage_rule"
|
|
28
28
|
autoload :ElementFormDefaultRule,
|
|
29
29
|
"#{__dir__}/rules/element_form_default_rule"
|
|
30
|
+
autoload :AttributeQualifiedPrefixRule,
|
|
31
|
+
"#{__dir__}/rules/attribute_qualified_prefix_rule"
|
|
30
32
|
autoload :DefaultPreferenceRule,
|
|
31
33
|
"#{__dir__}/rules/default_preference_rule"
|
|
32
34
|
autoload :InheritParentPrefixRule,
|
|
@@ -110,6 +110,18 @@ module Lutaml
|
|
|
110
110
|
# CRITICAL: Only applies when explicitly set, not when defaulted to :unqualified.
|
|
111
111
|
prefix = element_namespace.prefix_default || "ns#{hoisted.keys.length}"
|
|
112
112
|
hoisted[prefix] = element_namespace.uri
|
|
113
|
+
elsif element_namespace.attribute_form_default == :qualified &&
|
|
114
|
+
element_namespace.prefix_default
|
|
115
|
+
# A namespace that qualifies its ATTRIBUTES produces an
|
|
116
|
+
# inherently prefixed document: W3C attributes never
|
|
117
|
+
# inherit the default namespace, so every attribute
|
|
118
|
+
# already carries the prefix, and the coherent spelling
|
|
119
|
+
# prefixes the root too. Namespaces with unqualified
|
|
120
|
+
# attributes (the W3C default) keep the default-xmlns
|
|
121
|
+
# document style (lutaml-model#1124: w: document.xml vs
|
|
122
|
+
# default-form custom.xml).
|
|
123
|
+
hoisted[element_namespace.prefix_default] =
|
|
124
|
+
element_namespace.uri
|
|
113
125
|
else
|
|
114
126
|
# Default: prefer default format (cleaner)
|
|
115
127
|
hoisted[nil] = element_namespace.uri
|
|
@@ -182,8 +194,16 @@ module Lutaml
|
|
|
182
194
|
scope_config = needs.scope_config_for(ns_class)
|
|
183
195
|
next if scope_config
|
|
184
196
|
|
|
185
|
-
# Add remaining namespace (default format preferred
|
|
186
|
-
|
|
197
|
+
# Add remaining namespace (default format preferred;
|
|
198
|
+
# attribute-qualifying namespaces keep their declared
|
|
199
|
+
# prefix so foreign-namespace children stay qualified —
|
|
200
|
+
# lutaml-model#1124)
|
|
201
|
+
if ns_class.prefix_default &&
|
|
202
|
+
ns_class.attribute_form_default == :qualified
|
|
203
|
+
hoisted[ns_class.prefix_default] = ns_class.uri
|
|
204
|
+
else
|
|
205
|
+
hoisted[nil] = ns_class.uri
|
|
206
|
+
end
|
|
187
207
|
end
|
|
188
208
|
|
|
189
209
|
root_node = DeclarationPlan::ElementNode.new(
|
|
@@ -62,10 +62,46 @@ module Lutaml
|
|
|
62
62
|
return false unless ordered_ns_emittable?(plan, instance)
|
|
63
63
|
return false if plan[:ordered] && instance.is_a?(::Lutaml::Model::Serialize) &&
|
|
64
64
|
instance.element_order.nil?
|
|
65
|
+
# An UNORDERED instance (no parse-captured element_order)
|
|
66
|
+
# over a MULTI-NAMESPACE EXACT tree spells through the
|
|
67
|
+
# flat emission layout, whose slot numbering diverges from
|
|
68
|
+
# the engine descriptor for nested rows across namespaces
|
|
69
|
+
# — the ops address the wrong plan and grandchildren
|
|
70
|
+
# render with the grandparent's name and prefix (a
|
|
71
|
+
# constructed prefixed w:-root with an m:-namespace child
|
|
72
|
+
# spelled the child's t row as w:r). Single-namespace
|
|
73
|
+
# unordered trees spell faithfully (the clrScheme shape);
|
|
74
|
+
# the DOM lane serves the rest until the flat emission
|
|
75
|
+
# numbering matches the descriptor walk.
|
|
76
|
+
return false if multi_exact_ns_tree?(plan[:tree]) &&
|
|
77
|
+
instance.is_a?(::Lutaml::Model::Serialize) &&
|
|
78
|
+
instance.element_order.nil?
|
|
65
79
|
|
|
66
80
|
subtree_gate_ok?(plan, instance, register)
|
|
67
81
|
end
|
|
68
82
|
|
|
83
|
+
# Whether the tree's EXACT-ns rows (tree, attribute rows,
|
|
84
|
+
# child rows, recursively through nested plans) carry more
|
|
85
|
+
# than one distinct namespace URI.
|
|
86
|
+
def multi_exact_ns_tree?(tree, uris = ::Set.new)
|
|
87
|
+
return false unless tree.is_a?(::Hash)
|
|
88
|
+
|
|
89
|
+
ns = tree[:ns]
|
|
90
|
+
uris << ns[:exact] if ns.is_a?(::Hash) && ns[:exact]
|
|
91
|
+
(tree[:attributes] || []).each do |a|
|
|
92
|
+
ans = a[:ns]
|
|
93
|
+
uris << ans[:exact] if ans.is_a?(::Hash) && ans[:exact]
|
|
94
|
+
end
|
|
95
|
+
(tree[:children] || []).each do |r|
|
|
96
|
+
rns = r[:ns]
|
|
97
|
+
uris << rns[:exact] if rns.is_a?(::Hash) && rns[:exact]
|
|
98
|
+
if r[:plan] && PLANNED_ROW_KINDS.include?(r[:kind])
|
|
99
|
+
multi_exact_ns_tree?(r[:plan], uris)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
uris.length > 1
|
|
103
|
+
end
|
|
104
|
+
|
|
69
105
|
# The engine's attr-row ns_prefix deep-copy fix rides
|
|
70
106
|
# 1.9.407.0 (leptris#1967, fixed by leptris#1968): earlier
|
|
71
107
|
# engines keep the binding's freed FFI anchor pointer in the
|
|
@@ -119,6 +119,7 @@ module Lutaml
|
|
|
119
119
|
attr_reader :unspellable
|
|
120
120
|
|
|
121
121
|
def initialize(instance, plan, register)
|
|
122
|
+
@model_prefix = nil
|
|
122
123
|
@forms = {}
|
|
123
124
|
@hoisted = {}
|
|
124
125
|
@declared = {}
|
|
@@ -185,6 +186,23 @@ module Lutaml
|
|
|
185
186
|
end
|
|
186
187
|
end
|
|
187
188
|
collect(plan[:tree])
|
|
189
|
+
# #1124: under the attribute-qualified wire-form doctrine,
|
|
190
|
+
# a CONSTRUCTED instance (no parse provenance - no
|
|
191
|
+
# element_order AND no stored input declaration plan)
|
|
192
|
+
# whose namespace qualifies its attributes spells the
|
|
193
|
+
# whole document prefixed; rows compiled without an ns
|
|
194
|
+
# form (own-namespace children under element_form_default
|
|
195
|
+
# :qualified) take the model prefix instead of falling
|
|
196
|
+
# into no namespace.
|
|
197
|
+
ns_class = mapping.namespace_class
|
|
198
|
+
if instance.element_order.nil? &&
|
|
199
|
+
!instance.import_declaration_plan.is_a?(
|
|
200
|
+
Lutaml::Xml::DeclarationPlan,
|
|
201
|
+
) && ns_class &&
|
|
202
|
+
ns_class.attribute_form_default == :qualified &&
|
|
203
|
+
!ns_class.prefix_default.to_s.empty?
|
|
204
|
+
@model_prefix = ns_class.prefix_default.to_s
|
|
205
|
+
end
|
|
188
206
|
end
|
|
189
207
|
|
|
190
208
|
def unspellable?
|
|
@@ -219,6 +237,14 @@ module Lutaml
|
|
|
219
237
|
# planner's hoisted prefix for the URI, or unprefixed when
|
|
220
238
|
# hoisted as the default namespace.
|
|
221
239
|
def spell(local, ns_form = nil)
|
|
240
|
+
if ns_form.nil?
|
|
241
|
+
# No row ns: the element belongs to the model's own
|
|
242
|
+
# namespace (element_form_default :qualified) - under
|
|
243
|
+
# the attribute-qualified doctrine it spells with the
|
|
244
|
+
# model's declared prefix (#1124).
|
|
245
|
+
return @model_prefix ? "#{@model_prefix}:#{local}" : local
|
|
246
|
+
end
|
|
247
|
+
|
|
222
248
|
uri = if ns_form.is_a?(Hash)
|
|
223
249
|
ns_form[:exact]
|
|
224
250
|
else
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module ConstructedNs1124
|
|
6
|
+
class WNs < Lutaml::Xml::Namespace
|
|
7
|
+
uri "http://example.com/wordprocessingml"
|
|
8
|
+
prefix_default "w"
|
|
9
|
+
element_form_default :qualified
|
|
10
|
+
attribute_form_default :qualified
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class MNs < Lutaml::Xml::Namespace
|
|
14
|
+
uri "http://example.com/mathml"
|
|
15
|
+
prefix_default "m"
|
|
16
|
+
element_form_default :qualified
|
|
17
|
+
attribute_form_default :qualified
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class MathRun < Lutaml::Model::Serializable
|
|
21
|
+
attribute :text, :string
|
|
22
|
+
|
|
23
|
+
xml do
|
|
24
|
+
element "r"
|
|
25
|
+
namespace MNs
|
|
26
|
+
map_element "t", to: :text
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class Para < Lutaml::Model::Serializable
|
|
31
|
+
attribute :runs, MathRun, collection: true
|
|
32
|
+
|
|
33
|
+
xml do
|
|
34
|
+
element "p"
|
|
35
|
+
namespace WNs
|
|
36
|
+
map_element "r", to: :runs
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class Body < Lutaml::Model::Serializable
|
|
41
|
+
attribute :paras, Para, collection: true
|
|
42
|
+
|
|
43
|
+
xml do
|
|
44
|
+
element "body"
|
|
45
|
+
namespace WNs
|
|
46
|
+
map_element "p", to: :paras
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
RSpec.describe "constructed models serialize foreign namespaces prefixed" do
|
|
52
|
+
# lutaml-model#1124: a constructed (never-parsed) model must serialize
|
|
53
|
+
# child elements in foreign namespaces with their declared prefix,
|
|
54
|
+
# matching the parsed-and-reserialized form — not the default-namespace
|
|
55
|
+
# form. The wire-form signal is attribute qualification: namespaces
|
|
56
|
+
# with attribute_form_default :qualified produce inherently prefixed
|
|
57
|
+
# documents (w: attributes demand the prefix everywhere, root
|
|
58
|
+
# included), so both the w: root and the m: children spell prefixed
|
|
59
|
+
# on the constructed lane exactly as WordprocessingML parts do.
|
|
60
|
+
|
|
61
|
+
let(:register) { Lutaml::Model::Config.default_register }
|
|
62
|
+
|
|
63
|
+
around do |example|
|
|
64
|
+
Lutaml::Model::Config.with_adapter(xml: :leptris) { example.run }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def build_body
|
|
68
|
+
ConstructedNs1124::Body.new(
|
|
69
|
+
paras: [ConstructedNs1124::Para.new(
|
|
70
|
+
runs: [ConstructedNs1124::MathRun.new(text: "x")],
|
|
71
|
+
)],
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "serializes the constructed model fully prefixed" do
|
|
76
|
+
xml = build_body.to_xml
|
|
77
|
+
|
|
78
|
+
expect(xml).to include("<w:body")
|
|
79
|
+
expect(xml).to include("<w:p>")
|
|
80
|
+
expect(xml).to include("<m:r")
|
|
81
|
+
expect(xml).not_to include("<body")
|
|
82
|
+
expect(xml).not_to include("<r>")
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "round-trips constructed output to the identical form" do
|
|
86
|
+
xml = build_body.to_xml
|
|
87
|
+
reparsed = ConstructedNs1124::Body.from_xml(xml)
|
|
88
|
+
|
|
89
|
+
expect(reparsed.to_xml).to eq(xml)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "keeps the foreign-namespace child out of the parent's default form" do
|
|
93
|
+
xml = build_body.to_xml
|
|
94
|
+
|
|
95
|
+
expect(xml).not_to include('xmlns="http://example.com/mathml"')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "routes the multi-namespace unordered emission to the DOM lane" do
|
|
99
|
+
instance = build_body
|
|
100
|
+
plan = Lutaml::Xml::Leptris::PlanCompiler.compile(
|
|
101
|
+
ConstructedNs1124::Body, register
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
expect(
|
|
105
|
+
Lutaml::Xml::Leptris::NativeEmission.compatible?(
|
|
106
|
+
plan, instance, register
|
|
107
|
+
),
|
|
108
|
+
).to be(false)
|
|
109
|
+
end
|
|
110
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.170
|
|
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-
|
|
11
|
+
date: 2026-11-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -181,6 +181,11 @@ files:
|
|
|
181
181
|
- RELEASE_NOTES.adoc
|
|
182
182
|
- Rakefile
|
|
183
183
|
- bench/baselines/.gitkeep
|
|
184
|
+
- bench/baselines/main_mml.json
|
|
185
|
+
- bench/baselines/main_niso.json
|
|
186
|
+
- bench/baselines/main_sts.json
|
|
187
|
+
- bench/baselines/main_unitsml.json
|
|
188
|
+
- bench/baselines/main_xmi.json
|
|
184
189
|
- bench/bench_all.rb
|
|
185
190
|
- bench/bench_alloc_audit.rb
|
|
186
191
|
- bench/bench_common.rb
|
|
@@ -786,6 +791,7 @@ files:
|
|
|
786
791
|
- lib/lutaml/xml/decisions/decision_rule.rb
|
|
787
792
|
- lib/lutaml/xml/decisions/element_prefix_resolver.rb
|
|
788
793
|
- lib/lutaml/xml/decisions/rules.rb
|
|
794
|
+
- lib/lutaml/xml/decisions/rules/attribute_qualified_prefix_rule.rb
|
|
789
795
|
- lib/lutaml/xml/decisions/rules/attribute_usage_rule.rb
|
|
790
796
|
- lib/lutaml/xml/decisions/rules/default_preference_rule.rb
|
|
791
797
|
- lib/lutaml/xml/decisions/rules/element_form_default_rule.rb
|
|
@@ -1995,6 +2001,7 @@ files:
|
|
|
1995
2001
|
- spec/lutaml/xml/compiled_rule_namespace_spec.rb
|
|
1996
2002
|
- spec/lutaml/xml/conformance/xml_namespaces_spec.rb
|
|
1997
2003
|
- spec/lutaml/xml/conformance/xml_schema_instance_spec.rb
|
|
2004
|
+
- spec/lutaml/xml/constructed_namespace_prefix_spec.rb
|
|
1998
2005
|
- spec/lutaml/xml/content_model_validation_spec.rb
|
|
1999
2006
|
- spec/lutaml/xml/cross_class_dispatch_spec.rb
|
|
2000
2007
|
- spec/lutaml/xml/cross_register_plan_spec.rb
|