suma 0.1.23 → 0.1.25

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.
@@ -6,19 +6,20 @@ require "expressir"
6
6
 
7
7
  module Suma
8
8
  class ExpressSchema
9
- attr_accessor :path, :id, :parsed, :output_path
9
+ attr_accessor :path, :id, :parsed, :output_path, :is_standalone_file
10
10
 
11
- def initialize(id:, path:, output_path:)
11
+ def initialize(id:, path:, output_path:, is_standalone_file: false)
12
12
  @path = Pathname.new(path).expand_path
13
13
  @id = id
14
14
  @output_path = output_path
15
+ @is_standalone_file = is_standalone_file
15
16
  end
16
17
 
17
18
  def type
18
- case @path.to_s
19
- when %r{.*/resources/.*}
19
+ path_str = @path.to_s
20
+ if path_str.include?("/resources/")
20
21
  "resources"
21
- when %r{.*/modules/.*}
22
+ elsif path_str.include?("/modules/")
22
23
  "modules"
23
24
  else
24
25
  "unknown_type"
@@ -39,7 +40,23 @@ module Suma
39
40
  end
40
41
 
41
42
  def filename_plain
42
- File.join(@output_path, type, id, File.basename(@path))
43
+ ensure_id_loaded
44
+ build_output_filename
45
+ end
46
+
47
+ def ensure_id_loaded
48
+ parsed unless @id
49
+ end
50
+
51
+ def build_output_filename
52
+ if @is_standalone_file
53
+ # For standalone files, output directly to output_path
54
+ File.join(@output_path, "#{@id}.exp")
55
+ else
56
+ # For manifest schemas, preserve directory structure
57
+ # Note: @output_path already contains the category (resources/modules)
58
+ File.join(@output_path, @id, File.basename(@path))
59
+ end
43
60
  end
44
61
 
45
62
  def save_exp(with_annotations: false)
@@ -15,12 +15,15 @@ module Suma
15
15
  def run(metanorma_yaml_path:, schemas_all_path:, compile:,
16
16
  output_directory: "_site")
17
17
  Utils.log "Current directory: #{Dir.getwd}, writing #{schemas_all_path}..."
18
+
19
+ # Generate EXPRESS Schema Manifest by traversing Metanorma Site Manifest
20
+ # This uses Expressir::SchemaManifest for all manifest operations
18
21
  collection_config = export_schema_config(metanorma_yaml_path,
19
22
  schemas_all_path)
20
23
 
21
24
  unless compile
22
25
  Utils.log "No compile option set. Skipping schema compilation."
23
- nil
26
+ return nil
24
27
  end
25
28
 
26
29
  Utils.log "Compiling schema collection..."
@@ -33,6 +36,18 @@ output_directory: "_site")
33
36
 
34
37
  private
35
38
 
39
+ # Generates EXPRESS Schema Manifest from Metanorma Site Manifest structure.
40
+ #
41
+ # This method:
42
+ # 1. Reads the Metanorma site manifest to discover collection files
43
+ # 2. Traverses collection manifests to find individual schemas.yaml files
44
+ # 3. Uses Expressir::SchemaManifest to aggregate and manage schema entries
45
+ # 4. Saves the unified schema manifest using Expressir's to_file method
46
+ #
47
+ # @param metanorma_yaml_path [String] Path to Metanorma site manifest
48
+ # @param schemas_all_path [String] Output path for unified schema manifest
49
+ # @return [CollectionConfig] The loaded collection configuration
50
+ # rubocop:disable Metrics/MethodLength
36
51
  def export_schema_config(metanorma_yaml_path, schemas_all_path)
37
52
  # This reads the metanorma.yml file
38
53
  site_config = Suma::SiteConfig::Config.from_file(metanorma_yaml_path)
@@ -43,13 +58,17 @@ output_directory: "_site")
43
58
  collection_config.path = collection_config_path
44
59
  collection_config.manifest.expand_schemas_only("schema_docs")
45
60
 
61
+ # Recursively traverse collection manifests to build unified schema manifest
62
+ # Uses Expressir::SchemaManifest methods (concat, to_file) for operations
46
63
  exported_schema_config = collection_config.manifest.export_schema_config(schemas_all_path)
47
64
  exported_schema_config.path = schemas_all_path
48
65
 
66
+ # Save using Expressir's SchemaManifest#to_file method
49
67
  exported_schema_config.to_file
50
68
 
51
69
  collection_config
52
70
  end
71
+ # rubocop:enable Metrics/MethodLength
53
72
 
54
73
  def compile_schema(schemas_all_path, collection_config)
55
74
  # now get rid of the source documents for schema sources
@@ -9,8 +9,8 @@ require_relative "utils"
9
9
 
10
10
  module Suma
11
11
  class SchemaCollection
12
- attr_accessor :config, :schemas, :docs, :output_path_docs, :output_path_schemas,
13
- :manifest
12
+ attr_accessor :config, :schemas, :docs, :output_path_docs,
13
+ :output_path_schemas, :manifest
14
14
 
15
15
  def initialize(config: nil, config_yaml: nil, output_path_docs: nil,
16
16
  output_path_schemas: nil, manifest: nil)
