suma 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c8560abb88a9afd280a88d4671dc2aa2e674279765c5909ddba83df1e47c695c
4
+ data.tar.gz: 8aff2c39d4d9d380a5f685ac49823afd195a6862d16921301fc43a24448b820a
5
+ SHA512:
6
+ metadata.gz: 9e920d236b6df4c74fd6c52ae3c4d24403575d10f14b41f893560962d1531c5bb6ff6798efaa7d010c5fd346cf2e820e120eafbe8cea3d6b15a80f53d9f14030
7
+ data.tar.gz: fdb19a5151df97eba81e0c23382f9c5c6f7ee082bb1d7b447a25e927626f47391c658f1afd32ac20ecc66fb5064af12f3e3f1263a65daadb59962ae8ccf7533c
@@ -0,0 +1,27 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ pull_request:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ name: Ruby ${{ matrix.ruby }}
14
+ strategy:
15
+ matrix:
16
+ ruby:
17
+ - '3.2.2'
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Run the default task
27
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ronald.tse@ribose.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in suma.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/README.adoc ADDED
@@ -0,0 +1,83 @@
1
+ = Suma: utility for the STEP Unified Model-driven Architecture
2
+
3
+ == Purpose
4
+
5
+ SUMA, the "STEP Unified Model-Based Standards Architecture", is a authoring and
6
+ publication system developed for the management of EXPRESS schemas and its
7
+ documentation.
8
+
9
+ This utility is used by the
10
+ https://github.com/metanorma/iso-10303[ISO 10303 collection]
11
+ to build the following artifacts:
12
+
13
+ * the STEP Resource Library (SRL)
14
+
15
+
16
+ == Install
17
+
18
+ [source,sh]
19
+ ----
20
+ $ gem install suma
21
+ ----
22
+
23
+ == Usage
24
+
25
+ === General
26
+
27
+ [source,sh]
28
+ ----
29
+ # Defaults to `suma help`
30
+ $ suma
31
+ Commands:
32
+ suma build METANORMA_SITE_MANIFEST # Build collection specified in site manifest (`metanorma*.yml`)
33
+ suma help [COMMAND] # Describe available commands or one specific command
34
+ ----
35
+
36
+ Where:
37
+
38
+ `METANORMA_SITE_MANIFEST`:: This is the path to the Metanorma site manifest,
39
+ typically `metanorma.yml`.
40
+
41
+
42
+ === Compilation
43
+
44
+ .To compile SRL subset test collection
45
+ [source,sh]
46
+ ----
47
+ $ bundle exec suma build metanorma-test.yml
48
+ ----
49
+
50
+ .To build SRL collection
51
+ [source,sh]
52
+ ----
53
+ $ bundle exec suma build metanorma-srl.yml
54
+ ----
55
+
56
+ // .To compile all STEPmod migrated docs (without detached) individually
57
+ // [source,sh]
58
+ // ----
59
+ // $ bundle exec metanorma site generate
60
+ // ----
61
+
62
+
63
+ === Generating full schema listing files
64
+
65
+ We generate the full schema collection listing using the `--no-compile`
66
+ option in the `suma` command.
67
+
68
+ The generated `schemas-*.yaml` file name is derived from the input file name
69
+ with the word `metanorma` replaced with `schemas`.
70
+
71
+ [source,sh]
72
+ ----
73
+ $ bundle exec suma build --no-compile metanorma-srl.yml
74
+ # => generates schemas-srl.yml
75
+ ----
76
+
77
+ All documents need to have a `schemas.yaml` in their document root that lists
78
+ out which schemas the document includes.
79
+
80
+
81
+ == License
82
+
83
+ Copyright Ribose. BSD 2-clause license.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "suma"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/suma ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "suma/cli"
5
+
6
+ Suma::Cli.start(ARGV)
data/lib/suma/cli.rb ADDED
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require_relative "thor_ext"
5
+ require_relative "processor"
6
+ require_relative "utils"
7
+
8
+ module Suma
9
+ class Cli < Thor
10
+ extend ThorExt::Start
11
+
12
+ desc "build METANORMA_SITE_MANIFEST", "Build collection specified in site manifest (`metanorma*.yml`)"
13
+ option :compile, type: :boolean, default: true, desc: "Compile or skip compile of collection"
14
+ option :schemas_all_path, type: :string, aliases: "-s",
15
+ desc: "Generate file that contains all schemas in the collection."
16
+
17
+ def build(metanorma_site_manifest)
18
+ unless File.exist?(metanorma_site_manifest)
19
+ raise Errno::ENOENT, "Specified Metanorma site manifest file " \
20
+ "`#{metanorma_site_manifest}` not found."
21
+ end
22
+
23
+ # Set schemas_all_path to match metanorma_yaml_path
24
+ schemas_all_path = options[:schemas_all_path] ||
25
+ metanorma_site_manifest.gsub("metanorma", "schemas")
26
+
27
+ begin
28
+ Processor.run(
29
+ metanorma_yaml_path: metanorma_site_manifest,
30
+ schemas_all_path: schemas_all_path,
31
+ compile: options[:compile],
32
+ output_directory: "_site"
33
+ )
34
+ rescue StandardError => e
35
+ Utils.log "[ERROR] Error occurred during processing. See details below."
36
+ Utils.log e
37
+ Utils.log e.inspect
38
+ Utils.log e.backtrace
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "utils"
4
+ require "fileutils"
5
+ require "expressir"
6
+
7
+ module Suma
8
+ class ExpressSchema
9
+ attr_accessor :path, :id, :parsed, :output_path
10
+
11
+ def initialize(path:, output_path:)
12
+ @path = Pathname.new(path).expand_path
13
+ @parsed = Expressir::Express::Parser.from_file(@path.to_s)
14
+ Utils.log "Loaded EXPRESS schema: #{path}"
15
+
16
+ @id = @parsed.schemas.first.id
17
+ @output_path = output_path
18
+ end
19
+
20
+ def type
21
+ case @path.to_s
22
+ when %r{.*/resources/.*}
23
+ "resources"
24
+ when %r{.*/modules/.*}
25
+ "modules"
26
+ else
27
+ "unknown_type"
28
+ end
29
+ end
30
+
31
+ def to_plain
32
+ @parsed.to_s(no_remarks: true)
33
+ end
34
+
35
+ def filename_plain
36
+ File.join(@output_path, type, id, "#{id}.exp")
37
+ end
38
+
39
+ def save_exp
40
+ relative_path = Pathname.new(filename_plain).relative_path_from(Dir.pwd)
41
+ Utils.log "Save plain schema: #{relative_path}"
42
+
43
+ # return if File.exist?(filename_plain)
44
+ FileUtils.mkdir_p(File.dirname(filename_plain))
45
+
46
+ File.open(filename_plain, "w") do |file|
47
+ file.write(to_plain)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ # col = Suma::SchemaCollection.new(
54
+ # config_yaml: 'suma-schemas.yaml',
55
+ # output_path_docs: 'schema_docs',
56
+ # output_path_schemas: 'plain_schemas'
57
+ # )
58
+
59
+ # docs = col.compile
60
+
61
+ # paths = col.schemas.map do |schema|
62
+ # {
63
+ # plain_schema_path: schema.filename_plain,
64
+ # schema_doc_path: col.doc_from_schema_name(schema.id).output_xml_path
65
+ # }
66
+ # end
67
+
68
+ # Utils.log "COMPILED FILES ARE AT:"
69
+ # pp paths
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "schema_config"
4
+ require_relative "schema_collection"
5
+ require_relative "utils"
6
+ require_relative "to_replace/collection_config"
7
+ require_relative "to_replace/site_config"
8
+ require "metanorma/cli"
9
+ require "metanorma/cli/collection"
10
+ require "metanorma/collection/collection"
11
+
12
+ module Suma
13
+ class Processor
14
+ class << self
15
+ # Can move to schema_config.rb
16
+ def write_all_schemas(schemas_all_path, document_paths)
17
+ all_schemas = Suma::SchemaConfig::Config.new(path: schemas_all_path)
18
+
19
+ document_paths.each do |path|
20
+ schemas_yaml = File.join(File.dirname(path), "schemas.yaml")
21
+ next unless File.exist?(schemas_yaml)
22
+
23
+ schemas_config = Suma::SchemaConfig::Config.from_file(schemas_yaml)
24
+ all_schemas.concat(schemas_config)
25
+ end
26
+
27
+ Utils.log "Writing #{schemas_all_path}..."
28
+ all_schemas.to_file
29
+ Utils.log "Done."
30
+ end
31
+
32
+ def run(metanorma_yaml_path:, schemas_all_path:, compile:, output_directory: "_site")
33
+ Utils.log "Current directory: #{Dir.getwd}"
34
+
35
+ # This reads the metanorma.yml file
36
+ site_config = Suma::ToReplace::SiteConfig::Config.from_file(metanorma_yaml_path)
37
+
38
+ # TODO: only reading the first file, which is a collection.yml, which is a hack...
39
+ collection_config_path = site_config.metanorma.source.files.first
40
+ collection_config = Suma::ToReplace::CollectionConfig::Config.from_file(collection_config_path)
41
+ collection_config.path = collection_config_path
42
+
43
+ # Gather all the inner (per-document) collection.yml files
44
+ document_paths = collection_config.manifest.docref.map(&:file)
45
+
46
+ write_all_schemas(schemas_all_path, document_paths)
47
+
48
+ col = Suma::SchemaCollection.new(
49
+ config_yaml: schemas_all_path,
50
+ output_path_docs: "schema_docs",
51
+ output_path_schemas: "plain_schemas"
52
+ )
53
+
54
+ if compile
55
+ Utils.log "Compiling schema collection..."
56
+ col.compile
57
+ else
58
+ Utils.log "No compile option set. Skipping schema compilation."
59
+ end
60
+
61
+ # TODO: Do we still need this?
62
+ # Define Proc to resolve fileref
63
+ my_fileref_proc = proc do |ref_folder, fileref|
64
+ # move schemas to modified_schemas
65
+ if File.extname(fileref) == ".exp"
66
+ fileref.gsub!(
67
+ "../../schemas",
68
+ "modified_schemas"
69
+ )
70
+ end
71
+ File.join(ref_folder, fileref)
72
+ end
73
+
74
+ # TODO: Do we still need this?
75
+ # Define Proc to resolve identifier
76
+ my_identifier_proc = proc do |identifier|
77
+ case identifier
78
+ when %r{^documents/}
79
+ identifier.gsub("documents/", "")
80
+ else
81
+ identifier
82
+ end
83
+ end
84
+
85
+ # TODO: Do we still need this?
86
+ # Define Proc to handle the compilation of express schemas
87
+ express_schemas_renderer = proc do |collection_model|
88
+ end
89
+
90
+ # TODO: Do we still need this?
91
+ Metanorma::Collection.tap do |mn|
92
+ mn.set_identifier_resolver(&my_identifier_proc)
93
+ mn.set_fileref_resolver(&my_fileref_proc)
94
+ mn.set_pre_parse_model(&express_schemas_renderer)
95
+ end
96
+
97
+ if compile
98
+ Utils.log "Compiling complete collection..."
99
+
100
+ metanorma_collection = Metanorma::Collection.parse(collection_config_path)
101
+
102
+ # TODO: Somehow this is no longer used
103
+ collection_opts = {
104
+ format: [:html],
105
+ output_folder: output_directory,
106
+ compile: {
107
+ no_install_fonts: true
108
+ },
109
+ coverpage: "cover.html"
110
+ }
111
+ metanorma_collection.render(collection_opts)
112
+
113
+ # remove xml files
114
+ Dir.glob(File.join(Dir.getwd, output_directory, "*.xml")).each do |file|
115
+ File.delete(file)
116
+ end
117
+ else
118
+ Utils.log "No compile option set. Skipping collection compilation."
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "express_schema"
4
+ require_relative "schema_doc"
5
+ require_relative "schema_config"
6
+ require_relative "utils"
7
+
8
+ module Suma
9
+ class SchemaCollection
10
+ attr_accessor :config, :schemas, :docs, :output_path_docs, :output_path_schemas
11
+
12
+ def initialize(config: nil, config_yaml: nil, output_path_docs: nil, output_path_schemas: nil)
13
+ @schemas = []
14
+ @docs = []
15
+ @schema_name_to_docs = {}
16
+ @output_path_docs = if output_path_docs
17
+ Pathname.new(output_path_docs).expand_path
18
+ else
19
+ Pathname.new(Dir.pwd)
20
+ end
21
+ @output_path_schemas = if output_path_schemas
22
+ Pathname.new(output_path_schemas).expand_path
23
+ else
24
+ Pathname.new(Dir.pwd)
25
+ end
26
+
27
+ @config = if config
28
+ config
29
+ elsif config_yaml
30
+ SchemaConfig::Config.from_file(config_yaml)
31
+ end
32
+
33
+ return self unless @config
34
+
35
+ @config.schemas.each do |config_schema|
36
+ s = ExpressSchema.new(
37
+ path: config_schema.path,
38
+ output_path: @output_path_schemas
39
+ )
40
+ doc = SchemaDoc.new(
41
+ schema: s,
42
+ output_path: @output_path_docs.join(s.id)
43
+ )
44
+ @docs << doc
45
+ @schemas << s
46
+ @schema_name_to_docs[s.id] = doc
47
+ end
48
+ end
49
+
50
+ def doc_from_schema_name(schema_name)
51
+ @schema_name_to_docs[schema_name]
52
+ end
53
+
54
+ def compile
55
+ schemas.map(&:save_exp)
56
+
57
+ docs.each(&:compile)
58
+
59
+ # TODO: make this parallel
60
+ # puts "Starting Ractor processing"
61
+ # pool = Ractor.new do
62
+ # loop do
63
+ # Ractor.yield(Ractor.receive)
64
+ # end
65
+ # end
66
+ # workers = (1..4).map do |i|
67
+ # Ractor.new(pool, name: "r#{i}") do |p|
68
+ # loop do
69
+ # input = p.take
70
+ # puts "compiling in ractor for #{input.filename_adoc}"
71
+ # output_value = input.compile
72
+ # Ractor.yield(output_value)
73
+ # end
74
+ # end
75
+ # end
76
+ # docs.each do |doc|
77
+ # pool.send(doc)
78
+ # end
79
+ # results = []
80
+ # docs.size.times do
81
+ # results << Ractor.select(*workers)
82
+ # end
83
+ # pp results
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shale"
4
+ require_relative "schema"
5
+ require_relative "../utils"
6
+
7
+ module Suma
8
+ module SchemaConfig
9
+ class Config < Shale::Mapper
10
+ attribute :schemas, Schema, collection: true
11
+ attr_accessor :base_path, :path
12
+
13
+ def initialize(path: nil, **args)
14
+ @path = path
15
+ super(**args)
16
+ end
17
+
18
+ def base_path
19
+ File.dirname(@path)
20
+ end
21
+
22
+ yaml do
23
+ map "schemas", using: { from: :schemas_from_yaml, to: :schemas_to_yaml }
24
+ end
25
+
26
+ def self.from_file(path)
27
+ from_yaml(File.read(path)).tap do |x|
28
+ x.path = path
29
+ end
30
+ end
31
+
32
+ def to_file(to_path = path)
33
+ File.open(to_path, "w") do |f|
34
+ f.write(to_yaml)
35
+ end
36
+ end
37
+
38
+ def schemas_from_yaml(model, value)
39
+ model.schemas = value.map do |k, v|
40
+ Schema.new(id: k, path: v["path"])
41
+ end
42
+ end
43
+
44
+ def schemas_to_yaml(model, doc)
45
+ doc["schemas"] = model.schemas.sort_by(&:id).to_h do |schema|
46
+ [schema.id, { "path" => schema.path }]
47
+ end
48
+ end
49
+
50
+ def update_path(new_path)
51
+ old_base_path = File.dirname(@path)
52
+ new_base_path = File.dirname(new_path)
53
+
54
+ schemas.each do |schema|
55
+ schema_path = Pathname.new(schema.path)
56
+ next if schema_path.absolute?
57
+
58
+ schema_path = (Pathname.new(old_base_path) + schema_path).cleanpath
59
+ new_relative_schema_path = schema_path.relative_path_from(new_base_path)
60
+ schema.path = new_relative_schema_path
61
+ end
62
+
63
+ @path = new_path
64
+ end
65
+
66
+ def concat(another_config)
67
+ unless another_config.is_a?(self.class)
68
+ raise StandardError, "Can only concatenate a non SchemaConfig::Config object."
69
+ end
70
+
71
+ # We need to update the relative paths
72
+ if path != another_config.path
73
+ new_config = another_config.dup
74
+ new_config.update_path(path)
75
+ end
76
+
77
+ schemas.concat(another_config.schemas)
78
+ end
79
+
80
+ def save_to_path(filename)
81
+ new_config = dup
82
+ new_config.path = filename
83
+ new_config.update_base_path(File.dirname(filename))
84
+
85
+ File.open(filename, "w") do |f|
86
+ Utils.log "Writing #{filename}..."
87
+ f.write(to_yaml)
88
+ Utils.log "Done."
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shale"
4
+
5
+ module Suma
6
+ module SchemaConfig
7
+ class Schema < Shale::Mapper
8
+ attribute :id, Shale::Type::String
9
+ attribute :path, Shale::Type::String
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "schema_config/schema"
4
+ require_relative "schema_config/config"
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ # require "metanorma/cli"
5
+ require_relative "schema_config"
6
+
7
+ module Suma
8
+ class SchemaDoc
9
+ attr_accessor :schema, :output_path, :config
10
+
11
+ def initialize(schema:, output_path:)
12
+ @schema = schema
13
+ @output_path = output_path
14
+ end
15
+
16
+ def to_adoc(path_to_schema_yaml)
17
+ <<~HEREDOC
18
+ = #{@schema.id}
19
+ :lutaml-express-index: schemas; #{path_to_schema_yaml};
20
+ :bare: true
21
+ :mn-document-class: iso
22
+ :mn-output-extensions: xml,html
23
+
24
+ [lutaml,schemas,context]
25
+ ----
26
+ {% for schema in context.schemas %}
27
+
28
+ [%unnumbered]
29
+ == #{@schema.id}
30
+
31
+ [source%unnumbered]
32
+ --
33
+ {{ schema.formatted }}
34
+ --
35
+ {% endfor %}
36
+ ----
37
+
38
+ HEREDOC
39
+ end
40
+
41
+ def filename_adoc(ext = "adoc")
42
+ File.join(@output_path, "doc_#{@schema.id}.#{ext}")
43
+ end
44
+
45
+ def save_adoc
46
+ relative_path = Pathname.new(filename_adoc).relative_path_from(Dir.pwd)
47
+ Utils.log "Save EXPRESS adoc: #{relative_path}"
48
+
49
+ # return if File.exist?(filename_adoc)
50
+ FileUtils.mkdir_p(File.dirname(filename_adoc))
51
+
52
+ relative_path = Pathname.new(filename_config)
53
+ .relative_path_from(Pathname.new(File.dirname(filename_adoc)))
54
+
55
+ # Utils.log "relative_path #{relative_path}"
56
+
57
+ File.open(filename_adoc, "w") do |file|
58
+ file.write(to_adoc(relative_path))
59
+ end
60
+ end
61
+
62
+ def filename_config
63
+ File.join(@output_path, "schema_#{@schema.id}.yaml")
64
+ end
65
+
66
+ def to_config
67
+ # return @config unless @config
68
+ @config = SchemaConfig::Config.new
69
+ @config.schemas << SchemaConfig::Schema.new(
70
+ id: @schema.id,
71
+ path: @schema.path
72
+ )
73
+
74
+ @config
75
+ end
76
+
77
+ def save_config
78
+ relative_path = Pathname.new(filename_config).relative_path_from(Dir.pwd)
79
+ Utils.log "Save schema config: #{relative_path}"
80
+
81
+ # return if File.exist?(filename_config)
82
+ FileUtils.mkdir_p(File.dirname(filename_config))
83
+
84
+ File.open(filename_config, "w") do |file|
85
+ file.write(to_config.to_yaml)
86
+ end
87
+ end
88
+
89
+ # Compile Metanorma adoc per EXPRESS schema
90
+ def compile
91
+ return self if File.exist?(output_xml_path)
92
+
93
+ save_config
94
+ save_adoc
95
+
96
+ relative_path = Pathname.new(filename_adoc).relative_path_from(Dir.pwd)
97
+ Utils.log "Compiling schema #{relative_path}..."
98
+ Metanorma::Compile.new.compile(
99
+ filename_adoc,
100
+ agree_to_terms: true,
101
+ no_install_fonts: true
102
+ )
103
+ Utils.log "Compiling schema #{filename_adoc}...done!"
104
+
105
+ # clean_artifacts
106
+
107
+ # filename_adoc('xml')
108
+ self
109
+ end
110
+
111
+ def output_xml_path
112
+ filename_adoc("xml")
113
+ end
114
+
115
+ def clean_artifacts
116
+ [
117
+ filename_config,
118
+ filename_adoc,
119
+ filename_adoc("presentation.xml"),
120
+ filename_adoc("adoc.lutaml.log.txt"),
121
+ filename_adoc("err.html")
122
+ ].each do |filename|
123
+ FileUtils.rm_rf(filename)
124
+ end
125
+ end
126
+
127
+ def output_folder; end
128
+ end
129
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Suma
4
+ module ThorExt
5
+ # Configures Thor to behave more like a typical CLI, with better help and error handling.
6
+ #
7
+ # - Passing -h or --help to a command will show help for that command.
8
+ # - Unrecognized options will be treated as errors (instead of being silently ignored).
9
+ # - Error messages will be printed in red to stderr, without stack trace.
10
+ # - Full stack traces can be enabled by setting the VERBOSE environment variable.
11
+ # - Errors will cause Thor to exit with a non-zero status.
12
+ #
13
+ # To take advantage of this behavior, your CLI should subclass Thor and extend this module.
14
+ #
15
+ # class CLI < Thor
16
+ # extend ThorExt::Start
17
+ # end
18
+ #
19
+ # Start your CLI with:
20
+ #
21
+ # CLI.start
22
+ #
23
+ # In tests, prevent Kernel.exit from being called when an error occurs, like this:
24
+ #
25
+ # CLI.start(args, exit_on_failure: false)
26
+ #
27
+ module Start
28
+ def self.extended(base)
29
+ super
30
+ base.check_unknown_options!
31
+ end
32
+
33
+ def start(given_args = ARGV, config = {})
34
+ config[:shell] ||= Thor::Base.shell.new
35
+ handle_help_switches(given_args) do |args|
36
+ dispatch(nil, args, nil, config)
37
+ end
38
+ rescue StandardError => e
39
+ handle_exception_on_start(e, config)
40
+ end
41
+
42
+ private
43
+
44
+ def handle_help_switches(given_args)
45
+ yield(given_args.dup)
46
+ rescue Thor::UnknownArgumentError => e
47
+ retry_with_args = []
48
+
49
+ if given_args.first == "help"
50
+ retry_with_args = ["help"] if given_args.length > 1
51
+ elsif e.unknown.intersect?(%w[-h --help])
52
+ retry_with_args = ["help", (given_args - e.unknown).first]
53
+ end
54
+ raise unless retry_with_args.any?
55
+
56
+ yield(retry_with_args)
57
+ end
58
+
59
+ def handle_exception_on_start(error, config)
60
+ return if error.is_a?(Errno::EPIPE)
61
+ raise if ENV["VERBOSE"] || !config.fetch(:exit_on_failure, true)
62
+
63
+ message = error.message.to_s
64
+ message.prepend("[#{error.class}] ") if message.empty? || !error.is_a?(Thor::Error)
65
+
66
+ config[:shell]&.say_error(message, :red)
67
+ exit(false)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../utils"
4
+ require "shale"
5
+
6
+ module Suma
7
+ module ToReplace
8
+ module CollectionConfig
9
+ class CompileOptions < Shale::Mapper
10
+ attribute :no_install_fonts, Shale::Type::Boolean, default: -> { true }
11
+ attribute :agree_to_terms, Shale::Type::Boolean, default: -> { true }
12
+ end
13
+
14
+ class BibdataTitle < Shale::Mapper
15
+ attribute :language, Shale::Type::String
16
+ attribute :content, Shale::Type::String
17
+ end
18
+
19
+ class BibdataDocid < Shale::Mapper
20
+ attribute :type, Shale::Type::String
21
+ attribute :id, Shale::Type::String
22
+ end
23
+
24
+ class BibdataContributor < Shale::Mapper
25
+ attribute :name, Shale::Type::String
26
+ attribute :abbreviation, Shale::Type::String
27
+ end
28
+
29
+ class BibdataCopyright < Shale::Mapper
30
+ attribute :owner, BibdataContributor
31
+ attribute :from, Shale::Type::String
32
+ end
33
+
34
+ class Bibdata < Shale::Mapper
35
+ attribute :title, BibdataTitle, collection: true
36
+ attribute :type, Shale::Type::String
37
+ attribute :docid, BibdataDocid
38
+ attribute :edition, Shale::Type::Integer
39
+ attribute :copyright, BibdataCopyright
40
+ end
41
+
42
+ class ManifestItem < Shale::Mapper
43
+ attribute :identifier, Shale::Type::String
44
+ attribute :level, Shale::Type::String
45
+ attribute :title, Shale::Type::String
46
+ attribute :attachment, Shale::Type::Boolean
47
+ attribute :sectionsplit, Shale::Type::Boolean
48
+ attribute :file, Shale::Type::String
49
+ attribute :docref, ManifestItem, collection: true
50
+
51
+ yaml do
52
+ map "identifier", to: :identifier
53
+ map "level", to: :level
54
+ map "title", to: :title
55
+ map "attachment", to: :attachment
56
+ map "sectionsplit", to: :sectionsplit
57
+ map "file", to: :file
58
+ map "fileref", to: :fileref
59
+ map "docref", to: :docref
60
+ map "fileref", using: { from: :fileref_from_yaml, to: :fileref_to_yaml }
61
+ end
62
+
63
+ def fileref_from_yaml(model, value)
64
+ # Utils.log "model #{model}, value #{value}"
65
+ # file_from_yaml(model, value)
66
+ model.file ||= value
67
+ end
68
+
69
+ def fileref_to_yaml(_model, _doc)
70
+ nil
71
+ end
72
+ end
73
+
74
+ class Manifest < Shale::Mapper
75
+ attribute :level, Shale::Type::String
76
+ attribute :title, Shale::Type::String
77
+ attribute :sectionsplit, Shale::Type::Boolean
78
+ attribute :docref, ManifestItem, collection: true
79
+
80
+ def attachments
81
+ docref.detect do |ref|
82
+ ref.level == "attachments"
83
+ end&.docref
84
+ end
85
+
86
+ def documents
87
+ docref.detect do |ref|
88
+ ref.level == "document"
89
+ end&.docref
90
+ end
91
+ end
92
+
93
+ class Config < Shale::Mapper
94
+ attr_accessor :path
95
+
96
+ attribute :directives, Shale::Type::String, collection: true
97
+ attribute :bibdata, Bibdata
98
+ attribute :manifest, Manifest
99
+ attribute :format, Shale::Type::String, collection: true, default: -> { [:html] }
100
+ attribute :output_folder, Shale::Type::String
101
+ attribute :coverpage, Shale::Type::String, default: -> { "cover.html" }
102
+ attribute :compile, CompileOptions
103
+ attribute :prefatory_content, Shale::Type::String
104
+ attribute :final_content, Shale::Type::String
105
+
106
+ def self.from_file(path)
107
+ from_yaml(File.read(path))
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shale"
4
+
5
+ module Suma
6
+ module ToReplace
7
+ module SiteConfig
8
+ class SiteInfo < Shale::Mapper
9
+ attribute :organization, Shale::Type::String
10
+ attribute :name, Shale::Type::String
11
+ end
12
+
13
+ class Sources < Shale::Mapper
14
+ attribute :files, Shale::Type::String, collection: true
15
+ end
16
+
17
+ class Base < Shale::Mapper
18
+ attribute :source, Sources
19
+ attribute :collection, SiteInfo
20
+ end
21
+
22
+ class Config < Shale::Mapper
23
+ attribute :metanorma, Base
24
+
25
+ def self.from_file(path)
26
+ from_yaml(File.read(path))
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/suma/utils.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Suma
4
+ module Utils
5
+ class << self
6
+ def log(message)
7
+ puts "[suma] #{message}"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Suma
4
+ VERSION = "0.1.0"
5
+ end
data/lib/suma.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "suma/version"
4
+ require_relative "suma/processor"
5
+
6
+ module Suma
7
+ class Error < StandardError; end
8
+
9
+ # Your code goes here...
10
+ end
data/sig/suma.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Suma
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/suma.gemspec ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/suma/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "suma"
7
+ spec.version = Suma::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com"]
10
+
11
+ spec.summary = "Utility for SUMA " \
12
+ "(STEP Unified Model-Based Standards Architecture)"
13
+ spec.description = <<~DESCRIPTION
14
+ Utility for SUMA (STEP Unified Model-Based Standards Architecture)
15
+ DESCRIPTION
16
+
17
+ spec.homepage = "https://github.com/metanorma/suma"
18
+ spec.license = "BSD-2-Clause"
19
+
20
+ spec.bindir = "bin"
21
+ spec.require_paths = ["lib"]
22
+ spec.files = `git ls-files`.split("\n")
23
+ spec.test_files = `git ls-files -- {spec}/*`.split("\n")
24
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
29
+ `git ls-files -z`.split("\x0").reject do |f|
30
+ f.match(%r{^(test|spec|features)/})
31
+ end
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_runtime_dependency "expressir"
38
+ spec.add_runtime_dependency "metanorma-cli"
39
+ spec.add_runtime_dependency "shale"
40
+ spec.add_runtime_dependency "thor", ">= 0.20"
41
+ spec.add_development_dependency "rubocop"
42
+ spec.add_development_dependency "rubocop-performance"
43
+ spec.add_development_dependency "rubocop-rails"
44
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: suma
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: expressir
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: metanorma-cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: shale
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0.20'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0.20'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: 'Utility for SUMA (STEP Unified Model-Based Standards Architecture)
112
+
113
+ '
114
+ email:
115
+ - open.source@ribose.com
116
+ executables:
117
+ - suma
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".github/workflows/main.yml"
122
+ - ".gitignore"
123
+ - ".rspec"
124
+ - ".rubocop.yml"
125
+ - CODE_OF_CONDUCT.md
126
+ - Gemfile
127
+ - README.adoc
128
+ - Rakefile
129
+ - bin/console
130
+ - bin/setup
131
+ - exe/suma
132
+ - lib/suma.rb
133
+ - lib/suma/cli.rb
134
+ - lib/suma/express_schema.rb
135
+ - lib/suma/processor.rb
136
+ - lib/suma/schema_collection.rb
137
+ - lib/suma/schema_config.rb
138
+ - lib/suma/schema_config/config.rb
139
+ - lib/suma/schema_config/schema.rb
140
+ - lib/suma/schema_doc.rb
141
+ - lib/suma/thor_ext.rb
142
+ - lib/suma/to_replace/collection_config.rb
143
+ - lib/suma/to_replace/site_config.rb
144
+ - lib/suma/utils.rb
145
+ - lib/suma/version.rb
146
+ - sig/suma.rbs
147
+ - suma.gemspec
148
+ homepage: https://github.com/metanorma/suma
149
+ licenses:
150
+ - BSD-2-Clause
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 3.0.0
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubygems_version: 3.4.10
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Utility for SUMA (STEP Unified Model-Based Standards Architecture)
171
+ test_files: []