metanorma-plugin-lutaml 0.2.5 → 0.3.0

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: 720c7f46803fd6650d13e51e6b1e5111a09c9cf3773c832e239020a8ea5cee75
4
- data.tar.gz: d349fbb9970f16e8bbcf1396d71ec628b7cdbf0204dcdb50d14db8ba2727b0c2
3
+ metadata.gz: b289ab4f617cefd59b1fe794d256b1e903fdbbf419b2fba937fed2ef686969bc
4
+ data.tar.gz: f1a0678e22c0e703b031de634a48851d76ec474403a39cf626c9df31e36d8f4f
5
5
  SHA512:
6
- metadata.gz: 4a855cb5d2c1d7fa9878e0213c6e4ad53381afdaae8ac8cfaed1ed590c8b4a8d9784f12e148888a840c3829913d9a8ab4b0b1715339cade1320d8cfecb8f547c
7
- data.tar.gz: 0dc60a360f2416481d42c369eb12fd4c73f7833b4904255117bfa1c787accbc58e5de74f29488d9c4456908497bd60ccc680788c1f78c324fcaaa955b6e0449d
6
+ metadata.gz: 20c54f6adb3963c4db9be07adc77c0518f2d3140588a99fe68f177cdc2c927fc4996c3db0bf3a6bcd5ced2147d53ac877c3909ff025b6baa5498e1e491f8f761
7
+ data.tar.gz: 4479579349a783361f97c4066fb78d3abb538fcfbc1d6250e9daf9aecc465fa0e93d1240ee1de6b01f9a8750ad89d6e20e77cdfb26aebcf002d95416937eb86b
@@ -1,8 +1,10 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
1
3
  name: rake
2
4
 
3
5
  on:
4
6
  push:
5
- branches: [ main ]
7
+ branches: [ master, main ]
6
8
  tags: [ v* ]
7
9
  pull_request:
8
10
 
@@ -14,52 +16,38 @@ jobs:
14
16
  strategy:
15
17
  fail-fast: false
16
18
  matrix:
17
- ruby: [ '2.6', '2.5', '2.4' ]
19
+ ruby: [ '2.7', '2.6', '2.5', '2.4' ]
18
20
  os: [ ubuntu-latest, windows-latest, macos-latest ]
19
21
  experimental: [ false ]
20
22
  include:
21
- - ruby: '2.7'
23
+ - ruby: '3.0'
22
24
  os: 'ubuntu-latest'
23
25
  experimental: true
24
- - ruby: '2.7'
26
+ - ruby: '3.0'
25
27
  os: 'windows-latest'
26
28
  experimental: true
27
- - ruby: '2.7'
29
+ - ruby: '3.0'
28
30
  os: 'macos-latest'
29
31
  experimental: true
30
32
  steps:
31
33
  - uses: actions/checkout@master
32
34
 
33
- - name: Use Ruby
34
- uses: ruby/setup-ruby@v1
35
+ - uses: ruby/setup-ruby@v1
35
36
  with:
36
37
  ruby-version: ${{ matrix.ruby }}
37
38
  bundler-cache: true
38
39
 
39
- - name: Update gems
40
- run: bundle install --jobs 4 --retry 3
40
+ - uses: metanorma/metanorma-build-scripts/plantuml-setup-action@master
41
41
 
42
- - name: Install Grpahviz Ubuntu
43
- if: matrix.os == 'ubuntu-latest'
44
- run: sudo apt-get install graphviz
42
+ - run: bundle exec rake
45
43
 
46
- - name: Install Grpahviz macOS
47
- if: matrix.os == 'macos-latest'
48
- run: brew install graphviz
49
-
50
- - name: Install Grpahviz Windows
51
- if: matrix.os == 'windows-latest'
52
- uses: nick-invision/retry@v1
44
+ tests-passed:
45
+ needs: rake
46
+ runs-on: ubuntu-latest
47
+ steps:
48
+ - uses: peter-evans/repository-dispatch@v1
53
49
  with:
54
- polling_interval_seconds: 5
55
- timeout_minutes: 5
56
- max_attempts: 3
57
- command: choco install --no-progress graphviz
58
-
59
- - name: Check dot command
60
- if: matrix.os == 'windows-latest'
61
- run: |
62
- dot -?
63
-
64
- - name: Run specs
65
- run: bundle exec rake
50
+ token: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
51
+ repository: ${{ github.repository }}
52
+ event-type: notify
53
+ client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
data/Dockerfile ADDED
@@ -0,0 +1,4 @@
1
+ FROM ruby:2.6
2
+ COPY . .
3
+ RUN gem install bundler:2.1.4
4
+ RUN bundle install
data/README.adoc CHANGED
@@ -83,6 +83,36 @@ Will produce this output:
83
83
 
84
84
  This macro also supports `.lutaml` files.
85
85
 