@@ -18,7 +18,9 @@ module Suma
18
18
  @docs = {}
19
19
  @schema_name_to_docs = {}
20
20
  @output_path_docs = Pathname.new(output_path_docs || Dir.pwd).expand_path
21
- @output_path_schemas = Pathname.new(output_path_schemas || Dir.pwd).expand_path
21
+ @output_path_schemas = Pathname.new(
22
+ output_path_schemas || Dir.pwd,
23
+ ).expand_path
22
24
  @config = config
23
25
  @config ||= config_yaml && Expressir::SchemaManifest.from_file(config_yaml)
24
26
  @manifest = manifest
@@ -69,7 +71,7 @@ module Suma
69
71
 
70
72
  # Use SchemaExporter for schema export
71
73
  exporter = SchemaExporter.new(
72
- config: @config,
74
+ schemas: @config.schemas,
73
75
  output_path: @output_path_schemas,
74
76
  options: { annotations: false },
75
77
  )
@@ -2,16 +2,17 @@
2
2
 
3
3
  require_relative "express_schema"
4
4
  require_relative "utils"
5
+ require_relative "export_standalone_schema"
5
6
  require "fileutils"
6
7
 
7
8
  module Suma
8
9
  # SchemaExporter exports EXPRESS schemas from a manifest
9
10
  # with configurable options for annotations and ZIP packaging
10
11
  class SchemaExporter
11
- attr_reader :config, :output_path, :options
12
+ attr_reader :schemas, :output_path, :options
12
13
 
13
- def initialize(config:, output_path:, options: {})
14
- @config = config
14
+ def initialize(schemas:, output_path:, options: {})
15
+ @schemas = schemas
15
16
  @output_path = Pathname.new(output_path).expand_path
16
17
  @options = default_options.merge(options)
17
18
  end
@@ -19,7 +20,6 @@ module Suma
19
20
  def export
20
21
  Utils.log "Exporting schemas to: #{output_path}"
21
22
 
22
- schemas = config.schemas
23
23
  export_to_directory(schemas)
24
24
  create_zip_archive if options[:create_zip]
25
25
 
@@ -43,22 +43,37 @@ module Suma
43
43
  end
44
44
 
45
45
  def export_single_schema(schema)
46
- category = categorize_schema(schema)
47
- schema_output_path = output_path.join(category).to_s
46
+ # Check if this is a standalone EXPRESS file
47
+ # (not from a manifest structure)
48
+ is_standalone_file = schema.is_a?(ExportStandaloneSchema)
49
+ schema_output_path = determine_output_path(schema, is_standalone_file)
48
50
 
49
51
  express_schema = ExpressSchema.new(
50
52
  id: schema.id,
51
53
  path: schema.path.to_s,
52
54
  output_path: schema_output_path,
55
+ is_standalone_file: is_standalone_file,
53
56
  )
54
57
 
55
58
  express_schema.save_exp(with_annotations: options[:annotations])
56
59
  end
57
60
 
61
+ def determine_output_path(schema, is_standalone_file)
62
+ if is_standalone_file
63
+ # For standalone files, output directly to the root
64
+ output_path.to_s
65
+ else
66
+ # For manifest schemas, preserve directory structure
67
+ category = categorize_schema(schema)
68
+ output_path.join(category).to_s
69
+ end
70
+ end
71
+
58
72
  # rubocop:disable Metrics/MethodLength
59
73
  def categorize_schema(schema)
60
74
  path = schema.path.to_s
61
75
 
76
+ # Check if this is from a manifest structure or a standalone EXPRESS file
62
77
  case path
63
78
  when %r{/resources/}
64
79
  "resources"
@@ -69,7 +84,8 @@ module Suma
69
84
  when %r{/core_model/}
70
85
  "core_model"
71
86
  else
72
- "other"
87
+ # standalone EXPRESS file not from a manifest structure
88
+ "standalone"
73
89
  end
74
90
  end
75
91
  # rubocop:enable Metrics/MethodLength
data/lib/suma/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Suma
4
- VERSION = "0.1.23"
4
+ VERSION = "0.1.25"
5
5
  end
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.23
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-10-06 00:00:00.000000000 Z
11
+ date: 2025-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expressir
@@ -162,6 +162,7 @@ files:
162
162
  - lib/suma.rb
163
163
  - lib/suma/cli.rb
164
164
  - lib/suma/cli/build.rb
165
+ - lib/suma/cli/compare.rb
165
166
  - lib/suma/cli/convert_jsdai.rb
166
167
  - lib/suma/cli/export.rb
167
168
  - lib/suma/cli/extract_terms.rb
@@ -172,6 +173,10 @@ files:
172
173
  - lib/suma/cli/validate_links.rb
173
174
  - lib/suma/collection_config.rb
174
175
  - lib/suma/collection_manifest.rb
176
+ - lib/suma/eengine/errors.rb
177
+ - lib/suma/eengine/wrapper.rb
178
+ - lib/suma/eengine_converter.rb
179
+ - lib/suma/export_standalone_schema.rb
175
180
  - lib/suma/express_schema.rb
176
181
  - lib/suma/jsdai.rb
177
182
  - lib/suma/jsdai/figure.rb