suma 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0cee8119660d33e2592a44875f218ff7cad624c0c5ff89430c5f97eda5f593e
4
- data.tar.gz: 9fdc83bc1383b931d0907d9f31e4d94986a7922b55ef4f82ae437b4a52833f08
3
+ metadata.gz: 7d5ebe81c947831dfcd9c94b3eeea2a34f33d29c548a59a55347b35adecaecc7
4
+ data.tar.gz: '085a461362248532759fe4d47ce5e0e7ff510147a97537c17e039878ae2e503a'
5
5
  SHA512:
6
- metadata.gz: d2e87931a5396a1b42245c0d3156345e539b6d1f11bb82b6fcc9537603cec0f1d084e7636705d5eae87b180bc1618a77330e616b714ed1b94ae25f910a7209a6
7
- data.tar.gz: 80eebf4ce42b572fb812a8729d6a71e9a96ed08d7d2d2c04b9b9884d721adf70075a6c2ccc6d400bdbc94573edc44f273baec9c9adcb7517134a6473cbabfdf4
6
+ metadata.gz: df8f83de715f1dfe7bff547a539717841f0595f02c003caa69a2b09f24e50c02d9a7c1372dce6f7cfe4055e0c05ecd023b8b3033b966dd4e1016f4768bbf5b0c
7
+ data.tar.gz: 323215a01e582ad8d223bf76916454ca8ee23dd8d2a8f4bde78c1f57631b50da65cf05d83b6c94e9f94052fed943dfed73bfd05434a94f70414e1054652bc722
@@ -68,13 +68,14 @@ module Suma
68
68
  File.join(@output_path, "schema_#{@schema.id}.yaml")
69
69
  end
70
70
 
71
- def to_config
71
+ def to_config(path: nil)
72
72
  # return @config unless @config
73
73
  @config = SchemaConfig::Config.new
74
74
  @config.schemas << SchemaConfig::Schema.new(
75
75
  id: @schema.id,
76
- path: @schema.path
76
+ path: @schema.path,
77
77
  )
78
+ path and @config.path = path
78
79
 
79
80
  @config
80
81
  end
@@ -83,16 +84,16 @@ module Suma
83
84
  relative_path = Pathname.new(filename_config).relative_path_from(Dir.pwd)
84
85
  Utils.log "Save schema config: #{relative_path}"
85
86
 
87
+ # Still overwrite even if the file exists
86
88
  # return if File.exist?(filename_config)
87
89
  FileUtils.mkdir_p(File.dirname(filename_config))
88
90
 
89
- File.open(filename_config, "w") do |file|
90
- file.write(to_config.to_yaml)
91
- end
91
+ to_config.save_to_path(filename_config)
92
92
  end
93
93
 
94
94
  # Compile Metanorma adoc per EXPRESS schema
95
95
  def compile
96
+ # TODO: Clean artifacts after compiling
96
97
  # I am commenting out because I'm playing with the schemas-only status
97
98
  # return self if File.exist?(output_xml_path)
98
99
 
@@ -104,7 +105,7 @@ module Suma
104
105
  Metanorma::Compile.new.compile(
105
106
  filename_adoc,
106
107
  agree_to_terms: true,
107
- install_fonts: false
108
+ install_fonts: false,
108
109
  )
109
110
  Utils.log "Compiling schema (id: #{id}, type: #{self.class}) => #{relative_path}... done!"
110
111
 
@@ -124,7 +125,7 @@ module Suma
124
125
  filename_adoc,
125
126
  filename_adoc("presentation.xml"),
126
127
  filename_adoc("adoc.lutaml.log.txt"),
127
- filename_adoc("err.html")
128
+ filename_adoc("err.html"),
128
129
  ].each do |filename|
129
130
  FileUtils.rm_rf(filename)
130
131
  end
@@ -78,8 +78,6 @@ module Suma
78
78
  entry.save_exp
79
79
  end
80
80
 
81
- # DISABLING FOLLOWING CODE AS MISCONCEIVED. THE SCHEMA DOCUMENTS
82
- # BELONG IN THE MAIN COLLECTION NOT HERE
83
81
  docs.each_pair do |schema_id, entry|
84
82
  entry.compile
85
83
  end
@@ -9,6 +9,7 @@ module Suma
9
9
  class Config < Shale::Mapper
10
10
  attribute :schemas, Schema, collection: true
11
11
  attribute :path, Shale::Type::String
12
+ attr_accessor :output_path
12
13
 
13
14
  def initialize(**args)
14
15
  @path = path_relative_to_absolute(path) if path
