suma 0.1.0 → 0.1.1
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/.github/workflows/rake.yml +15 -0
- data/.github/workflows/release.yml +25 -0
- data/.rubocop.yml +8 -6
- data/lib/suma/collection_config.rb +22 -0
- data/lib/suma/collection_manifest.rb +124 -0
- data/lib/suma/express_schema.rb +12 -6
- data/lib/suma/processor.rb +22 -27
- data/lib/suma/{schema_doc.rb → schema_attachment.rb} +15 -9
- data/lib/suma/schema_collection.rb +46 -18
- data/lib/suma/schema_config/config.rb +50 -8
- data/lib/suma/schema_config/schema.rb +1 -0
- data/lib/suma/schema_document.rb +96 -0
- data/lib/suma/site_config.rb +29 -0
- data/lib/suma/version.rb +1 -1
- metadata +13 -10
- data/.github/workflows/main.yml +0 -27
- data/lib/suma/to_replace/collection_config.rb +0 -112
- data/lib/suma/to_replace/site_config.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0cee8119660d33e2592a44875f218ff7cad624c0c5ff89430c5f97eda5f593e
|
4
|
+
data.tar.gz: 9fdc83bc1383b931d0907d9f31e4d94986a7922b55ef4f82ae437b4a52833f08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2e87931a5396a1b42245c0d3156345e539b6d1f11bb82b6fcc9537603cec0f1d084e7636705d5eae87b180bc1618a77330e616b714ed1b94ae25f910a7209a6
|
7
|
+
data.tar.gz: 80eebf4ce42b572fb812a8729d6a71e9a96ed08d7d2d2c04b9b9884d721adf70075a6c2ccc6d400bdbc94573edc44f273baec9c9adcb7517134a6473cbabfdf4
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: rake
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master, main ]
|
8
|
+
tags: [ v* ]
|
9
|
+
pull_request:
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
rake:
|
13
|
+
uses: metanorma/ci/.github/workflows/generic-rake.yml@main
|
14
|
+
secrets:
|
15
|
+
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: release
|
4
|
+
|
5
|
+
on:
|
6
|
+
workflow_dispatch:
|
7
|
+
inputs:
|
8
|
+
next_version:
|
9
|
+
description: |
|
10
|
+
Next release version. Possible values: x.y.z, major, minor, patch (or pre|rc|etc).
|
11
|
+
Also, you can pass 'skip' to skip 'git tag' and do 'gem push' for the current version
|
12
|
+
required: true
|
13
|
+
default: 'skip'
|
14
|
+
repository_dispatch:
|
15
|
+
types: [ do-release ]
|
16
|
+
|
17
|
+
jobs:
|
18
|
+
release:
|
19
|
+
uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
|
20
|
+
with:
|
21
|
+
next_version: ${{ github.event.inputs.next_version }}
|
22
|
+
secrets:
|
23
|
+
rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
|
24
|
+
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
|
25
|
+
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
inherit_from:
|
4
|
+
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
+
# local repo-specific modifications
|
7
|
+
# ...
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
AllCops:
|
10
|
+
TargetRubyVersion: 3.4
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "utils"
|
4
|
+
require "shale"
|
5
|
+
require_relative "collection_manifest"
|
6
|
+
require "metanorma/cli"
|
7
|
+
require "metanorma/cli/collection"
|
8
|
+
require "metanorma/collection/collection"
|
9
|
+
|
10
|
+
module Suma
|
11
|
+
class CollectionConfig < Metanorma::Collection::Config::Config
|
12
|
+
attribute :manifest, ::Suma::CollectionManifest
|
13
|
+
|
14
|
+
def self.from_file(path)
|
15
|
+
from_yaml(File.read(path))
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_file(path)
|
19
|
+
File.open(path, "w") { |f| f.write to_yaml }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "metanorma/cli"
|
4
|
+
require "metanorma/cli/collection"
|
5
|
+
require "metanorma/collection/collection"
|
6
|
+
|
7
|
+
module Suma
|
8
|
+
class CollectionManifest < Metanorma::Collection::Config::Manifest
|
9
|
+
attribute :schemas_only, Shale::Type::Boolean
|
10
|
+
attribute :entry, CollectionManifest, collection: true
|
11
|
+
# attribute :schema_source, Shale::Type::String
|
12
|
+
attr_accessor :schema_config
|
13
|
+
|
14
|
+
yaml do
|
15
|
+
map "identifier", to: :identifier
|
16
|
+
map "type", to: :type
|
17
|
+
map "level", using: { from: :level_from_yaml, to: :nop_to_yaml }
|
18
|
+
map "title", to: :title
|
19
|
+
map "url", to: :url
|
20
|
+
map "attachment", to: :attachment
|
21
|
+
map "sectionsplit", to: :sectionsplit
|
22
|
+
map "schemas-only", to: :schemas_only
|
23
|
+
map "index", to: :index
|
24
|
+
map "file", to: :file
|
25
|
+
map "fileref", using: { from: :fileref_from_yaml, to: :nop_to_yaml }
|
26
|
+
map "entry", to: :entry
|
27
|
+
map "docref", using: { from: :docref_from_yaml, to: :nop_to_yaml }
|
28
|
+
map "manifest", using: { from: :docref_from_yaml, to: :nop_to_yaml }
|
29
|
+
map "bibdata", using: { from: :bibdata_from_yaml,
|
30
|
+
to: :bibdata_to_yaml }
|
31
|
+
end
|
32
|
+
|
33
|
+
def docref_from_yaml(model, value)
|
34
|
+
model.entry = CollectionManifest.from_yaml(value.to_yaml)
|
35
|
+
end
|
36
|
+
|
37
|
+
def export_schema_config(path)
|
38
|
+
export_config = @schema_config || Suma::SchemaConfig::Config.new
|
39
|
+
return export_config unless entry
|
40
|
+
|
41
|
+
entry.each do |x|
|
42
|
+
child_config = x.export_schema_config(path)
|
43
|
+
export_config.concat(child_config) if child_config
|
44
|
+
end
|
45
|
+
|
46
|
+
export_config
|
47
|
+
end
|
48
|
+
|
49
|
+
def lookup(attr_sym, match)
|
50
|
+
results = entry.select { |e| e.send(attr_sym) == match }
|
51
|
+
results << self if send(attr_sym) == match
|
52
|
+
results
|
53
|
+
end
|
54
|
+
|
55
|
+
def process_entry(schema_output_path)
|
56
|
+
return [self] unless entry
|
57
|
+
|
58
|
+
ret = entry.each_with_object([]) do |e, m|
|
59
|
+
add = e.expand_schemas_only(schema_output_path)
|
60
|
+
m.concat(add)
|
61
|
+
end
|
62
|
+
|
63
|
+
self.entry = ret
|
64
|
+
[self]
|
65
|
+
end
|
66
|
+
|
67
|
+
def expand_schemas_only(schema_output_path)
|
68
|
+
return process_entry(schema_output_path) unless file
|
69
|
+
|
70
|
+
# If there is collection.yml, this is a document collection, we process
|
71
|
+
# schemas.yaml.
|
72
|
+
if File.basename(file) == 'collection.yml'
|
73
|
+
schemas_yaml_path = File.join(File.dirname(file), "schemas.yaml")
|
74
|
+
if schemas_yaml_path && File.exist?(schemas_yaml_path)
|
75
|
+
@schema_config = Suma::SchemaConfig::Config.from_file(schemas_yaml_path)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
return process_entry(schema_output_path) unless schemas_only
|
80
|
+
|
81
|
+
# If we are going to keep the schemas-only file and compile it, we can't
|
82
|
+
# have it showing up in output.
|
83
|
+
self.index = false
|
84
|
+
|
85
|
+
doc = CollectionConfig.from_file(file)
|
86
|
+
doc_id = doc.bibdata.id
|
87
|
+
|
88
|
+
entries = @schema_config.schemas.map do |schema|
|
89
|
+
fname = [File.basename(schema.path, ".exp"), ".xml"].join
|
90
|
+
|
91
|
+
CollectionManifest.new(
|
92
|
+
identifier: schema.id,
|
93
|
+
title: schema.id,
|
94
|
+
file: File.join(schema_output_path, schema.id, "doc_#{fname}"),
|
95
|
+
# schema_source: schema.path
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
# we need to separate this file from the following new entries
|
100
|
+
added = CollectionManifest.new(
|
101
|
+
title: "Collection",
|
102
|
+
type: "collection",
|
103
|
+
identifier: self.identifier + "_"
|
104
|
+
)
|
105
|
+
|
106
|
+
added.entry = [
|
107
|
+
CollectionManifest.new(
|
108
|
+
title: doc_id,
|
109
|
+
type: "document",
|
110
|
+
entry: entries,
|
111
|
+
),
|
112
|
+
]
|
113
|
+
|
114
|
+
[self, added]
|
115
|
+
end
|
116
|
+
|
117
|
+
def remove_schemas_only_sources
|
118
|
+
ret = entry.each_with_object([]) do |e, m|
|
119
|
+
e.schemas_only or m << e
|
120
|
+
end
|
121
|
+
self.entry = ret
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/lib/suma/express_schema.rb
CHANGED
@@ -8,12 +8,9 @@ module Suma
|
|
8
8
|
class ExpressSchema
|
9
9
|
attr_accessor :path, :id, :parsed, :output_path
|
10
10
|
|
11
|
-
def initialize(path:, output_path:)
|
11
|
+
def initialize(id:, path:, output_path:)
|
12
12
|
@path = Pathname.new(path).expand_path
|
13
|
-
@
|
14
|
-
Utils.log "Loaded EXPRESS schema: #{path}"
|
15
|
-
|
16
|
-
@id = @parsed.schemas.first.id
|
13
|
+
@id = id
|
17
14
|
@output_path = output_path
|
18
15
|
end
|
19
16
|
|
@@ -28,8 +25,17 @@ module Suma
|
|
28
25
|
end
|
29
26
|
end
|
30
27
|
|
28
|
+
def parsed
|
29
|
+
return @parsed if @parsed
|
30
|
+
|
31
|
+
@parsed = Expressir::Express::Parser.from_file(@path.to_s)
|
32
|
+
Utils.log "Loaded EXPRESS schema: #{path}"
|
33
|
+
@id = @parsed.schemas.first.id
|
34
|
+
@parsed
|
35
|
+
end
|
36
|
+
|
31
37
|
def to_plain
|
32
|
-
|
38
|
+
parsed.to_s(no_remarks: true)
|
33
39
|
end
|
34
40
|
|
35
41
|
def filename_plain
|
data/lib/suma/processor.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
require_relative "schema_config"
|
4
4
|
require_relative "schema_collection"
|
5
5
|
require_relative "utils"
|
6
|
-
require_relative "
|
7
|
-
require_relative "
|
6
|
+
require_relative "collection_config"
|
7
|
+
require_relative "site_config"
|
8
8
|
require "metanorma/cli"
|
9
9
|
require "metanorma/cli/collection"
|
10
10
|
require "metanorma/collection/collection"
|
@@ -12,43 +12,33 @@ require "metanorma/collection/collection"
|
|
12
12
|
module Suma
|
13
13
|
class Processor
|
14
14
|
class << self
|
15
|
-
# Can move to schema_config.rb
|
16
|
-
def write_all_schemas(schemas_all_path, document_paths)
|
17
|
-
all_schemas = Suma::SchemaConfig::Config.new(path: schemas_all_path)
|
18
|
-
|
19
|
-
document_paths.each do |path|
|
20
|
-
schemas_yaml = File.join(File.dirname(path), "schemas.yaml")
|
21
|
-
next unless File.exist?(schemas_yaml)
|
22
|
-
|
23
|
-
schemas_config = Suma::SchemaConfig::Config.from_file(schemas_yaml)
|
24
|
-
all_schemas.concat(schemas_config)
|
25
|
-
end
|
26
|
-
|
27
|
-
Utils.log "Writing #{schemas_all_path}..."
|
28
|
-
all_schemas.to_file
|
29
|
-
Utils.log "Done."
|
30
|
-
end
|
31
15
|
|
32
16
|
def run(metanorma_yaml_path:, schemas_all_path:, compile:, output_directory: "_site")
|
33
17
|
Utils.log "Current directory: #{Dir.getwd}"
|
34
18
|
|
35
19
|
# This reads the metanorma.yml file
|
36
|
-
site_config = Suma::
|
20
|
+
site_config = Suma::SiteConfig::Config.from_file(metanorma_yaml_path)
|
37
21
|
|
38
22
|
# TODO: only reading the first file, which is a collection.yml, which is a hack...
|
39
23
|
collection_config_path = site_config.metanorma.source.files.first
|
40
|
-
collection_config = Suma::
|
24
|
+
collection_config = Suma::CollectionConfig.from_file(collection_config_path)
|
41
25
|
collection_config.path = collection_config_path
|
26
|
+
collection_config.manifest.expand_schemas_only("schema_docs")
|
42
27
|
|
43
|
-
|
44
|
-
|
28
|
+
exported_schema_config = collection_config.manifest.export_schema_config(schemas_all_path)
|
29
|
+
exported_schema_config.path = schemas_all_path
|
45
30
|
|
46
|
-
|
31
|
+
Utils.log "Writing #{schemas_all_path}..."
|
32
|
+
exported_schema_config.to_file
|
33
|
+
Utils.log "Done."
|
34
|
+
|
35
|
+
# now get rid of the source documents for schema sources
|
47
36
|
|
48
37
|
col = Suma::SchemaCollection.new(
|
49
38
|
config_yaml: schemas_all_path,
|
39
|
+
manifest: collection_config.manifest,
|
50
40
|
output_path_docs: "schema_docs",
|
51
|
-
output_path_schemas: "plain_schemas"
|
41
|
+
output_path_schemas: "plain_schemas",
|
52
42
|
)
|
53
43
|
|
54
44
|
if compile
|
@@ -58,6 +48,10 @@ module Suma
|
|
58
48
|
Utils.log "No compile option set. Skipping schema compilation."
|
59
49
|
end
|
60
50
|
|
51
|
+
new_collection_config_path = "collection-output.yaml"
|
52
|
+
collection_config.manifest.remove_schemas_only_sources
|
53
|
+
collection_config.to_file(new_collection_config_path)
|
54
|
+
|
61
55
|
# TODO: Do we still need this?
|
62
56
|
# Define Proc to resolve fileref
|
63
57
|
my_fileref_proc = proc do |ref_folder, fileref|
|
@@ -97,16 +91,17 @@ module Suma
|
|
97
91
|
if compile
|
98
92
|
Utils.log "Compiling complete collection..."
|
99
93
|
|
100
|
-
|
94
|
+
# TODO: Why will defining a collection immediately compile??
|
95
|
+
metanorma_collection = Metanorma::Collection.parse(new_collection_config_path)
|
101
96
|
|
102
97
|
# TODO: Somehow this is no longer used
|
103
98
|
collection_opts = {
|
104
99
|
format: [:html],
|
105
100
|
output_folder: output_directory,
|
106
101
|
compile: {
|
107
|
-
|
102
|
+
install_fonts: false,
|
108
103
|
},
|
109
|
-
coverpage: "cover.html"
|
104
|
+
coverpage: "cover.html",
|
110
105
|
}
|
111
106
|
metanorma_collection.render(collection_opts)
|
112
107
|
|
@@ -5,28 +5,33 @@ require "fileutils"
|
|
5
5
|
require_relative "schema_config"
|
6
6
|
|
7
7
|
module Suma
|
8
|
-
class
|
9
|
-
attr_accessor :schema, :output_path, :config
|
8
|
+
class SchemaAttachment
|
9
|
+
attr_accessor :schema, :output_path, :config, :id
|
10
10
|
|
11
11
|
def initialize(schema:, output_path:)
|
12
12
|
@schema = schema
|
13
|
+
@id = schema.id
|
13
14
|
@output_path = output_path
|
14
15
|
end
|
15
16
|
|
17
|
+
def output_extensions
|
18
|
+
"xml,html"
|
19
|
+
end
|
20
|
+
|
16
21
|
def to_adoc(path_to_schema_yaml)
|
17
22
|
<<~HEREDOC
|
18
|
-
= #{@
|
23
|
+
= #{@id}
|
19
24
|
:lutaml-express-index: schemas; #{path_to_schema_yaml};
|
20
25
|
:bare: true
|
21
26
|
:mn-document-class: iso
|
22
|
-
:mn-output-extensions:
|
27
|
+
:mn-output-extensions: #{output_extensions}
|
23
28
|
|
24
29
|
[lutaml,schemas,context]
|
25
30
|
----
|
26
31
|
{% for schema in context.schemas %}
|
27
32
|
|
28
33
|
[%unnumbered]
|
29
|
-
== #{@
|
34
|
+
== #{@id}
|
30
35
|
|
31
36
|
[source%unnumbered]
|
32
37
|
--
|
@@ -88,19 +93,20 @@ module Suma
|
|
88
93
|
|
89
94
|
# Compile Metanorma adoc per EXPRESS schema
|
90
95
|
def compile
|
91
|
-
|
96
|
+
# I am commenting out because I'm playing with the schemas-only status
|
97
|
+
# return self if File.exist?(output_xml_path)
|
92
98
|
|
93
99
|
save_config
|
94
100
|
save_adoc
|
95
101
|
|
96
102
|
relative_path = Pathname.new(filename_adoc).relative_path_from(Dir.pwd)
|
97
|
-
Utils.log "Compiling schema #{relative_path}
|
103
|
+
Utils.log "Compiling schema (id: #{id}, type: #{self.class}) => #{relative_path}"
|
98
104
|
Metanorma::Compile.new.compile(
|
99
105
|
filename_adoc,
|
100
106
|
agree_to_terms: true,
|
101
|
-
|
107
|
+
install_fonts: false
|
102
108
|
)
|
103
|
-
Utils.log "Compiling schema #{
|
109
|
+
Utils.log "Compiling schema (id: #{id}, type: #{self.class}) => #{relative_path}... done!"
|
104
110
|
|
105
111
|
# clean_artifacts
|
106
112
|
|
@@ -1,17 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "express_schema"
|
4
|
-
require_relative "
|
4
|
+
require_relative "schema_attachment"
|
5
|
+
require_relative "schema_document"
|
5
6
|
require_relative "schema_config"
|
6
7
|
require_relative "utils"
|
7
8
|
|
8
9
|
module Suma
|
9
10
|
class SchemaCollection
|
10
|
-
attr_accessor :config, :schemas, :docs, :output_path_docs, :output_path_schemas
|
11
|
+
attr_accessor :config, :schemas, :docs, :output_path_docs, :output_path_schemas,
|
12
|
+
:manifest
|
11
13
|
|
12
|
-
def initialize(config: nil, config_yaml: nil, output_path_docs: nil, output_path_schemas: nil)
|
13
|
-
@schemas =
|
14
|
-
@docs =
|
14
|
+
def initialize(config: nil, config_yaml: nil, output_path_docs: nil, output_path_schemas: nil, manifest: nil)
|
15
|
+
@schemas = {}
|
16
|
+
@docs = {}
|
15
17
|
@schema_name_to_docs = {}
|
16
18
|
@output_path_docs = if output_path_docs
|
17
19
|
Pathname.new(output_path_docs).expand_path
|
@@ -30,34 +32,60 @@ module Suma
|
|
30
32
|
SchemaConfig::Config.from_file(config_yaml)
|
31
33
|
end
|
32
34
|
|
33
|
-
|
35
|
+
@manifest = manifest
|
36
|
+
end
|
37
|
+
|
38
|
+
def doc_from_schema_name(schema_name)
|
39
|
+
@schema_name_to_docs[schema_name]
|
40
|
+
end
|
34
41
|
|
35
|
-
|
42
|
+
def process_schemas(schemas, klass)
|
43
|
+
schemas.each do |config_schema|
|
36
44
|
s = ExpressSchema.new(
|
37
|
-
|
38
|
-
|
45
|
+
id: config_schema.id,
|
46
|
+
path: config_schema.path.to_s,
|
47
|
+
output_path: @output_path_schemas.to_s
|
39
48
|
)
|
40
|
-
|
49
|
+
|
50
|
+
doc = klass.new(
|
41
51
|
schema: s,
|
42
52
|
output_path: @output_path_docs.join(s.id)
|
43
53
|
)
|
44
|
-
|
45
|
-
@
|
54
|
+
|
55
|
+
@docs[s.id] = doc
|
56
|
+
@schemas[s.id] = s
|
46
57
|
@schema_name_to_docs[s.id] = doc
|
47
58
|
end
|
48
59
|
end
|
49
60
|
|
50
|
-
def
|
51
|
-
@
|
61
|
+
def finalize
|
62
|
+
# Process each schema in @config.schemas
|
63
|
+
process_schemas(@config.schemas, SchemaAttachment)
|
64
|
+
|
65
|
+
manifest_entry = @manifest.lookup(:schemas_only, true)
|
66
|
+
|
67
|
+
manifest_entry.each do |entry|
|
68
|
+
next unless entry.schema_config
|
69
|
+
|
70
|
+
# Process each schema in entry.schema_config.schemas
|
71
|
+
process_schemas(entry.schema_config.schemas, SchemaDocument)
|
72
|
+
end
|
52
73
|
end
|
53
74
|
|
54
75
|
def compile
|
55
|
-
|
76
|
+
finalize
|
77
|
+
schemas.each_pair do |schema_id, entry|
|
78
|
+
entry.save_exp
|
79
|
+
end
|
56
80
|
|
57
|
-
|
81
|
+
# DISABLING FOLLOWING CODE AS MISCONCEIVED. THE SCHEMA DOCUMENTS
|
82
|
+
# BELONG IN THE MAIN COLLECTION NOT HERE
|
83
|
+
docs.each_pair do |schema_id, entry|
|
84
|
+
entry.compile
|
85
|
+
end
|
58
86
|
|
59
87
|
# TODO: make this parallel
|
60
|
-
#
|
88
|
+
# Utils.log"Starting Ractor processing"
|
61
89
|
# pool = Ractor.new do
|
62
90
|
# loop do
|
63
91
|
# Ractor.yield(Ractor.receive)
|
@@ -67,7 +95,7 @@ module Suma
|
|
67
95
|
# Ractor.new(pool, name: "r#{i}") do |p|
|
68
96
|
# loop do
|
69
97
|
# input = p.take
|
70
|
-
#
|
98
|
+
# Utils.log"compiling in ractor for #{input.filename_adoc}"
|
71
99
|
# output_value = input.compile
|
72
100
|
# Ractor.yield(output_value)
|
73
101
|
# end
|
@@ -8,10 +8,10 @@ module Suma
|
|
8
8
|
module SchemaConfig
|
9
9
|
class Config < Shale::Mapper
|
10
10
|
attribute :schemas, Schema, collection: true
|
11
|
-
|
11
|
+
attribute :path, Shale::Type::String
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@path = path
|
13
|
+
def initialize(**args)
|
14
|
+
@path = path_relative_to_absolute(path) if path
|
15
15
|
super(**args)
|
16
16
|
end
|
17
17
|
|
@@ -25,7 +25,7 @@ module Suma
|
|
25
25
|
|
26
26
|
def self.from_file(path)
|
27
27
|
from_yaml(File.read(path)).tap do |x|
|
28
|
-
x.path
|
28
|
+
x.set_initial_path(path)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -35,19 +35,61 @@ module Suma
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def set_initial_path(new_path)
|
39
|
+
@path = path_relative_to_absolute(new_path)
|
40
|
+
schemas.each do |schema|
|
41
|
+
schema.path = path_relative_to_absolute(schema.path)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
38
45
|
def schemas_from_yaml(model, value)
|
39
46
|
model.schemas = value.map do |k, v|
|
40
|
-
Schema.new(id: k, path: v["path"])
|
47
|
+
Schema.new(id: k, path: path_relative_to_absolute(v["path"]))
|
41
48
|
end
|
42
49
|
end
|
43
50
|
|
51
|
+
# TODO: I can't get the relative path working. The schemas-*.yaml file is
|
52
|
+
# meant to contain the "path" key, which is a relative path to its
|
53
|
+
# location, then sets the base path to each schema path, which is supposed
|
54
|
+
# to be relative to "path" key. Somehow, the @path variable is always
|
55
|
+
# missing in to_yaml...
|
44
56
|
def schemas_to_yaml(model, doc)
|
57
|
+
# puts "^"*30
|
58
|
+
# pp self
|
59
|
+
# pp @path
|
45
60
|
doc["schemas"] = model.schemas.sort_by(&:id).to_h do |schema|
|
46
|
-
[schema.id, { "path" => schema.path }]
|
61
|
+
[schema.id, { "path" => path_absolute_to_relative(schema.path) }]
|
47
62
|
end
|
48
63
|
end
|
49
64
|
|
65
|
+
def path_relative_to_absolute(relative_path)
|
66
|
+
eval_path = Pathname.new(relative_path)
|
67
|
+
return relative_path if eval_path.absolute?
|
68
|
+
|
69
|
+
# Or based on current working directory?
|
70
|
+
return relative_path unless @path
|
71
|
+
|
72
|
+
Pathname.new(File.dirname(@path)).join(eval_path).expand_path.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
def path_absolute_to_relative(absolute_path)
|
76
|
+
# puts "path_absolute_to_relative 1 #{absolute_path}"
|
77
|
+
# pp self
|
78
|
+
# pp path
|
79
|
+
# pp @hello
|
80
|
+
return absolute_path unless @path
|
81
|
+
|
82
|
+
relative_path = Pathname.new(absolute_path).relative_path_from(Pathname.new(@path).dirname).to_s
|
83
|
+
# puts "path_absolute_to_relative x #{relative_path}"
|
84
|
+
relative_path
|
85
|
+
end
|
86
|
+
|
50
87
|
def update_path(new_path)
|
88
|
+
if @path.nil?
|
89
|
+
@path = new_path
|
90
|
+
return @path
|
91
|
+
end
|
92
|
+
|
51
93
|
old_base_path = File.dirname(@path)
|
52
94
|
new_base_path = File.dirname(new_path)
|
53
95
|
|
@@ -68,8 +110,8 @@ module Suma
|
|
68
110
|
raise StandardError, "Can only concatenate a non SchemaConfig::Config object."
|
69
111
|
end
|
70
112
|
|
71
|
-
# We need to update the relative paths
|
72
|
-
if path != another_config.path
|
113
|
+
# We need to update the relative paths when paths exist
|
114
|
+
if path && another_config.path && path != another_config.path
|
73
115
|
new_config = another_config.dup
|
74
116
|
new_config.update_path(path)
|
75
117
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "schema_attachment"
|
4
|
+
|
5
|
+
module Suma
|
6
|
+
class SchemaDocument < SchemaAttachment
|
7
|
+
def bookmark(anchor)
|
8
|
+
a = anchor.gsub(/\}\}/, ' | replace: "\", "-"}}')
|
9
|
+
"[[#{@id}.#{a}]]"
|
10
|
+
end
|
11
|
+
|
12
|
+
def schema_anchors
|
13
|
+
<<~HEREDOC
|
14
|
+
// _fund_cons.liquid
|
15
|
+
[[#{@id}_funds]]
|
16
|
+
|
17
|
+
// _constants.liquid
|
18
|
+
{% if schema.constants.size > 0 %}
|
19
|
+
#{bookmark("constants")}
|
20
|
+
{% for thing in schema.constants %}
|
21
|
+
#{bookmark("{{thing.id}}")}
|
22
|
+
{% endfor %}
|
23
|
+
{% endif %}
|
24
|
+
|
25
|
+
// _types.liquid
|
26
|
+
{% if schema.types.size > 0 %}
|
27
|
+
#{bookmark("types")}
|
28
|
+
// _type.liquid
|
29
|
+
{% for thing in schema.types %}
|
30
|
+
#{bookmark("{{thing.id}}")}
|
31
|
+
{% if thing.items.size > 0 %}
|
32
|
+
// _type_items.liquid
|
33
|
+
#{bookmark("{{thing.id}}.items")}
|
34
|
+
{% for item in thing.items %}
|
35
|
+
#{bookmark("{{thing.id}}.items.{{item.id}}")}
|
36
|
+
{% endfor %}
|
37
|
+
{% endif %}
|
38
|
+
{% endfor %}
|
39
|
+
{% endif %}
|
40
|
+
|
41
|
+
// _entities.liquid
|
42
|
+
{% if schema.entities.size > 0 %}
|
43
|
+
#{bookmark("entities")}
|
44
|
+
{% for thing in schema.entities %}
|
45
|
+
// _entity.liquid
|
46
|
+
#{bookmark("{{thing.id}}")}
|
47
|
+
{% endfor %}
|
48
|
+
{% endif %}
|
49
|
+
HEREDOC
|
50
|
+
end
|
51
|
+
|
52
|
+
# ////
|
53
|
+
# TODO:
|
54
|
+
# % render "templates/entities", schema: schema, schema_id: schema.id, things: schema.entities, thing_prefix: root_thing_prefix, depth: 2 %
|
55
|
+
#
|
56
|
+
# % render "templates/subtype_constraints", schema_id: schema.id, things: schema.subtype_constraints, thing_prefix: root_thing_prefix, depth: 2 %
|
57
|
+
#
|
58
|
+
# % render "templates/functions", schema_id: schema.id, things: schema.functions, thing_prefix: root_thing_prefix, depth: 2 %
|
59
|
+
#
|
60
|
+
# % render "templates/procedures", schema_id: schema.id, things: schema.procedures, thing_prefix: root_thing_prefix, depth: 2 %
|
61
|
+
#
|
62
|
+
# % render "templates/rules", schema_id: schema.id, things: schema.rules, thing_prefix: root_thing_prefix, depth: 2 %
|
63
|
+
# ////
|
64
|
+
|
65
|
+
def output_extensions
|
66
|
+
"xml"
|
67
|
+
end
|
68
|
+
|
69
|
+
# #.gsub(/[\n\r]{2,}/, '')
|
70
|
+
def to_adoc(path_to_schema_yaml)
|
71
|
+
<<~HEREDOC
|
72
|
+
= #{@schema.id}
|
73
|
+
:lutaml-express-index: schemas; #{path_to_schema_yaml};
|
74
|
+
:bare: true
|
75
|
+
:mn-document-class: iso
|
76
|
+
:mn-output-extensions: xml,html
|
77
|
+
|
78
|
+
[lutaml,schemas,context]
|
79
|
+
----
|
80
|
+
{% for schema in context.schemas %}
|
81
|
+
|
82
|
+
[[#{@id}]]
|
83
|
+
[%unnumbered,type=express]
|
84
|
+
== #{@id} #{schema_anchors.gsub(%r{//[^\r\n]+}, "").gsub(/[\n\r]+/, "").gsub(/^[\n\r]/, "")}
|
85
|
+
|
86
|
+
[source%unnumbered]
|
87
|
+
--
|
88
|
+
{{ schema.formatted }}
|
89
|
+
--
|
90
|
+
{% endfor %}
|
91
|
+
----
|
92
|
+
|
93
|
+
HEREDOC
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "shale"
|
4
|
+
|
5
|
+
module Suma
|
6
|
+
module SiteConfig
|
7
|
+
class SiteInfo < Shale::Mapper
|
8
|
+
attribute :organization, Shale::Type::String
|
9
|
+
attribute :name, Shale::Type::String
|
10
|
+
end
|
11
|
+
|
12
|
+
class Sources < Shale::Mapper
|
13
|
+
attribute :files, Shale::Type::String, collection: true
|
14
|
+
end
|
15
|
+
|
16
|
+
class Base < Shale::Mapper
|
17
|
+
attribute :source, Sources
|
18
|
+
attribute :collection, SiteInfo
|
19
|
+
end
|
20
|
+
|
21
|
+
class Config < Shale::Mapper
|
22
|
+
attribute :metanorma, Base
|
23
|
+
|
24
|
+
def self.from_file(path)
|
25
|
+
from_yaml(File.read(path))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/suma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: suma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: expressir
|
@@ -118,7 +118,8 @@ executables:
|
|
118
118
|
extensions: []
|
119
119
|
extra_rdoc_files: []
|
120
120
|
files:
|
121
|
-
- ".github/workflows/
|
121
|
+
- ".github/workflows/rake.yml"
|
122
|
+
- ".github/workflows/release.yml"
|
122
123
|
- ".gitignore"
|
123
124
|
- ".rspec"
|
124
125
|
- ".rubocop.yml"
|
@@ -131,16 +132,18 @@ files:
|
|
131
132
|
- exe/suma
|
132
133
|
- lib/suma.rb
|
133
134
|
- lib/suma/cli.rb
|
135
|
+
- lib/suma/collection_config.rb
|
136
|
+
- lib/suma/collection_manifest.rb
|
134
137
|
- lib/suma/express_schema.rb
|
135
138
|
- lib/suma/processor.rb
|
139
|
+
- lib/suma/schema_attachment.rb
|
136
140
|
- lib/suma/schema_collection.rb
|
137
141
|
- lib/suma/schema_config.rb
|
138
142
|
- lib/suma/schema_config/config.rb
|
139
143
|
- lib/suma/schema_config/schema.rb
|
140
|
-
- lib/suma/
|
144
|
+
- lib/suma/schema_document.rb
|
145
|
+
- lib/suma/site_config.rb
|
141
146
|
- lib/suma/thor_ext.rb
|
142
|
-
- lib/suma/to_replace/collection_config.rb
|
143
|
-
- lib/suma/to_replace/site_config.rb
|
144
147
|
- lib/suma/utils.rb
|
145
148
|
- lib/suma/version.rb
|
146
149
|
- sig/suma.rbs
|
@@ -149,7 +152,7 @@ homepage: https://github.com/metanorma/suma
|
|
149
152
|
licenses:
|
150
153
|
- BSD-2-Clause
|
151
154
|
metadata: {}
|
152
|
-
post_install_message:
|
155
|
+
post_install_message:
|
153
156
|
rdoc_options: []
|
154
157
|
require_paths:
|
155
158
|
- lib
|
@@ -164,8 +167,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
167
|
- !ruby/object:Gem::Version
|
165
168
|
version: '0'
|
166
169
|
requirements: []
|
167
|
-
rubygems_version: 3.
|
168
|
-
signing_key:
|
170
|
+
rubygems_version: 3.3.27
|
171
|
+
signing_key:
|
169
172
|
specification_version: 4
|
170
173
|
summary: Utility for SUMA (STEP Unified Model-Based Standards Architecture)
|
171
174
|
test_files: []
|
data/.github/workflows/main.yml
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
name: Ruby
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches:
|
6
|
-
- main
|
7
|
-
|
8
|
-
pull_request:
|
9
|
-
|
10
|
-
jobs:
|
11
|
-
build:
|
12
|
-
runs-on: ubuntu-latest
|
13
|
-
name: Ruby ${{ matrix.ruby }}
|
14
|
-
strategy:
|
15
|
-
matrix:
|
16
|
-
ruby:
|
17
|
-
- '3.2.2'
|
18
|
-
|
19
|
-
steps:
|
20
|
-
- uses: actions/checkout@v4
|
21
|
-
- name: Set up Ruby
|
22
|
-
uses: ruby/setup-ruby@v1
|
23
|
-
with:
|
24
|
-
ruby-version: ${{ matrix.ruby }}
|
25
|
-
bundler-cache: true
|
26
|
-
- name: Run the default task
|
27
|
-
run: bundle exec rake
|
@@ -1,112 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../utils"
|
4
|
-
require "shale"
|
5
|
-
|
6
|
-
module Suma
|
7
|
-
module ToReplace
|
8
|
-
module CollectionConfig
|
9
|
-
class CompileOptions < Shale::Mapper
|
10
|
-
attribute :no_install_fonts, Shale::Type::Boolean, default: -> { true }
|
11
|
-
attribute :agree_to_terms, Shale::Type::Boolean, default: -> { true }
|
12
|
-
end
|
13
|
-
|
14
|
-
class BibdataTitle < Shale::Mapper
|
15
|
-
attribute :language, Shale::Type::String
|
16
|
-
attribute :content, Shale::Type::String
|
17
|
-
end
|
18
|
-
|
19
|
-
class BibdataDocid < Shale::Mapper
|
20
|
-
attribute :type, Shale::Type::String
|
21
|
-
attribute :id, Shale::Type::String
|
22
|
-
end
|
23
|
-
|
24
|
-
class BibdataContributor < Shale::Mapper
|
25
|
-
attribute :name, Shale::Type::String
|
26
|
-
attribute :abbreviation, Shale::Type::String
|
27
|
-
end
|
28
|
-
|
29
|
-
class BibdataCopyright < Shale::Mapper
|
30
|
-
attribute :owner, BibdataContributor
|
31
|
-
attribute :from, Shale::Type::String
|
32
|
-
end
|
33
|
-
|
34
|
-
class Bibdata < Shale::Mapper
|
35
|
-
attribute :title, BibdataTitle, collection: true
|
36
|
-
attribute :type, Shale::Type::String
|
37
|
-
attribute :docid, BibdataDocid
|
38
|
-
attribute :edition, Shale::Type::Integer
|
39
|
-
attribute :copyright, BibdataCopyright
|
40
|
-
end
|
41
|
-
|
42
|
-
class ManifestItem < Shale::Mapper
|
43
|
-
attribute :identifier, Shale::Type::String
|
44
|
-
attribute :level, Shale::Type::String
|
45
|
-
attribute :title, Shale::Type::String
|
46
|
-
attribute :attachment, Shale::Type::Boolean
|
47
|
-
attribute :sectionsplit, Shale::Type::Boolean
|
48
|
-
attribute :file, Shale::Type::String
|
49
|
-
attribute :docref, ManifestItem, collection: true
|
50
|
-
|
51
|
-
yaml do
|
52
|
-
map "identifier", to: :identifier
|
53
|
-
map "level", to: :level
|
54
|
-
map "title", to: :title
|
55
|
-
map "attachment", to: :attachment
|
56
|
-
map "sectionsplit", to: :sectionsplit
|
57
|
-
map "file", to: :file
|
58
|
-
map "fileref", to: :fileref
|
59
|
-
map "docref", to: :docref
|
60
|
-
map "fileref", using: { from: :fileref_from_yaml, to: :fileref_to_yaml }
|
61
|
-
end
|
62
|
-
|
63
|
-
def fileref_from_yaml(model, value)
|
64
|
-
# Utils.log "model #{model}, value #{value}"
|
65
|
-
# file_from_yaml(model, value)
|
66
|
-
model.file ||= value
|
67
|
-
end
|
68
|
-
|
69
|
-
def fileref_to_yaml(_model, _doc)
|
70
|
-
nil
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
class Manifest < Shale::Mapper
|
75
|
-
attribute :level, Shale::Type::String
|
76
|
-
attribute :title, Shale::Type::String
|
77
|
-
attribute :sectionsplit, Shale::Type::Boolean
|
78
|
-
attribute :docref, ManifestItem, collection: true
|
79
|
-
|
80
|
-
def attachments
|
81
|
-
docref.detect do |ref|
|
82
|
-
ref.level == "attachments"
|
83
|
-
end&.docref
|
84
|
-
end
|
85
|
-
|
86
|
-
def documents
|
87
|
-
docref.detect do |ref|
|
88
|
-
ref.level == "document"
|
89
|
-
end&.docref
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
class Config < Shale::Mapper
|
94
|
-
attr_accessor :path
|
95
|
-
|
96
|
-
attribute :directives, Shale::Type::String, collection: true
|
97
|
-
attribute :bibdata, Bibdata
|
98
|
-
attribute :manifest, Manifest
|
99
|
-
attribute :format, Shale::Type::String, collection: true, default: -> { [:html] }
|
100
|
-
attribute :output_folder, Shale::Type::String
|
101
|
-
attribute :coverpage, Shale::Type::String, default: -> { "cover.html" }
|
102
|
-
attribute :compile, CompileOptions
|
103
|
-
attribute :prefatory_content, Shale::Type::String
|
104
|
-
attribute :final_content, Shale::Type::String
|
105
|
-
|
106
|
-
def self.from_file(path)
|
107
|
-
from_yaml(File.read(path))
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "shale"
|
4
|
-
|
5
|
-
module Suma
|
6
|
-
module ToReplace
|
7
|
-
module SiteConfig
|
8
|
-
class SiteInfo < Shale::Mapper
|
9
|
-
attribute :organization, Shale::Type::String
|
10
|
-
attribute :name, Shale::Type::String
|
11
|
-
end
|
12
|
-
|
13
|
-
class Sources < Shale::Mapper
|
14
|
-
attribute :files, Shale::Type::String, collection: true
|
15
|
-
end
|
16
|
-
|
17
|
-
class Base < Shale::Mapper
|
18
|
-
attribute :source, Sources
|
19
|
-
attribute :collection, SiteInfo
|
20
|
-
end
|
21
|
-
|
22
|
-
class Config < Shale::Mapper
|
23
|
-
attribute :metanorma, Base
|
24
|
-
|
25
|
-
def self.from_file(path)
|
26
|
-
from_yaml(File.read(path))
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|