omml 0.2.11 → 0.2.12
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/.gitattributes +12 -0
- data/.github/workflows/corpus.yml +106 -0
- data/.github/workflows/portable.yml +47 -0
- data/.github/workflows/release.yml +1 -0
- data/.rubocop.yml +5 -0
- data/README.adoc +27 -0
- data/lib/omml/models/ct_anchor.rb +2 -2
- data/lib/omml/models/ct_on_off.rb +1 -1
- data/lib/omml/models/ct_wordprocessing_on_off.rb +1 -1
- data/lib/omml/models/simple_types/st_hex_color_auto.rb +15 -0
- data/lib/omml/models/simple_types/st_hex_color_rgb.rb +9 -0
- data/lib/omml/models/simple_types/st_lang_code.rb +9 -0
- data/lib/omml/models.rb +3 -0
- data/lib/omml/opal.rb +1 -0
- data/lib/omml/portable.rb +192 -0
- data/lib/omml/version.rb +1 -1
- data/lib/omml.rb +1 -0
- data/model/portable/bindings/coordinate.rs +153 -0
- data/model/portable/bindings/coordinate.ts +74 -0
- data/model/portable/bindings/integer.rs +110 -0
- data/model/portable/bindings/integer.ts +74 -0
- data/model/portable/bindings/token.rs +30 -0
- data/model/portable/bindings/token.ts +16 -0
- data/model/portable/enum-subset-v1.json +1 -0
- data/model/portable/manifest.json +933 -0
- data/model/portable/runtime-graph-v1.json +1 -0
- data/model/portable/scalar-subset-v1.json +1 -0
- data/omml.gemspec +2 -1
- data/scripts/export_portable_models.rb +90 -0
- data/scripts/replay_corpus.rb +458 -0
- metadata +21 -3
- data/CLAUDE.md +0 -74
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4e2d70643b709dcb9aed591c580fae3060a524a843c8b172548ddd3e9ad78247
|
|
4
|
+
data.tar.gz: fa961e21646ccc794c792177e02e3ced8e069976d36b6b68f3b0ac9f0479b33e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f9812e4f3641a1dd4e49cd602c91d6d1b4f9835b93c691f9cfb3b153540a27eef388637153726c3422128f535d270f35fb6a9bb1aab453ad542f4351d9464071
|
|
7
|
+
data.tar.gz: 208bda736014b30481ec0f9a4e592333b59a3f735830714bb74c1f4a185165bc28571649982526ad3ca5312ed9c0b28edb63447f44229895b68d54e6cf3d36da
|
data/.gitattributes
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Preserve the bytes the pinned replay hashes on every checkout.
|
|
2
|
+
*.yaml text eol=lf
|
|
3
|
+
*.yml text eol=lf
|
|
4
|
+
*.json text eol=lf
|
|
5
|
+
*.parg text eol=lf
|
|
6
|
+
*.txt text eol=lf
|
|
7
|
+
*.rb text eol=lf
|
|
8
|
+
*.xml text eol=lf
|
|
9
|
+
*.gemspec text eol=lf
|
|
10
|
+
Gemfile text eol=lf
|
|
11
|
+
Rakefile text eol=lf
|
|
12
|
+
bin/* text eol=lf
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
name: corpus
|
|
2
|
+
|
|
3
|
+
# Replays the plurimath-testsuite stage generation pinned in
|
|
4
|
+
# spec/fixtures/testsuite-pin.yml: the testsuite's own validator checks the
|
|
5
|
+
# pin, tampered copies of the pin must fail that check, and every
|
|
6
|
+
# model-roundtrip row of the pinned generation must give its expected model
|
|
7
|
+
# and to_xml output (scripts/replay_corpus.rb).
|
|
8
|
+
|
|
9
|
+
on:
|
|
10
|
+
push:
|
|
11
|
+
branches: [ main ]
|
|
12
|
+
pull_request:
|
|
13
|
+
schedule:
|
|
14
|
+
- cron: "37 4 * * 1"
|
|
15
|
+
workflow_dispatch:
|
|
16
|
+
|
|
17
|
+
permissions:
|
|
18
|
+
contents: read
|
|
19
|
+
|
|
20
|
+
defaults:
|
|
21
|
+
run:
|
|
22
|
+
shell: bash
|
|
23
|
+
|
|
24
|
+
# The testsuite commit is a literal here (not read from a step output) so the
|
|
25
|
+
# checkout ref is fixed by this file; a step checks it against the pin.
|
|
26
|
+
env:
|
|
27
|
+
TESTSUITE_COMMIT: 337262eda0483ceaa43a02cc52362c5b721e5eb3
|
|
28
|
+
PIN: spec/fixtures/testsuite-pin.yml
|
|
29
|
+
|
|
30
|
+
jobs:
|
|
31
|
+
replay:
|
|
32
|
+
name: Pinned testsuite generation replay (${{ matrix.os }})
|
|
33
|
+
runs-on: ${{ matrix.os }}
|
|
34
|
+
strategy:
|
|
35
|
+
fail-fast: false
|
|
36
|
+
matrix:
|
|
37
|
+
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
|
38
|
+
timeout-minutes: 30
|
|
39
|
+
|
|
40
|
+
steps:
|
|
41
|
+
- name: Keep line endings as committed
|
|
42
|
+
run: git config --global core.autocrlf false
|
|
43
|
+
|
|
44
|
+
- uses: actions/checkout@v4
|
|
45
|
+
|
|
46
|
+
- uses: ruby/setup-ruby@v1
|
|
47
|
+
with:
|
|
48
|
+
ruby-version: "3.4"
|
|
49
|
+
bundler-cache: true
|
|
50
|
+
|
|
51
|
+
- name: Check TESTSUITE_COMMIT matches the pin
|
|
52
|
+
run: |
|
|
53
|
+
pinned=$(ruby -ryaml -e 'puts YAML.safe_load_file(ARGV[0]).fetch("commit")' "$PIN")
|
|
54
|
+
test "$pinned" = "$TESTSUITE_COMMIT" || { echo "TESTSUITE_COMMIT=$TESTSUITE_COMMIT but $PIN has $pinned"; exit 1; }
|
|
55
|
+
|
|
56
|
+
- uses: actions/checkout@v4
|
|
57
|
+
with:
|
|
58
|
+
repository: plurimath/plurimath-testsuite
|
|
59
|
+
ref: ${{ env.TESTSUITE_COMMIT }}
|
|
60
|
+
path: tmp/testsuite
|
|
61
|
+
persist-credentials: false
|
|
62
|
+
|
|
63
|
+
- name: Validate the pin with the testsuite's validator
|
|
64
|
+
run: ruby tmp/testsuite/scripts/validate-stages.rb tmp/testsuite --pin "$PIN"
|
|
65
|
+
|
|
66
|
+
- name: A wrong commit, digest or generation fails the validator
|
|
67
|
+
run: |
|
|
68
|
+
mkdir -p tmp/pins
|
|
69
|
+
tamper() {
|
|
70
|
+
ruby -ryaml -e '
|
|
71
|
+
pin = YAML.safe_load_file(ARGV[0])
|
|
72
|
+
pin[ARGV[1]] = ARGV[1] == "generation" ? Integer(ARGV[2]) : ARGV[2]
|
|
73
|
+
File.write(ARGV[3], YAML.dump(pin))
|
|
74
|
+
' "$PIN" "$1" "$2" "tmp/pins/$3.yml"
|
|
75
|
+
if ruby tmp/testsuite/scripts/validate-stages.rb tmp/testsuite --pin "tmp/pins/$3.yml" > "tmp/pins/$3.log" 2>&1; then
|
|
76
|
+
echo "the validator accepted a pin with a wrong $1"; exit 1
|
|
77
|
+
fi
|
|
78
|
+
# The failure must be the pin's, not some other file's.
|
|
79
|
+
grep -A2 "FAIL tmp/pins/$3.yml" "tmp/pins/$3.log" || { cat "tmp/pins/$3.log"; exit 1; }
|
|
80
|
+
echo "ok: wrong $1 rejected"
|
|
81
|
+
}
|
|
82
|
+
tamper commit 0000000000000000000000000000000000000000 commit
|
|
83
|
+
tamper snapshot_digest "sha256:$(printf '0%.0s' {1..64})" digest
|
|
84
|
+
tamper generation 1 generation-1
|
|
85
|
+
tamper generation 99 generation-99
|
|
86
|
+
|
|
87
|
+
- name: Pin and replay specs
|
|
88
|
+
run: bundle exec rspec spec/corpus
|
|
89
|
+
|
|
90
|
+
- name: Replay every model-roundtrip row of the pinned generation
|
|
91
|
+
run: >-
|
|
92
|
+
mkdir -p tmp/corpus &&
|
|
93
|
+
bundle exec ruby scripts/replay_corpus.rb
|
|
94
|
+
--testsuite tmp/testsuite
|
|
95
|
+
--pin "$PIN"
|
|
96
|
+
--report tmp/corpus/replay-report.json
|
|
97
|
+
2>&1 | tee tmp/corpus/replay.log
|
|
98
|
+
|
|
99
|
+
- uses: actions/upload-artifact@v4
|
|
100
|
+
if: always()
|
|
101
|
+
with:
|
|
102
|
+
name: corpus-replay-${{ matrix.os }}
|
|
103
|
+
path: |
|
|
104
|
+
tmp/corpus
|
|
105
|
+
tmp/pins
|
|
106
|
+
if-no-files-found: warn
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: portable model declarations
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
workflow_dispatch:
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
defaults:
|
|
11
|
+
run:
|
|
12
|
+
shell: bash
|
|
13
|
+
|
|
14
|
+
env:
|
|
15
|
+
BUNDLE_GEMFILE: .ci/Gemfile.portable
|
|
16
|
+
LUTAML_MODEL_SOURCE: .build/lutaml-model
|
|
17
|
+
LUTAML_MODEL_COMMIT: eff859d0f6c2bb0936dd3add8ee252aea9dbaa17
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
enum-declarations:
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
strategy:
|
|
23
|
+
fail-fast: false
|
|
24
|
+
matrix:
|
|
25
|
+
ruby: ["3.3", "4.0"]
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v4
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
with:
|
|
30
|
+
repository: lutaml/lutaml-model
|
|
31
|
+
ref: eff859d0f6c2bb0936dd3add8ee252aea9dbaa17
|
|
32
|
+
path: .build/lutaml-model
|
|
33
|
+
- uses: ruby/setup-ruby@v1
|
|
34
|
+
with:
|
|
35
|
+
ruby-version: ${{ matrix.ruby }}
|
|
36
|
+
bundler-cache: true
|
|
37
|
+
- name: Require the declared candidate API
|
|
38
|
+
run: bundle exec ruby -rlutaml/model/lml -e 'raise "missing candidate registry" unless Lutaml::Model::Lml::ValueDeclarations::VERSION == 1'
|
|
39
|
+
- name: Replay native scalar and namespace behavior across adapters
|
|
40
|
+
run: bundle exec rspec spec/omml/portable_spec.rb
|
|
41
|
+
- name: Reproduce the owned declaration artifact
|
|
42
|
+
run: |
|
|
43
|
+
bundle exec ruby -Ilib scripts/export_portable_models.rb .build/portable
|
|
44
|
+
cmp model/portable/enum-subset-v1.json .build/portable/enum-subset-v1.json
|
|
45
|
+
cmp model/portable/scalar-subset-v1.json .build/portable/scalar-subset-v1.json
|
|
46
|
+
cmp model/portable/runtime-graph-v1.json .build/portable/runtime-graph-v1.json
|
|
47
|
+
bundle exec ruby -Ilib -romml -e 'raise "wrong model count" unless Omml::Portable.model_declarations.fetch("models").length == 1'
|
data/.rubocop.yml
CHANGED
data/README.adoc
CHANGED
|
@@ -225,3 +225,30 @@ https://github.com/plurimath/omml.
|
|
|
225
225
|
Copyright Ribose Inc.
|
|
226
226
|
|
|
227
227
|
https://opensource.org/licenses/BSD-2-Clause[BSD-2-Clause License].
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
== Portable enum declarations (candidate)
|
|
231
|
+
|
|
232
|
+
`Omml::Portable.export_bundle(Omml::Models::CTBr)` exports the verified
|
|
233
|
+
closed string enum family through the explicit LutaML named-value
|
|
234
|
+
registry. The registry declares 43 OMML string enums, the two allowed
|
|
235
|
+
`xml:space` values, six bounded integer types, and two coordinate types.
|
|
236
|
+
The accompanying trusted bindings in `model/portable/bindings/` preserve
|
|
237
|
+
Ruby XML casting separately from canonical JSON values.
|
|
238
|
+
|
|
239
|
+
`Omml::Portable.model_declarations` reads the checksummed CTBr graph.
|
|
240
|
+
Pass `"scalar-subset-v1"` for seven native text and integer models, or
|
|
241
|
+
`"runtime-graph-v1"` for the public OMath and OMathPara roots and the
|
|
242
|
+
native model graph with all 26 choice groups. Target generators determine
|
|
243
|
+
which XML mappings they can realize. The TypeScript candidate replays the
|
|
244
|
+
native formula corpus through both public roots.
|
|
245
|
+
|
|
246
|
+
`Omml::Portable.native_bindings(bundle)` supplies the verified native class
|
|
247
|
+
bindings separately. The source XML corpus uses the existing
|
|
248
|
+
`use_prefix: true` writer option to retain qualified attribute QNames.
|
|
249
|
+
|
|
250
|
+
To reproduce the declaration artifact, check out the exact framework commit
|
|
251
|
+
from `.github/workflows/portable.yml`, set `LUTAML_MODEL_SOURCE` to that
|
|
252
|
+
checkout and `LUTAML_MODEL_COMMIT` to its SHA, then run
|
|
253
|
+
`BUNDLE_GEMFILE=.ci/Gemfile.portable bundle exec ruby scripts/export_portable_models.rb`.
|
|
254
|
+
No callback code is serialized into the artifact.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Omml
|
|
4
4
|
module Models
|
|
5
5
|
class CTAnchor < Base
|
|
6
|
-
attribute :
|
|
6
|
+
attribute :simple_position, :ct_point2_d
|
|
7
7
|
attribute :position_h, :ct_pos_h
|
|
8
8
|
attribute :position_v, :ct_pos_v
|
|
9
9
|
attribute :extent, :ct_positive_size2_d
|
|
@@ -31,7 +31,7 @@ module Omml
|
|
|
31
31
|
namespace Omml::Namespace
|
|
32
32
|
|
|
33
33
|
sequence do
|
|
34
|
-
map_element :simplePos, to: :
|
|
34
|
+
map_element :simplePos, to: :simple_position, render_empty: true
|
|
35
35
|
map_element :positionH, to: :position_h, render_empty: true
|
|
36
36
|
map_element :positionV, to: :position_v, render_empty: true
|
|
37
37
|
map_element :extent, to: :extent, render_empty: true
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Omml
|
|
4
|
+
module Models
|
|
5
|
+
class STHexColorAuto < Lutaml::Model::Type::String
|
|
6
|
+
def self.cast(value, options = {})
|
|
7
|
+
return if value.nil?
|
|
8
|
+
|
|
9
|
+
options[:values] = [super("auto")]
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
Omml::Configuration.register_model(STHexColorAuto, id: :st_hex_color_auto)
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/omml/models.rb
CHANGED
|
@@ -232,6 +232,8 @@ module Omml
|
|
|
232
232
|
autoload :STFldCharType, "omml/models/simple_types/st_fld_char_type"
|
|
233
233
|
autoload :STGeomGuideName, "omml/models/simple_types/st_geom_guide_name"
|
|
234
234
|
autoload :STHexColor, "omml/models/simple_types/st_hex_color"
|
|
235
|
+
autoload :STHexColorAuto, "omml/models/simple_types/st_hex_color_auto"
|
|
236
|
+
autoload :STHexColorRGB, "omml/models/simple_types/st_hex_color_rgb"
|
|
235
237
|
autoload :STHighlightColor, "omml/models/simple_types/st_highlight_color"
|
|
236
238
|
autoload :STHint, "omml/models/simple_types/st_hint"
|
|
237
239
|
autoload :STInfoTextType, "omml/models/simple_types/st_info_text_type"
|
|
@@ -239,6 +241,7 @@ module Omml
|
|
|
239
241
|
autoload :STInteger255, "omml/models/simple_types/st_integer255"
|
|
240
242
|
autoload :STJc, "omml/models/simple_types/st_jc"
|
|
241
243
|
autoload :STLang, "omml/models/simple_types/st_lang"
|
|
244
|
+
autoload :STLangCode, "omml/models/simple_types/st_lang_code"
|
|
242
245
|
autoload :STLimLoc, "omml/models/simple_types/st_lim_loc"
|
|
243
246
|
autoload :STLock, "omml/models/simple_types/st_lock"
|
|
244
247
|
autoload :STOnOff, "omml/models/simple_types/st_on_off"
|
data/lib/omml/opal.rb
CHANGED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
if RUBY_ENGINE != "opal"
|
|
4
|
+
require "json"
|
|
5
|
+
require "digest"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
module Omml
|
|
9
|
+
# Only explicitly verified scalar declarations participate in this registry.
|
|
10
|
+
module Portable
|
|
11
|
+
REGISTRY_VERSION = 1
|
|
12
|
+
DIRECTORY = if RUBY_ENGINE != "opal"
|
|
13
|
+
File.expand_path("../../model/portable", __dir__).freeze
|
|
14
|
+
end
|
|
15
|
+
ENUM_TYPES = %i[
|
|
16
|
+
STAlignH STAlignV STBorder STBrClear
|
|
17
|
+
STBrType STBreakBin STBreakBinSub STCalendarType
|
|
18
|
+
STCombineBrackets STDisplacedByCustomXml STEdGrp STEm
|
|
19
|
+
STFFTextType STFType STFldCharType STHighlightColor
|
|
20
|
+
STHint STInfoTextType STJc STLimLoc
|
|
21
|
+
STLock STOnOff STPTabAlignment STPTabLeader
|
|
22
|
+
STPTabRelativeTo STProofErr STRelFromH STRelFromV
|
|
23
|
+
STRubyAlign STScript STSdtDateMappingType STShd
|
|
24
|
+
STShp STStyle STTextEffect STTheme
|
|
25
|
+
STThemeColor STTopBot STUnderline STVerticalAlignRun
|
|
26
|
+
STWrapText STXAlign STYAlign
|
|
27
|
+
].freeze
|
|
28
|
+
INTEGER_BOUNDS = {
|
|
29
|
+
UnsignedInt: [0, 4_294_967_295].freeze,
|
|
30
|
+
UnsignedLong: [0, 18_446_744_073_709_551_615].freeze,
|
|
31
|
+
STInteger2: [-2, 2].freeze,
|
|
32
|
+
STInteger255: [1, 255].freeze,
|
|
33
|
+
STSpacingRule: [0, 4].freeze,
|
|
34
|
+
STTextScale: [0, 600].freeze,
|
|
35
|
+
}.freeze
|
|
36
|
+
DECIMAL_BOUNDS = {
|
|
37
|
+
STCoordinate: [-27_273_042_329_600, 27_273_042_316_900].freeze,
|
|
38
|
+
STPositiveCoordinate: [0, 27_273_042_316_900].freeze,
|
|
39
|
+
}.freeze
|
|
40
|
+
REQUIRED_RUNTIME = "portable scalar export requires " \
|
|
41
|
+
"named-value declaration registry version 1"
|
|
42
|
+
|
|
43
|
+
class UnsupportedRuntime < StandardError; end
|
|
44
|
+
|
|
45
|
+
module_function
|
|
46
|
+
|
|
47
|
+
def model_declarations(graph = "enum-subset-v1")
|
|
48
|
+
unless DIRECTORY
|
|
49
|
+
raise UnsupportedRuntime,
|
|
50
|
+
"load model declarations through the target runtime"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
entry = declaration_manifest.fetch("graphs").fetch(graph)
|
|
54
|
+
bytes = File.binread(File.join(DIRECTORY, entry.fetch("file")))
|
|
55
|
+
unless Digest::SHA256.hexdigest(bytes) == entry.fetch("sha256")
|
|
56
|
+
raise UnsupportedRuntime, "OMML model declaration checksum mismatch"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
JSON.parse(bytes)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def enum_declarations
|
|
63
|
+
require_registry!
|
|
64
|
+
make_registry(enum_entries)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def value_declarations
|
|
68
|
+
require_registry!
|
|
69
|
+
make_registry(value_entries)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def export_bundle(roots, register: nil)
|
|
73
|
+
declarations = value_declarations
|
|
74
|
+
Omml::Models.eager_load!
|
|
75
|
+
Omml::Configuration.populate_context! unless Omml::Configuration.context
|
|
76
|
+
Lutaml::Model::Lml.export_bundle(
|
|
77
|
+
roots, register: register || Omml::Configuration.context_id,
|
|
78
|
+
value_declarations: declarations
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Native bindings remain separate from declaration bytes.
|
|
83
|
+
def native_bindings(bundle)
|
|
84
|
+
require_registry!
|
|
85
|
+
entries = value_entries
|
|
86
|
+
declarations = make_registry(entries)
|
|
87
|
+
classes = entries.keys.to_h { |klass| [klass.name, klass] }
|
|
88
|
+
bundle.value_types.to_h do |id, definition|
|
|
89
|
+
klass = classes[id.split("@", 2).first]
|
|
90
|
+
[id, verified_binding(id, definition, declarations, klass)]
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def require_registry!
|
|
95
|
+
if RUBY_ENGINE == "opal"
|
|
96
|
+
raise UnsupportedRuntime, REQUIRED_RUNTIME
|
|
97
|
+
else
|
|
98
|
+
require "lutaml/model/lml"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
raise UnsupportedRuntime, REQUIRED_RUNTIME unless registry_available?
|
|
102
|
+
rescue LoadError => e
|
|
103
|
+
raise unless e.path == "lutaml/model/lml"
|
|
104
|
+
|
|
105
|
+
raise UnsupportedRuntime, REQUIRED_RUNTIME
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def registry_available?
|
|
109
|
+
defined?(Lutaml::Model::Lml::ValueDeclarations) &&
|
|
110
|
+
Lutaml::Model::Lml::ValueDeclarations::VERSION == REGISTRY_VERSION
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def make_registry(entries)
|
|
114
|
+
Lutaml::Model::Lml::ValueDeclarations.new(entries,
|
|
115
|
+
version: REGISTRY_VERSION)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def enum_entries
|
|
119
|
+
entries = ENUM_TYPES.to_h do |name|
|
|
120
|
+
klass = Omml::Models.const_get(name, false)
|
|
121
|
+
# The native String validator accepts empty strings before enum checks.
|
|
122
|
+
[klass, enum_definition([*klass::VALUES, ""])]
|
|
123
|
+
end
|
|
124
|
+
entries[Lutaml::Xml::W3c::XmlSpaceType] =
|
|
125
|
+
enum_definition(%w[default preserve])
|
|
126
|
+
entries
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def enum_definition(values)
|
|
130
|
+
{ "base" => "string", "facets" => { "enumeration" => values.dup } }
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def value_entries
|
|
134
|
+
enum_entries
|
|
135
|
+
.merge(numeric_entries(INTEGER_BOUNDS, "integer"))
|
|
136
|
+
.merge(numeric_entries(DECIMAL_BOUNDS, "decimal"))
|
|
137
|
+
.merge(string_entries)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def numeric_entries(bounds, base)
|
|
141
|
+
bounds.to_h do |name, (min, max)|
|
|
142
|
+
klass = Omml::Models.const_get(name, false)
|
|
143
|
+
[klass, {
|
|
144
|
+
"base" => base,
|
|
145
|
+
"facets" => {
|
|
146
|
+
"min_inclusive" => min.to_s,
|
|
147
|
+
"max_inclusive" => max.to_s,
|
|
148
|
+
"source_binding_v1" => true,
|
|
149
|
+
},
|
|
150
|
+
}]
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def string_entries
|
|
155
|
+
# HexBinary's native pattern matches every String, including empty.
|
|
156
|
+
# The restored STLangCode alias uses exactly that String cast.
|
|
157
|
+
transparent = { "base" => "string", "facets" => {} }
|
|
158
|
+
{
|
|
159
|
+
Omml::Models::HexBinary => transparent,
|
|
160
|
+
Omml::Models::STLang => transparent,
|
|
161
|
+
Omml::Models::STHexColor => enum_definition(["auto", ""]),
|
|
162
|
+
Omml::Models::Token => {
|
|
163
|
+
"base" => "string", "facets" => { "source_binding_v1" => true }
|
|
164
|
+
},
|
|
165
|
+
}
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def verified_binding(id, definition, declarations, klass)
|
|
169
|
+
unless klass && definition == declarations.fetch(klass)
|
|
170
|
+
raise Lutaml::Model::Lml::RejectedError.new(
|
|
171
|
+
:missing_type_binding, nil, "unverified scalar binding: #{id}"
|
|
172
|
+
)
|
|
173
|
+
end
|
|
174
|
+
klass
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def declaration_manifest
|
|
178
|
+
manifest = JSON.parse(File.binread(File.join(DIRECTORY,
|
|
179
|
+
"manifest.json")))
|
|
180
|
+
unless manifest["manifest"] == 1
|
|
181
|
+
raise UnsupportedRuntime, "unsupported OMML declaration manifest"
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
manifest
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
private_class_method :require_registry!, :registry_available?,
|
|
188
|
+
:make_registry, :enum_entries, :enum_definition,
|
|
189
|
+
:value_entries, :numeric_entries, :string_entries,
|
|
190
|
+
:verified_binding, :declaration_manifest
|
|
191
|
+
end
|
|
192
|
+
end
|
data/lib/omml/version.rb
CHANGED
data/lib/omml.rb
CHANGED
|
@@ -11,6 +11,7 @@ module Omml
|
|
|
11
11
|
autoload :Models, "omml/models"
|
|
12
12
|
autoload :Namespace, "omml/namespace"
|
|
13
13
|
autoload :Parser, "omml/parser"
|
|
14
|
+
autoload :Portable, "omml/portable"
|
|
14
15
|
autoload :TypeSubstitutions, "omml/type_substitutions"
|
|
15
16
|
autoload :WordprocessingNamespace, "omml/wordprocessing_namespace"
|
|
16
17
|
|