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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/suma/processor.rb', line 16
def run(metanorma_yaml_path:, schemas_all_path:, compile:, output_directory: "_site")
Utils.log "Current directory: #{Dir.getwd}"
site_config = Suma::SiteConfig::Config.from_file(metanorma_yaml_path)
collection_config_path = site_config.metanorma.source.files.first
collection_config = Suma::CollectionConfig.from_file(collection_config_path)
collection_config.path = collection_config_path
collection_config.manifest.expand_schemas_only("schema_docs")
exported_schema_config = collection_config.manifest.export_schema_config(schemas_all_path)
exported_schema_config.path = schemas_all_path
Utils.log "Writing #{schemas_all_path}..."
exported_schema_config.to_file
Utils.log "Done."
col = Suma::SchemaCollection.new(
config_yaml: schemas_all_path,
manifest: collection_config.manifest,
output_path_docs: "schema_docs",
output_path_schemas: "plain_schemas",
)
if compile
Utils.log "Compiling schema collection..."
col.compile
else
Utils.log "No compile option set. Skipping schema compilation."
end
new_collection_config_path = "collection-output.yaml"
collection_config.manifest.remove_schemas_only_sources
collection_config.to_file(new_collection_config_path)
my_fileref_proc = proc do |ref_folder, fileref|
if File.extname(fileref) == ".exp"
fileref.gsub!(
"../../schemas",
"modified_schemas"
)
end
File.join(ref_folder, fileref)
end
my_identifier_proc = proc do |identifier|
case identifier
when %r{^documents/}
identifier.gsub("documents/", "")
else
identifier
end
end
express_schemas_renderer = proc do |collection_model|
end
Metanorma::Collection.tap do |mn|
mn.set_identifier_resolver(&my_identifier_proc)
mn.set_fileref_resolver(&my_fileref_proc)
mn.set_pre_parse_model(&express_schemas_renderer)
end
if compile
Utils.log "Compiling complete collection..."
metanorma_collection = Metanorma::Collection.parse(new_collection_config_path)
collection_opts = {
format: [:html],
output_folder: output_directory,
compile: {
install_fonts: false,
},
coverpage: "cover.html",
}
metanorma_collection.render(collection_opts)
Dir.glob(File.join(Dir.getwd, output_directory, "*.xml")).each do |file|
File.delete(file)
end
else
Utils.log "No compile option set. Skipping collection compilation."
end
end
|