Class: Suma::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/suma/processor.rb

Class Method Summary collapse

Class Method Details

.run(metanorma_yaml_path:, schemas_all_path:, compile:, output_directory: "_site") ⇒ Object



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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/suma/processor.rb', line 15

def run(metanorma_yaml_path:, schemas_all_path:, compile:,
output_directory: "_site")
  Utils.log "Current directory: #{Dir.getwd}"

  # This reads the metanorma.yml file
  site_config = Suma::SiteConfig::Config.from_file(metanorma_yaml_path)

  # TODO: only reading the first file, which is a collection.yml, which is a hack...
  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."

  # now get rid of the source documents for schema sources

  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)

  if compile
    Utils.log "Compiling complete collection..."

    metanorma_collection = Metanorma::Collection.parse(new_collection_config_path)

    collection_opts = {
      output_folder: output_directory,
      compile: {
        install_fonts: false,
      },
      coverpage: "cover.html",
    }
    metanorma_collection.render(collection_opts)

    # TODO: Temporarily disable removal of XML files
    Dir.glob(File.join(Dir.getwd, output_directory,
                       "*.xml")).each do |file|
      puts "NOT DELETING ANY FILE #{file.inspect}"
      # File.delete(file)
    end
  else
    Utils.log "No compile option set. Skipping collection compilation."
  end
end