suma 0.1.10 → 0.1.11

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: 9c08dd5c9b1e53371518104f17eaa1b0ae59590069e15239051f2619e3083086
4
- data.tar.gz: f4aa885d0259c98ee8f00eefdb21b2fd6d4c2b9ac2e64d6987ce55fe362b5bab
3
+ metadata.gz: 91d8fb8b814f47412c1374e7c12c9d3fb5368a5275c409355c6cc02a728305b6
4
+ data.tar.gz: 3cdf5da9b7c251df88f6434222e3a575e6f1cf3839f83ab7cb47091180807510
5
5
  SHA512:
6
- metadata.gz: a0fcddad0380d5c5e0a714729c0fc59e8195f83f7af1c40fe29caf8fd124cc75fffdaceaeb973b5d4f6cedd0ab526695b7019b5d2391faa94a9b4735267b389f
7
- data.tar.gz: 6f667b5a28f8807980351345dc49ab4959a01b35a1d5463a2afb1851fa2718c55d53916248e2f92eca58d8f899466752d2bd51579747e8d74a8391ba43f3309f
6
+ metadata.gz: 55422c9b98ac260feb77bc8937aff2d45196ba369850a5166b82fec88e7318007c2a6e3d345a441b0ea7e6e3c6df3854432a56ab33012079ababa0fae8a0f6ab
7
+ data.tar.gz: 50e1425e0bb51cff0866dbb4f7de66c03fc72772660aa253eafa5f25ebcd072e6d7f4c4b5006ad84c78fbd9364eb8cf5494498fc1c6747efe9e2b50a9de8757a
data/README.adoc CHANGED
@@ -130,6 +130,42 @@ This command:
130
130
  * Provides progress bars to track schema loading and link validation
131
131
 
132
132
 
133
+ === Reformat command
134
+
135
+ ==== General
136
+
137
+ The `reformat` command provides utilities for reformatting EXPRESS files.
138
+
139
+ [source,sh]
140
+ ----
141
+ $ suma reformat EXPRESS_FILE_PATH [options]
142
+ ----
143
+
144
+ Parameters:
145
+
146
+ `EXPRESS_FILE_PATH`:: Path to an EXPRESS file or a folder containing EXPRESS
147
+ files
148
+
149
+ Options:
150
+
151
+ `--[no-]recursive`:: Select EXPRESS files recursively based on the specified
152
+ folder path (default: false)
153
+
154
+ [example]
155
+ ====
156
+ .To reformat all EXPRESS files under the current directory recursively
157
+ [source,sh]
158
+ ----
159
+ $ bundle exec suma reformat `pwd` -r
160
+ ----
161
+ ====
162
+
163
+ This command:
164
+
165
+ * Loads the EXPRESS files specified in the `EXPRESS_FILE_PATH`
166
+ * Reformats and saves the loaded EXPRESS files
167
+
168
+
133
169
  == Usage: Ruby
134
170
 