86
+ Instead of using the direct path to the file one can use `lutaml-express-index` document attribute to supply directory with express files or yaml index file to parse as well as the cache file location. The syntax is as follows:
87
+
88
+ [source,adoc]
89
+ -----
90
+ :lutaml-express-index: my_custom_name; dir_or_index_path[; cache=cache_path]
91
+ -----
92
+
93
+ Where:
94
+
95
+ * `my_custom_name` - is name of the parsed express files context for the later use with lutaml macro
96
+
97
+ * `dir_or_index_path` - location of directory with express files or path to yaml index file to parse
98
+
99
+ * `cache_path` - optional, location of the expressir cache file to use
100
+
101
+ Example of real usage:
102
+
103
+ [source,adoc]
104
+ -----
105
+ = Document title
106
+ Author
107
+ :lutaml-express-index: my_custom_name; /path/to/express_files; cache=/path/to/cache_file.yaml
108
+ [lutaml,my_custom_name,my_context]
109
+ ----
110
+ {% for schema in my_context.schemas %}
111
+ == {{schema.id}}
112
+ {% endfor %}
113
+ ----
114
+ -----
115
+
86
116
  === Usage, `lutaml_uml_attributes_table` macro
87
117
 
88
118
  This macro allows to quickly render datamodel attributes/values tables. Given `example.lutaml` file with the content:
@@ -76,18 +76,17 @@ module Metanorma
76
76
  file_paths = []
77
77
  result = contexts_names.each_with_object([]) do |path, res|
78
78
  if express_indexes[path]
79
- res.push(*express_indexes[path])
79
+ res.push(express_indexes[path])
80
80
  else
81
81
  file_paths.push(path)
82
82
  end
83
83
  end
84
84
  if !file_paths.empty?
85
- from_files = content_from_files(document, file_paths)
86
- .map do |n|
87
- n.to_liquid.map { |j| j.merge('relative_path_prefix' => Utils.relative_file_path(document, File.dirname(j['file']))) }
88
- end
89
- .flatten
90
- result += from_files
85
+ from_files = content_from_files(document, file_paths).to_liquid
86
+ from_files['schemas'] = from_files['schemas'].map do |n|
87
+ n.merge('relative_path_prefix' => Utils.relative_file_path(document, File.dirname(n['file'])))
88
+ end
89
+ result.push(from_files)
91
90
  end
92
91
  result
93
92
  end
@@ -96,15 +95,20 @@ module Metanorma
96
95
  options = parse_options(block_match[3])
97
96
  contexts_items(block_match, document, express_indexes)
98
97
  .map do |items|
99
- opts = options.merge('relative_path_prefix' => items['relative_path_prefix'])
98
+ if items['schemas']
99
+ items['schemas'] = items['schemas'].map do |j|
100
+ opts = options.merge('relative_path_prefix' => j['relative_path_prefix'])
101
+ decorate_context_items(j, opts)
102
+ end
103
+ end
100
104
  parse_context_block(document: document,
101
105
  context_lines: current_block,
102
- context_items: decorate_context_items(items, opts),
106
+ context_items: items,
103
107
  context_name: block_match[2].strip)
104
108
  end.flatten
105
- # rescue StandardError => e
106
- # document.logger.warn("Failed to parse lutaml block: #{e.message}")
107
- # []
109
+ rescue StandardError => e
110
+ document.logger.warn("Failed to parse lutaml block: #{e.message}")
111
+ []
108
112
  end
109
113
 
110
114
  def parse_options(options_string)
@@ -1,8 +1,12 @@
1
+ require "expressir/express_exp/cache"
2
+
1
3
  module Metanorma
2
4
  module Plugin
3
5
  module Lutaml
4
6
  # Helpers for lutaml macroses
5
7
  module Utils
8
+ LUTAML_EXP_IDX_TAG = /^:lutaml-express-index:(?<index_name>.+?);(?<index_path>.+?);?(\s*cache=(?<cache_path>.+))?$/.freeze
9
+
6
10
  module_function
7
11
 
8
12
  def relative_file_path(document, file_path)
@@ -32,20 +36,75 @@ module Metanorma
32
36
  end
33
37
  end
34
38
 
