suma 0.2.5 → 0.2.6
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 +3 -0
- data/.github/workflows/release.yml +5 -1
- data/.rubocop_todo.yml +78 -26
- data/CLAUDE.md +76 -0
- data/Gemfile +3 -1
- data/README.adoc +131 -0
- data/lib/suma/cli/build.rb +2 -3
- data/lib/suma/cli/check_svg_quality.rb +178 -0
- data/lib/suma/cli/compare.rb +7 -158
- data/lib/suma/cli/export.rb +1 -7
- data/lib/suma/cli/extract_terms.rb +7 -648
- data/lib/suma/cli/generate_schemas.rb +9 -123
- data/lib/suma/cli/validate_links.rb +15 -290
- data/lib/suma/cli.rb +39 -0
- data/lib/suma/collection_manifest.rb +3 -4
- data/lib/suma/express_schema.rb +43 -30
- data/lib/suma/jsdai/figure_xml.rb +12 -9
- data/lib/suma/jsdai.rb +0 -6
- data/lib/suma/link_validator.rb +203 -0
- data/lib/suma/processor.rb +75 -101
- data/lib/suma/schema_attachment.rb +2 -29
- data/lib/suma/schema_collection.rb +1 -32
- data/lib/suma/schema_comparer.rb +116 -0
- data/lib/suma/schema_document.rb +0 -14
- data/lib/suma/schema_exporter.rb +16 -28
- data/lib/suma/schema_index.rb +53 -0
- data/lib/suma/schema_manifest_generator.rb +105 -0
- data/lib/suma/svg_quality/batch_report.rb +80 -0
- data/lib/suma/svg_quality/formatters/json_formatter.rb +30 -0
- data/lib/suma/svg_quality/formatters/terminal_formatter.rb +168 -0
- data/lib/suma/svg_quality/formatters/yaml_formatter.rb +32 -0
- data/lib/suma/svg_quality/report.rb +52 -0
- data/lib/suma/svg_quality.rb +28 -0
- data/lib/suma/term_extractor.rb +393 -0
- data/lib/suma/utils.rb +10 -2
- data/lib/suma/version.rb +1 -1
- data/lib/suma.rb +3 -2
- data/suma.gemspec +3 -2
- metadata +33 -7
- data/lib/suma/export_standalone_schema.rb +0 -14
data/lib/suma/express_schema.rb
CHANGED
|
@@ -6,6 +6,42 @@ require "expressir"
|
|
|
6
6
|
|
|
7
7
|
module Suma
|
|
8
8
|
class ExpressSchema
|
|
9
|
+
module Type
|
|
10
|
+
RESOURCE = :resource
|
|
11
|
+
MODULE_ARM = :module_arm
|
|
12
|
+
MODULE_MIM = :module_mim
|
|
13
|
+
BUSINESS_OBJECT_MODEL = :business_object_model
|
|
14
|
+
CORE_MODEL = :core_model
|
|
15
|
+
STANDALONE = :standalone
|
|
16
|
+
|
|
17
|
+
ID_SUFFIXES = {
|
|
18
|
+
"_arm" => :MODULE_ARM,
|
|
19
|
+
"_mim" => :MODULE_MIM,
|
|
20
|
+
"_bom" => :BUSINESS_OBJECT_MODEL,
|
|
21
|
+
}.freeze
|
|
22
|
+
|
|
23
|
+
PATH_SEGMENTS = {
|
|
24
|
+
"/resources/" => :RESOURCE,
|
|
25
|
+
"/modules/" => :MODULE_ARM,
|
|
26
|
+
"/core_model/" => :CORE_MODEL,
|
|
27
|
+
}.freeze
|
|
28
|
+
|
|
29
|
+
def self.classify(id:, path:)
|
|
30
|
+
name = id&.downcase || ""
|
|
31
|
+
|
|
32
|
+
ID_SUFFIXES.each do |suffix, type|
|
|
33
|
+
return const_get(type) if name.end_with?(suffix)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
path_str = path.to_s
|
|
37
|
+
PATH_SEGMENTS.each do |segment, type|
|
|
38
|
+
return const_get(type) if path_str.include?(segment)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
STANDALONE
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
9
45
|
attr_accessor :path, :id, :parsed, :output_path, :is_standalone_file
|
|
10
46
|
|
|
11
47
|
def initialize(id:, path:, output_path:, is_standalone_file: false)
|
|
@@ -16,14 +52,7 @@ module Suma
|
|
|
16
52
|
end
|
|
17
53
|
|
|
18
54
|
def type
|
|
19
|
-
|
|
20
|
-
if path_str.include?("/resources/")
|
|
21
|
-
"resources"
|
|
22
|
-
elsif path_str.include?("/modules/")
|
|
23
|
-
"modules"
|
|
24
|
-
else
|
|
25
|
-
"unknown_type"
|
|
26
|
-
end
|
|
55
|
+
@type ||= classify
|
|
27
56
|
end
|
|
28
57
|
|
|
29
58
|
def parsed
|
|
@@ -50,11 +79,8 @@ module Suma
|
|
|
50
79
|
|
|
51
80
|
def build_output_filename
|
|
52
81
|
if @is_standalone_file
|
|
53
|
-
# For standalone files, output directly to output_path
|
|
54
82
|
File.join(@output_path, "#{@id}.exp")
|
|
55
83
|
else
|
|
56
|
-
# For manifest schemas, preserve directory structure
|
|
57
|
-
# Note: @output_path already contains the category (resources/modules)
|
|
58
84
|
parent_dir = File.basename(File.dirname(@path))
|
|
59
85
|
File.join(@output_path, parent_dir, File.basename(@path))
|
|
60
86
|
end
|
|
@@ -65,29 +91,16 @@ module Suma
|
|
|
65
91
|
schema_type = with_annotations ? "annotated" : "plain"
|
|
66
92
|
Utils.log "Save #{schema_type} schema: #{relative_path}"
|
|
67
93
|
|
|
68
|
-
# return if File.exist?(filename_plain)
|
|
69
94
|
FileUtils.mkdir_p(File.dirname(filename_plain))
|
|
70
95
|
|
|
71
96
|
content = with_annotations ? parsed.to_s(no_remarks: false) : to_plain
|
|
72
97
|
File.write(filename_plain, content)
|
|
73
98
|
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# col = Suma::SchemaCollection.new(
|
|
78
|
-
# config_yaml: 'suma-schemas.yaml',
|
|
79
|
-
# output_path_docs: 'schema_docs',
|
|
80
|
-
# output_path_schemas: 'plain_schemas'
|
|
81
|
-
# )
|
|
82
|
-
|
|
83
|
-
# docs = col.compile
|
|
84
99
|
|
|
85
|
-
|
|
86
|
-
# {
|
|
87
|
-
# plain_schema_path: schema.filename_plain,
|
|
88
|
-
# schema_doc_path: col.doc_from_schema_name(schema.id).output_xml_path
|
|
89
|
-
# }
|
|
90
|
-
# end
|
|
100
|
+
private
|
|
91
101
|
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
def classify
|
|
103
|
+
Type.classify(id: @id, path: @path)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -11,10 +11,11 @@ module Suma
|
|
|
11
11
|
attribute :href, :string
|
|
12
12
|
|
|
13
13
|
xml do
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
map_attribute "
|
|
17
|
-
map_attribute "
|
|
14
|
+
element "img.area"
|
|
15
|
+
ordered
|
|
16
|
+
map_attribute "shape", to: :shape, render_empty: true
|
|
17
|
+
map_attribute "coords", to: :coords, render_empty: true
|
|
18
|
+
map_attribute "href", to: :href, render_empty: true
|
|
18
19
|
end
|
|
19
20
|
end
|
|
20
21
|
|
|
@@ -24,8 +25,9 @@ module Suma
|
|
|
24
25
|
attribute :areas, FigureXmlImageArea, collection: true
|
|
25
26
|
|
|
26
27
|
xml do
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
element "img"
|
|
29
|
+
ordered
|
|
30
|
+
map_attribute "src", to: :src, render_empty: true
|
|
29
31
|
map_element "img.area", to: :areas
|
|
30
32
|
end
|
|
31
33
|
end
|
|
@@ -37,9 +39,10 @@ module Suma
|
|
|
37
39
|
attribute :img, FigureXmlImage
|
|
38
40
|
|
|
39
41
|
xml do
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
map_attribute "
|
|
42
|
+
element "imgfile.content"
|
|
43
|
+
ordered
|
|
44
|
+
map_attribute "module", to: :module, render_empty: true
|
|
45
|
+
map_attribute "file", to: :file, render_empty: true
|
|
43
46
|
map_element "img", to: :img
|
|
44
47
|
end
|
|
45
48
|
end
|
data/lib/suma/jsdai.rb
CHANGED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "schema_index"
|
|
4
|
+
require "expressir"
|
|
5
|
+
|
|
6
|
+
module Suma
|
|
7
|
+
LinkValidationResult = Struct.new(:file, :line, :link, :reason, keyword_init: true)
|
|
8
|
+
|
|
9
|
+
class LinkValidator
|
|
10
|
+
def initialize(index)
|
|
11
|
+
@index = index
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def validate(links_by_file)
|
|
15
|
+
unresolved = []
|
|
16
|
+
|
|
17
|
+
links_by_file.each do |file, links|
|
|
18
|
+
line_index = build_link_line_index(file)
|
|
19
|
+
validate_file(file, links, line_index, unresolved)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
unresolved
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def build_link_line_index(file)
|
|
28
|
+
content = File.read(file)
|
|
29
|
+
index = {}
|
|
30
|
+
content.lines.each_with_index do |line, idx|
|
|
31
|
+
line.scan(/<<express:([^,>]+)(?:,[^>]+)?>>/).flatten.each do |link|
|
|
32
|
+
index[link] ||= idx
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
index
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def validate_file(file, links, line_index, unresolved)
|
|
39
|
+
links.each do |link|
|
|
40
|
+
line_idx = line_index[link]
|
|
41
|
+
next unless line_idx
|
|
42
|
+
|
|
43
|
+
parts = link.split(".")
|
|
44
|
+
|
|
45
|
+
if parts.size == 1
|
|
46
|
+
validate_schema_only(parts[0], file, line_idx, link, unresolved)
|
|
47
|
+
else
|
|
48
|
+
validate_element(parts, file, line_idx, link, unresolved)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def validate_schema_only(schema_name, file, line_idx, link, unresolved)
|
|
54
|
+
schema = @index.find_schema(schema_name)
|
|
55
|
+
|
|
56
|
+
return if schema
|
|
57
|
+
|
|
58
|
+
unresolved << LinkValidationResult.new(
|
|
59
|
+
file: file,
|
|
60
|
+
line: line_idx + 1,
|
|
61
|
+
link: link,
|
|
62
|
+
reason: "Schema '#{schema_name}' not found",
|
|
63
|
+
)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def validate_element(parts, file, line_idx, link, unresolved)
|
|
67
|
+
schema_name = parts[0]
|
|
68
|
+
element_name = parts[1]
|
|
69
|
+
|
|
70
|
+
schema = @index.find_schema(schema_name)
|
|
71
|
+
|
|
72
|
+
unless schema
|
|
73
|
+
unresolved << LinkValidationResult.new(
|
|
74
|
+
file: file,
|
|
75
|
+
line: line_idx + 1,
|
|
76
|
+
link: link,
|
|
77
|
+
reason: "Schema '#{schema_name}' not found",
|
|
78
|
+
)
|
|
79
|
+
return
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
element = @index.find_element(schema_name, element_name)
|
|
83
|
+
|
|
84
|
+
unless element
|
|
85
|
+
unresolved << LinkValidationResult.new(
|
|
86
|
+
file: file,
|
|
87
|
+
line: line_idx + 1,
|
|
88
|
+
link: link,
|
|
89
|
+
reason: "Element '#{element_name}' not found in schema '#{schema_name}'",
|
|
90
|
+
)
|
|
91
|
+
return
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
return unless parts.size > 2
|
|
95
|
+
|
|
96
|
+
error = validate_deep_path(schema, element, parts[2..], file, line_idx, link)
|
|
97
|
+
unresolved << error if error
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def validate_deep_path(schema, element, path_parts, file, line_idx, full_link)
|
|
101
|
+
current = element
|
|
102
|
+
current_path = "#{schema.id}.#{element.id}"
|
|
103
|
+
|
|
104
|
+
path_parts.each do |part|
|
|
105
|
+
case current
|
|
106
|
+
when Expressir::Model::Declarations::Entity
|
|
107
|
+
attribute = current.attributes&.find { |a| a.id.downcase == part.downcase }
|
|
108
|
+
|
|
109
|
+
unless attribute
|
|
110
|
+
return LinkValidationResult.new(
|
|
111
|
+
file: file,
|
|
112
|
+
line: line_idx + 1,
|
|
113
|
+
link: full_link,
|
|
114
|
+
reason: "Attribute '#{part}' not found in entity '#{current_path}'",
|
|
115
|
+
)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
current = attribute
|
|
119
|
+
current_path += ".#{part}"
|
|
120
|
+
|
|
121
|
+
when Expressir::Model::Declarations::Type
|
|
122
|
+
underlying = current.underlying_type
|
|
123
|
+
|
|
124
|
+
if underlying.is_a?(Expressir::Model::DataTypes::Enumeration)
|
|
125
|
+
enum_value = underlying.items.find { |e| e.id.downcase == part.downcase }
|
|
126
|
+
|
|
127
|
+
unless enum_value
|
|
128
|
+
return LinkValidationResult.new(
|
|
129
|
+
file: file,
|
|
130
|
+
line: line_idx + 1,
|
|
131
|
+
link: full_link,
|
|
132
|
+
reason: "Enumeration value '#{part}' not found in type '#{current_path}'",
|
|
133
|
+
)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
current = enum_value
|
|
137
|
+
current_path += ".#{part}"
|
|
138
|
+
|
|
139
|
+
elsif underlying
|
|
140
|
+
base_type = find_base_type(schema, underlying)
|
|
141
|
+
|
|
142
|
+
unless base_type
|
|
143
|
+
return LinkValidationResult.new(
|
|
144
|
+
file: file,
|
|
145
|
+
line: line_idx + 1,
|
|
146
|
+
link: full_link,
|
|
147
|
+
reason: "Base type not found for '#{current_path}'",
|
|
148
|
+
)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
current = base_type
|
|
152
|
+
|
|
153
|
+
else
|
|
154
|
+
return LinkValidationResult.new(
|
|
155
|
+
file: file,
|
|
156
|
+
line: line_idx + 1,
|
|
157
|
+
link: full_link,
|
|
158
|
+
reason: "Cannot navigate deeper from type '#{current_path}'",
|
|
159
|
+
)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
else
|
|
163
|
+
return LinkValidationResult.new(
|
|
164
|
+
file: file,
|
|
165
|
+
line: line_idx + 1,
|
|
166
|
+
link: full_link,
|
|
167
|
+
reason: "Cannot navigate deeper from '#{current_path}'",
|
|
168
|
+
)
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
nil
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def find_base_type(schema, type_ref)
|
|
176
|
+
return nil if %w[INTEGER REAL STRING BOOLEAN NUMBER BINARY
|
|
177
|
+
LOGICAL].include?(type_ref.to_s.upcase)
|
|
178
|
+
|
|
179
|
+
if type_ref.is_a?(String)
|
|
180
|
+
find_schema_element(schema, type_ref)
|
|
181
|
+
elsif type_ref.is_a?(Expressir::Model::ModelElement)
|
|
182
|
+
type_ref
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def find_schema_element(schema, element_name)
|
|
187
|
+
[
|
|
188
|
+
schema.entities,
|
|
189
|
+
schema.types,
|
|
190
|
+
schema.constants,
|
|
191
|
+
schema.functions,
|
|
192
|
+
schema.rules,
|
|
193
|
+
schema.procedures,
|
|
194
|
+
schema.subtype_constraints,
|
|
195
|
+
].each do |collection|
|
|
196
|
+
element = collection&.find { |e| e.id.downcase == element_name.downcase }
|
|
197
|
+
return element if element
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
nil
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
data/lib/suma/processor.rb
CHANGED
|
@@ -8,107 +8,81 @@ require "metanorma"
|
|
|
8
8
|
|
|
9
9
|
module Suma
|
|
10
10
|
class Processor
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
collection_config.manifest
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
collection_config
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
metanorma_collection.render(collection_opts)
|
|
89
|
-
|
|
90
|
-
# TODO: Temporarily disable removal of XML files
|
|
91
|
-
Dir.glob(File.join(Dir.getwd, output_directory,
|
|
92
|
-
"*.xml")).each do |file|
|
|
93
|
-
puts "NOT DELETING ANY FILE #{file.inspect}"
|
|
94
|
-
# File.delete(file)
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def build_collection(collection_config, output_directory)
|
|
99
|
-
new_collection_config_path = "collection-output.yaml"
|
|
100
|
-
collection_config.manifest.remove_schemas_only_sources
|
|
101
|
-
collection_config.to_file(new_collection_config_path)
|
|
102
|
-
|
|
103
|
-
collection = Metanorma::Collection.parse(new_collection_config_path)
|
|
104
|
-
|
|
105
|
-
collection_opts = {
|
|
106
|
-
output_folder: output_directory,
|
|
107
|
-
compile: { install_fonts: false },
|
|
108
|
-
coverpage: collection_config.coverpage || "cover.html",
|
|
109
|
-
}
|
|
110
|
-
[collection, collection_opts]
|
|
111
|
-
end
|
|
11
|
+
attr_reader :metanorma_yaml_path, :output_directory, :schemas_all_path,
|
|
12
|
+
:compile_flag
|
|
13
|
+
|
|
14
|
+
def initialize(metanorma_yaml_path:, schemas_all_path:, compile: true,
|
|
15
|
+
output_directory: "_site")
|
|
16
|
+
@metanorma_yaml_path = metanorma_yaml_path
|
|
17
|
+
@schemas_all_path = schemas_all_path
|
|
18
|
+
@compile_flag = compile
|
|
19
|
+
@output_directory = output_directory
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def run
|
|
23
|
+
Utils.log "Current directory: #{Dir.getwd}, writing #{schemas_all_path}..."
|
|
24
|
+
|
|
25
|
+
collection_config = export_schema_config
|
|
26
|
+
|
|
27
|
+
return nil unless @compile_flag
|
|
28
|
+
|
|
29
|
+
Utils.log "Compiling schema collection..."
|
|
30
|
+
compile_schema(schemas_all_path, collection_config)
|
|
31
|
+
|
|
32
|
+
Utils.log "Compiling complete collection..."
|
|
33
|
+
compile_collection(collection_config, output_directory)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def export_schema_config
|
|
39
|
+
site_config = Suma::SiteConfig::Config.from_file(metanorma_yaml_path)
|
|
40
|
+
|
|
41
|
+
collection_config_path = site_config.metanorma.source.files.first
|
|
42
|
+
collection_config = Suma::CollectionConfig.from_file(collection_config_path)
|
|
43
|
+
collection_config.path = collection_config_path
|
|
44
|
+
collection_config.manifest.expand_schemas_only("schema_docs")
|
|
45
|
+
|
|
46
|
+
exported_schema_config = collection_config.manifest.export_schema_config(schemas_all_path)
|
|
47
|
+
exported_schema_config.path = schemas_all_path
|
|
48
|
+
|
|
49
|
+
exported_schema_config.to_file
|
|
50
|
+
|
|
51
|
+
collection_config
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def compile_schema(schemas_all_path, collection_config)
|
|
55
|
+
col = Suma::SchemaCollection.new(
|
|
56
|
+
config_yaml: schemas_all_path,
|
|
57
|
+
manifest: collection_config.manifest,
|
|
58
|
+
output_path_docs: "schema_docs",
|
|
59
|
+
output_path_schemas: "plain_schemas",
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
col.compile
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def compile_collection(collection_config, output_directory)
|
|
66
|
+
metanorma_collection, collection_opts = build_collection(
|
|
67
|
+
collection_config, output_directory
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
metanorma_collection.render(collection_opts)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def build_collection(collection_config, output_directory)
|
|
74
|
+
new_collection_config_path = "collection-output.yaml"
|
|
75
|
+
collection_config.manifest.remove_schemas_only_sources
|
|
76
|
+
collection_config.to_file(new_collection_config_path)
|
|
77
|
+
|
|
78
|
+
collection = Metanorma::Collection.parse(new_collection_config_path)
|
|
79
|
+
|
|
80
|
+
collection_opts = {
|
|
81
|
+
output_folder: output_directory,
|
|
82
|
+
compile: { install_fonts: false },
|
|
83
|
+
coverpage: collection_config.coverpage || "cover.html",
|
|
84
|
+
}
|
|
85
|
+
[collection, collection_opts]
|
|
112
86
|
end
|
|
113
87
|
end
|
|
114
88
|
end
|
|
@@ -50,15 +50,12 @@ module Suma
|
|
|
50
50
|
relative_path = Pathname.new(filename_adoc).relative_path_from(Dir.pwd)
|
|
51
51
|
Utils.log "Save EXPRESS adoc: #{relative_path}"
|
|
52
52
|
|
|
53
|
-
# return if File.exist?(filename_adoc)
|
|
54
53
|
FileUtils.mkdir_p(File.dirname(filename_adoc))
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
config_relative = Pathname.new(filename_config)
|
|
57
56
|
.relative_path_from(Pathname.new(File.dirname(filename_adoc)))
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
File.write(filename_adoc, to_adoc(relative_path))
|
|
58
|
+
File.write(filename_adoc, to_adoc(config_relative))
|
|
62
59
|
end
|
|
63
60
|
|
|
64
61
|
def filename_config
|
|
@@ -66,7 +63,6 @@ module Suma
|
|
|
66
63
|
end
|
|
67
64
|
|
|
68
65
|
def to_config(path: nil)
|
|
69
|
-
# return @config unless @config
|
|
70
66
|
@config = Expressir::SchemaManifest.new
|
|
71
67
|
@config.schemas << Expressir::SchemaManifestEntry.new(
|
|
72
68
|
id: @schema.id,
|
|
@@ -81,8 +77,6 @@ module Suma
|
|
|
81
77
|
relative_path = Pathname.new(filename_config).relative_path_from(Dir.pwd)
|
|
82
78
|
Utils.log "Save schema config: #{relative_path}"
|
|
83
79
|
|
|
84
|
-
# Still overwrite even if the file exists
|
|
85
|
-
# return if File.exist?(filename_config)
|
|
86
80
|
FileUtils.mkdir_p(File.dirname(filename_config))
|
|
87
81
|
|
|
88
82
|
to_config.save_to_path(filename_config)
|
|
@@ -90,10 +84,6 @@ module Suma
|
|
|
90
84
|
|
|
91
85
|
# Compile Metanorma adoc per EXPRESS schema
|
|
92
86
|
def compile
|
|
93
|
-
# TODO: Clean artifacts after compiling
|
|
94
|
-
# I am commenting out because I'm playing with the schemas-only status
|
|
95
|
-
# return self if File.exist?(output_xml_path)
|
|
96
|
-
|
|
97
87
|
save_config
|
|
98
88
|
save_adoc
|
|
99
89
|
|
|
@@ -103,28 +93,11 @@ module Suma
|
|
|
103
93
|
install_fonts: false)
|
|
104
94
|
Utils.log "Compiling schema (id: #{id}, type: #{self.class}) => #{relative_path}... done!"
|
|
105
95
|
|
|
106
|
-
# clean_artifacts
|
|
107
|
-
|
|
108
|
-
# filename_adoc('xml')
|
|
109
96
|
self
|
|
110
97
|
end
|
|
111
98
|
|
|
112
99
|
def output_xml_path
|
|
113
100
|
filename_adoc("xml")
|
|
114
101
|
end
|
|
115
|
-
|
|
116
|
-
def clean_artifacts
|
|
117
|
-
[
|
|
118
|
-
filename_config,
|
|
119
|
-
filename_adoc,
|
|
120
|
-
filename_adoc("presentation.xml"),
|
|
121
|
-
filename_adoc("adoc.lutaml.log.txt"),
|
|
122
|
-
filename_adoc("err.html"),
|
|
123
|
-
].each do |filename|
|
|
124
|
-
FileUtils.rm_rf(filename)
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def output_folder; end
|
|
129
102
|
end
|
|
130
103
|
end
|
|
@@ -52,24 +52,20 @@ module Suma
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def finalize
|
|
55
|
-
# Process each schema in @config.schemas
|
|
56
55
|
process_schemas(@config.schemas, SchemaAttachment)
|
|
57
56
|
|
|
58
|
-
manifest_entry = @manifest.
|
|
57
|
+
manifest_entry = @manifest.lookup_schemas_only
|
|
59
58
|
|
|
60
59
|
manifest_entry.each do |entry|
|
|
61
60
|
next unless entry.schema_config
|
|
62
61
|
|
|
63
|
-
# Process each schema in entry.schema_config.schemas
|
|
64
62
|
process_schemas(entry.schema_config.schemas, SchemaDocument)
|
|
65
63
|
end
|
|
66
64
|
end
|
|
67
65
|
|
|
68
|
-
# rubocop:disable Metrics/MethodLength
|
|
69
66
|
def compile
|
|
70
67
|
finalize
|
|
71
68
|
|
|
72
|
-
# Use SchemaExporter for schema export
|
|
73
69
|
exporter = SchemaExporter.new(
|
|
74
70
|
schemas: @config.schemas,
|
|
75
71
|
output_path: @output_path_schemas,
|
|
@@ -80,33 +76,6 @@ module Suma
|
|
|
80
76
|
docs.each_pair do |_schema_id, entry|
|
|
81
77
|
entry.compile
|
|
82
78
|
end
|
|
83
|
-
|
|
84
|
-
# TODO: make this parallel
|
|
85
|
-
# Utils.log"Starting Ractor processing"
|
|
86
|
-
# pool = Ractor.new do
|
|
87
|
-
# loop do
|
|
88
|
-
# Ractor.yield(Ractor.receive)
|
|
89
|
-
# end
|
|
90
|
-
# end
|
|
91
|
-
# workers = (1..4).map do |i|
|
|
92
|
-
# Ractor.new(pool, name: "r#{i}") do |p|
|
|
93
|
-
# loop do
|
|
94
|
-
# input = p.take
|
|
95
|
-
# Utils.log"compiling in ractor for #{input.filename_adoc}"
|
|
96
|
-
# output_value = input.compile
|
|
97
|
-
# Ractor.yield(output_value)
|
|
98
|
-
# end
|
|
99
|
-
# end
|
|
100
|
-
# end
|
|
101
|
-
# docs.each do |doc|
|
|
102
|
-
# pool.send(doc)
|
|
103
|
-
# end
|
|
104
|
-
# results = []
|
|
105
|
-
# docs.size.times do
|
|
106
|
-
# results << Ractor.select(*workers)
|
|
107
|
-
# end
|
|
108
|
-
# pp results
|
|
109
79
|
end
|
|
110
|
-
# rubocop:enable Metrics/MethodLength
|
|
111
80
|
end
|
|
112
81
|
end
|