135
171
  === General
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require_relative "../thor_ext"
5
+
6
+ module Suma
7
+ module Cli
8
+ # Reformat command for reformatting EXPRESS files
9
+ class Reformat < Thor
10
+ desc "reformat EXPRESS_FILE_PATH",
11
+ "Reformat EXPRESS files"
12
+ option :recursive, type: :boolean, default: false, aliases: "-r",
13
+ desc: "Reformat EXPRESS files under the specified " \
14
+ "path recursively"
15
+
16
+ def reformat(express_file_path) # rubocop:disable Metrics/AbcSize
17
+ if File.file?(express_file_path)
18
+ unless File.exist?(express_file_path)
19
+ raise Errno::ENOENT, "Specified EXPRESS file " \
20
+ "`#{express_file_path}` not found."
21
+ end
22
+
23
+ if File.extname(express_file_path) != ".exp"
24
+ raise ArgumentError, "Specified file `#{express_file_path}` is " \
25
+ "not an EXPRESS file."
26
+ end
27
+
28
+ exp_files = [express_file_path]
29
+ elsif options[:recursive]
30
+ exp_files = Dir.glob("#{express_file_path}/**/*.exp")
31
+ else
32
+ exp_files = Dir.glob("#{express_file_path}/*.exp")
33
+ end
34
+
35
+ if exp_files.empty?
36
+ raise Errno::ENOENT, "No EXPRESS files found in " \
37
+ "`#{express_file_path}`."
38
+ end
39
+
40
+ run(exp_files)
41
+ end
42
+
43
+ private
44
+
45
+ def run(exp_files)
46
+ exp_files.each do |exp_file|
47
+ reformat_exp(exp_file)
48
+ end
49
+ end
50
+
51
+ def reformat_exp(file) # rubocop:disable Metrics/AbcSize
52
+ # Read the file content
53
+ file_content = File.read(file)
54
+
55
+ # Extract all comments between '(*"' and '\n*)'
56
+ # Avoid incorrect selection of some comment blocks
57
+ # containing '(*text*)' inside
58
+ comments = file_content.scan(/\(\*"(.*?)\n\*\)/m).map(&:first)
59
+
60
+ if comments.count.positive?
61
+ content_without_comments = file_content.gsub(/\(\*".*?\n\*\)/m, "")
62
+
63
+ # remove extra newlines
64
+ new_content = content_without_comments.gsub(/(\n\n+)/, "\n\n")
65
+ # Add '(*"' and '\n*)' to enclose the comment block
66
+ new_comments = comments.map { |c| "(*\"#{c}\n*)" }.join("\n\n")
67
+ # Append the comments to the end of the file
68
+ new_content = "#{new_content}\n\n#{new_comments}\n"
69
+
70
+ # Compare the changes between the original content with the modified
71
+ # content, if the changes are just whitespaces, skip modifying the
72
+ # file
73
+ if file_content.gsub(/(\n+)/, "\n") == new_content.gsub(/(\n+)/, "\n")
74
+ puts "No changes made to #{file}"
75
+ return
76
+ end
77
+
78
+ update_exp(file, new_content)
79
+ end
80
+ end
81
+
82
+ def update_exp(file, content)
83
+ # Write the modified content to a new file
84
+ File.write(file, content)
85
+ puts "Reformatted EXPRESS file and saved to #{file}"
86
+ end
87
+ end
88
+ end
89
+ end
data/lib/suma/cli.rb CHANGED
@@ -27,6 +27,16 @@ module Suma
27
27
  require_relative "cli/links"
28
28
  Cli::Links.start
29
29
  end
30
+
31
+ desc "reformat EXPRESS_FILE_PATH",
32
+ "Reformat EXPRESS files"
33
+ option :recursive, type: :boolean, default: false, aliases: "-r",
34
+ desc: "Reformat EXPRESS files under the specified " \
35
+ "path recursively"
36
+ def reformat(_express_file_path)
37
+ require_relative "cli/reformat"
38
+ Cli::Reformat.start
39
+ end
30
40
  end
31
41
  end
32
42
  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.10"
4
+ VERSION = "0.1.11"
5
5
  end
data/suma.gemspec CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
33
33
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
34
  spec.require_paths = ["lib"]
35
35
 
36
- spec.add_dependency "expressir", "~> 2.1.16"
36
+ spec.add_dependency "expressir", "~> 2.1"
37
37
  spec.add_dependency "lutaml-model", "~> 0.7"
38
38
  spec.add_dependency "metanorma-cli"
39
39
  spec.add_dependency "ruby-progressbar"
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.10
4
+ version: 0.1.11
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-03-23 00:00:00.000000000 Z
11
+ date: 2025-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expressir
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.16
19
+ version: '2.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.16
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: lutaml-model
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +107,7 @@ files:
107
107
  - lib/suma/cli.rb
108
108
  - lib/suma/cli/build.rb
109
109
  - lib/suma/cli/links.rb
110
+ - lib/suma/cli/reformat.rb
110
111
  - lib/suma/collection_config.rb
111
112
  - lib/suma/collection_manifest.rb
112
113
  - lib/suma/express_schema.rb