35
- def process_express_index(folder, name, idxs, document)
36
- idxs[name] = []
37
- Dir["#{Utils.relative_file_path(document, folder)}/*"].each do |path|
38
- next if [".", ".."].include?(path)
39
-
40
- begin
41
- parsed = ::Lutaml::Parser.parse(File.new(path, encoding: "UTF-8"))
42
- parsed = parsed.map { |n| n.to_liquid.map { |j| j.merge('relative_path_prefix' => Utils.relative_file_path(document, File.dirname(j['file']))) } }.flatten
43
- idxs[name]
44
- .push(*parsed)
45
- rescue StandardError => e
46
- document.logger.warn("Failed to load #{path}: #{e.message}")
47
- end
39
+ def process_express_index(path, cache_path, document, force_read = false)
40
+ cache_full_path = Utils.relative_file_path(document, cache_path) if cache_path
41
+ if !force_read && cache_full_path && File.file?(cache_full_path)
42
+ return express_from_cache(cache_full_path)
43
+ end
44
+
45
+ full_path = Utils.relative_file_path(document, path)
46
+ wrapper = express_from_path(document, full_path)
47
+ if cache_full_path && !File.file?(cache_full_path)
48
+ express_write_cache(cache_full_path, wrapper.original_document, document)
49
+ end
50
+ wrapper
51
+ rescue StandardError => e
52
+ document.logger.warn("Failed to load #{full_path}: #{e.message}")
53
+ nil
54
+ rescue Expressir::ExpressExp::CacheLoadError
55
+ process_express_index(path, cache_path, document, true)
56
+ end
57
+
58
+ def express_from_cache(path)
59
+ ::Lutaml::Parser
60
+ .parse(File.new(path), ::Lutaml::Parser::EXPRESS_CACHE_PARSE_TYPE)
61
+ end
62
+
63
+ def express_write_cache(path, repository, document)
64
+ root_path = Pathname.new(relative_file_path(document, ''))
65
+ Expressir::ExpressExp::Cache
66
+ .to_file(path,
67
+ repository,
68
+ root_path: root_path)
69
+ end
70
+
71
+ def express_from_path(document, path)
72
+ if File.directory?(path)
73
+ return express_from_folder(path)
74
+ end
75
+
76
+ express_from_index(document, path)
77
+ end
78
+
79
+ def express_from_folder(folder)
80
+ files = Dir["#{folder}/*.exp"].map { |nested_path| File.new(nested_path, encoding: "UTF-8") }
81
+ ::Lutaml::Parser.parse(files)
82
+ end
83
+
84
+ def express_decorate_wrapper(wrapper, document)
85
+ serialized = wrapper.to_liquid
86
+ serialized['schemas'] = serialized['schemas'].map do |j|
87
+ j.merge('relative_path_prefix' => Utils.relative_file_path(document, File.dirname(j['file'])))
88
+ end
89
+ serialized
90
+ end
91
+
92
+ def express_from_index(document, path)
93
+ yaml_content = YAML.safe_load(File.read(path))
94
+ root_path = yaml_content['path']
95
+ schemas_paths = yaml_content
96
+ .fetch('schemas')
97
+ .map do |(schema_name, schema_values)|
98
+ if schema_values['path']
99
+ schema_values['path']
100
+ else
101
+ File.join(root_path.to_s, "#{schema_name}.exp")
102
+ end
103
+ end
104
+ files_to_load = schemas_paths.map do |path|
105
+ File.new(Utils.relative_file_path(document, path), encoding: "UTF-8")
48
106
  end
107
+ ::Lutaml::Parser.parse(files_to_load)
49
108
  end
50
109
 
51
110
  def parse_document_express_indexes(document, input_lines)
@@ -54,14 +113,15 @@ module Metanorma
54
113
  line = input_lines.next
55
114
  break if line.length.zero?
56
115
 
57
- _, name, folder = line.match(/^:lutaml-express-index:(.+?);(.+?)$/)&.to_a
58
- if folder && name
59
- process_express_index(
60
- folder.strip.gsub(";", ""),
61
- name.strip,
62
- express_indexes,
63
- document
64
- )
116
+ match = line.match(LUTAML_EXP_IDX_TAG)
117
+ if match
118
+ name = match[:index_name]
119
+ path = match[:index_path]
120
+ cache = match[:cache_path]
121
+ repositories = process_express_index(path.strip, cache, document)
122
+ if repositories
123
+ express_indexes[name.strip] = express_decorate_wrapper(repositories, document)
124
+ end
65
125
  end
66
126
  end
67
127
  express_indexes
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.2.5".freeze
4
+ VERSION = "0.3.0".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ["lib"]
25
25
 
26
26
  spec.add_dependency "liquid"
27
- spec.add_dependency "lutaml", "~> 0.4.0"
27
+ spec.add_dependency "lutaml", "~> 0.5.0"
28
28
  spec.add_dependency "lutaml-uml", "~> 0.2.0"
29
29
  spec.add_dependency "metanorma"
30
30
  spec.add_dependency "relaton-cli"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-plugin-lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-08 00:00:00.000000000 Z
11
+ date: 2021-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.0
33
+ version: 0.5.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.4.0
40
+ version: 0.5.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: lutaml-uml
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -244,6 +244,7 @@ files:
244
244
  - ".github/workflows/rake.yml"
245
245
  - ".gitignore"
246
246
  - CODE_OF_CONDUCT.md
247
+ - Dockerfile
247
248
  - Gemfile
248
249
  - LICENSE
249
250
  - README.adoc