@@ -39,6 +40,7 @@ module Suma
39
40
  @path = path_relative_to_absolute(new_path)
40
41
  schemas.each do |schema|
41
42
  schema.path = path_relative_to_absolute(schema.path)
43
+ schema.container_path = File.expand_path(@path)
42
44
  end
43
45
  end
44
46
 
@@ -48,17 +50,25 @@ module Suma
48
50
  end
49
51
  end
50
52
 
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...
56
53
  def schemas_to_yaml(model, doc)
57
- # puts "^"*30
58
- # pp self
59
- # pp @path
60
54
  doc["schemas"] = model.schemas.sort_by(&:id).to_h do |schema|
61
- [schema.id, { "path" => path_absolute_to_relative(schema.path) }]
55
+ # We are outputting the schemas collection file to the directory where
56
+ # the collection config is at (assumed to be Dir.pwd), not to the
57
+ # directory we sourced the manifest from, e.g.
58
+ # documents/iso-10303-41/schemas.yaml.
59
+
60
+ # So the schema.container_path = @config.path is not
61
+ # in fact needed, as the files are already absolute. This notion of
62
+ # using @path to create relative paths was misconceived
63
+ [
64
+ schema.id,
65
+ {
66
+ "path" => path_absolute_to_relative(
67
+ schema.path,
68
+ model.output_path || Dir.pwd,
69
+ ),
70
+ },
71
+ ]
62
72
  end
63
73
  end
64
74
 
@@ -68,20 +78,18 @@ module Suma
68
78
 
69
79
  # Or based on current working directory?
70
80
  return relative_path unless @path
81
+ # ... but if this calculates path, we end up expanding it anyway
71
82
 
72
83
  Pathname.new(File.dirname(@path)).join(eval_path).expand_path.to_s
73
84
  end
74
85
 
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
86
+ def path_absolute_to_relative(absolute_path, container_path)
87
+ container_path ||= @path
88
+ return absolute_path unless container_path
81
89
 
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
90
+ p = Pathname.new(container_path)
91
+ container = p.directory? ? p.to_s : p.dirname
92
+ Pathname.new(absolute_path).relative_path_from(container).to_s
85
93
  end
86
94
 
87
95
  def update_path(new_path)
@@ -98,8 +106,8 @@ module Suma
98
106
  next if schema_path.absolute?
99
107
 
100
108
  schema_path = (Pathname.new(old_base_path) + schema_path).cleanpath
101
- new_relative_schema_path = schema_path.relative_path_from(new_base_path)
102
- schema.path = new_relative_schema_path
109
+ # This is the new relative schema_path
110
+ schema.path = schema_path.relative_path_from(new_base_path)
103
111
  end
104
112
 
105
113
  @path = new_path
@@ -107,7 +115,7 @@ module Suma
107
115
 
108
116
  def concat(another_config)
109
117
  unless another_config.is_a?(self.class)
110
- raise StandardError, "Can only concatenate a non SchemaConfig::Config object."
118
+ raise StandardError, "Can only concat a SchemaConfig::Config object."
111
119
  end
112
120
 
113
121
  # We need to update the relative paths when paths exist
@@ -120,13 +128,15 @@ module Suma
120
128
  end
121
129
 
122
130
  def save_to_path(filename)
123
- new_config = dup
124
- new_config.path = filename
125
- new_config.update_base_path(File.dirname(filename))
131
+ new_config = dup.tap do |c|
132
+ c.path = filename
133
+ c.update_path(File.dirname(filename))
134
+ c.output_path = filename
135
+ end
126
136
 
127
137
  File.open(filename, "w") do |f|
128
138
  Utils.log "Writing #{filename}..."
129
- f.write(to_yaml)
139
+ f.write(new_config.to_yaml)
130
140
  Utils.log "Done."
131
141
  end
132
142
  end
@@ -8,6 +8,12 @@ module Suma
8
8
  attribute :id, Shale::Type::String
9
9
  attribute :path, Shale::Type::String
10
10
  # attribute :schemas_only, Shale::Type::Boolean
11
+
12
+ # container_path is a copy of Suma::SchemaConfig::Config.path,
13
+ # used to resolve the path of each schema within
14
+ # Suma::SchemaConfig::Config.schemas,
15
+ # when Suma::SchemaConfig::Config.schemas is recursively flattened
16
+ attr_accessor :container_path
11
17
  end
12
18
  end
13
19
  end
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.1"
4
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-20 00:00:00.000000000 Z
11
+ date: 2024-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expressir