metanorma-plugin-lutaml 0.2.4.pre.alpha.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15b69c1b6c78145b90da125ebc64ef043c4ebc88912708ef3183581548e12a1d
4
- data.tar.gz: e8c607b6654b776d8363d439265db8c8efafce0453d0992e81699ba1273d7fd8
3
+ metadata.gz: 9fb3bd82b6d23d6684bd1ca4793eb9d423dbe8132bf9e303bf5be17369fbd9e3
4
+ data.tar.gz: 9112fcf75f2cf32ac4f18e4e6dc0b7ef5385b247ca7293fafb9dd0d9185a4c0c
5
5
  SHA512:
6
- metadata.gz: 2e2b41a80e0058e29ab19bc4cc5957fc821f50d49d3408d27593f4abb62638eb5799dbd4190bbb6f56cdd226ecd96bb95ca2e334907a575850e01f1889e7382b
7
- data.tar.gz: e2da2ed10903ce9561135f006a0e5cab90c18c3683b5fd24c71e0bb0b85a6f2f07a5890c6b9ab790d1cdc7b23e27e57c5b35f83158592de32abb72789b4bf608
6
+ metadata.gz: e71b2f2667ad1f77bedcdd7459ff3b4ef19889a625cd14573741e855f6b97a1910f2a35198190f397f0158a23f9a49f24daaadb2ecc86bc59e948245c5e515f9
7
+ data.tar.gz: 253186ae00898321c291cdca4f5c5f118fff2072845977540cefaeb1b55a7bc326cba50649a1481e8b90e8565ce76df129d280ccbdf045c5336b5a9a921c9254
@@ -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:
@@ -2,7 +2,7 @@ module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
4
  class ExpressRemarksDecorator
5
- RELATIVE_PREFIX_MACRO_REGEXP = /^(\* <<express.+?>>;|link|image|video|audio|include)(:+)?(?![^\/:]+:\/\/|[A-Z]:\/|\/)([^:\[]+)(\[.*\])?$/.freeze
5
+ RELATIVE_PREFIX_MACRO_REGEXP = /^(link|image|video|audio|include)(:+)?(?![^\/:]+:\/\/|[A-Z]:\/|\/)([^:\[]+)(\[.*\])?$/.freeze
6
6
 
7
7
  attr_reader :remark, :options
8
8
 
@@ -76,18 +76,23 @@ 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
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
86
+ # TODO: decide how to handle expressir multiply file parse as one object and lutaml
87
+ if from_files.is_a?(Array)
88
+ result.push(*from_files.map(&:to_liquid))
89
+ else
90
+ from_files = from_files.to_liquid
91
+ from_files['schemas'] = from_files['schemas'].map do |n|
92
+ n.merge('relative_path_prefix' => Utils.relative_file_path(document, File.dirname(n['file'])))
93
+ end
94
+ result.push(from_files)
95
+ end
91
96
  end
92
97
  result
93
98
  end
@@ -96,15 +101,20 @@ module Metanorma
96
101
  options = parse_options(block_match[3])
97
102
  contexts_items(block_match, document, express_indexes)
98
103
  .map do |items|
99
- opts = options.merge('relative_path_prefix' => items['relative_path_prefix'])
104
+ if items['schemas']
105
+ items['schemas'] = items['schemas'].map do |j|
106
+ opts = options.merge('relative_path_prefix' => j['relative_path_prefix'])
107
+ decorate_context_items(j, opts)
108
+ end
109
+ end
100
110
  parse_context_block(document: document,
101
111
  context_lines: current_block,
102
- context_items: decorate_context_items(items, opts),
112
+ context_items: items,
103
113
  context_name: block_match[2].strip)
104
114
  end.flatten
105
- # rescue StandardError => e
106
- # document.logger.warn("Failed to parse lutaml block: #{e.message}")
107
- # []
115
+ rescue StandardError => e
116
+ document.logger.warn("Failed to parse lutaml block: #{e.message}")
117
+ []
108
118
  end
109
119
 
110
120
  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,76 @@ 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 Expressir::ExpressExp::CacheLoadError
52
+ FileUtils.rm_rf(cache_full_path)
53
+ process_express_index(path, cache_path, document, true)
54
+ rescue StandardError => e
55
+ document.logger.warn("Failed to load #{full_path}: #{e.message}")
56
+ nil
57
+ end
58
+
59
+ def express_from_cache(path)
60
+ ::Lutaml::Parser
61
+ .parse(File.new(path), ::Lutaml::Parser::EXPRESS_CACHE_PARSE_TYPE)
62
+ end
63
+
64
+ def express_write_cache(path, repository, document)
65
+ root_path = Pathname.new(relative_file_path(document, ''))
66
+ Expressir::ExpressExp::Cache
67
+ .to_file(path,
68
+ repository,
69
+ root_path: root_path)
70
+ end
71
+
72
+ def express_from_path(document, path)
73
+ if File.directory?(path)
74
+ return express_from_folder(path)
75
+ end
76
+
77
+ express_from_index(document, path)
78
+ end
79
+
80
+ def express_from_folder(folder)
81
+ files = Dir["#{folder}/*.exp"].map { |nested_path| File.new(nested_path, encoding: "UTF-8") }
82
+ ::Lutaml::Parser.parse(files)
83
+ end
84
+
85
+ def express_decorate_wrapper(wrapper, document)
86
+ serialized = wrapper.to_liquid
87
+ serialized['schemas'] = serialized['schemas'].map do |j|
88
+ j.merge('relative_path_prefix' => Utils.relative_file_path(document, File.dirname(j['file'])))
89
+ end
90
+ serialized
91
+ end
92
+
93
+ def express_from_index(document, path)
94
+ yaml_content = YAML.safe_load(File.read(path))
95
+ root_path = yaml_content['path']
96
+ schemas_paths = yaml_content
97
+ .fetch('schemas')
98
+ .map do |(schema_name, schema_values)|
99
+ if schema_values['path']
100
+ schema_values['path']
101
+ else
102
+ File.join(root_path.to_s, "#{schema_name}.exp")
103
+ end
104
+ end
105
+ files_to_load = schemas_paths.map do |path|
106
+ File.new(Utils.relative_file_path(document, path), encoding: "UTF-8")
48
107
  end
108
+ ::Lutaml::Parser.parse(files_to_load)
49
109
  end
50
110
 
51
111
  def parse_document_express_indexes(document, input_lines)
@@ -54,14 +114,15 @@ module Metanorma
54
114
  line = input_lines.next
55
115
  break if line.length.zero?
56
116
 
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
- )
117
+ match = line.match(LUTAML_EXP_IDX_TAG)
118
+ if match
119
+ name = match[:index_name]
120
+ path = match[:index_path]
121
+ cache = match[:cache_path]
122
+ repositories = process_express_index(path.strip, cache, document)
123
+ if repositories
124
+ express_indexes[name.strip] = express_decorate_wrapper(repositories, document)
125
+ end
65
126
  end
66
127
  end
67
128
  express_indexes
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.2.4-alpha.3".freeze
4
+ VERSION = "0.3.1".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -24,8 +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.1.pre.alpha.2"
28
- spec.add_dependency "lutaml-uml", "~> 0.2.0"
27
+ spec.add_dependency "lutaml"
29
28
  spec.add_dependency "metanorma"
30
29
  spec.add_dependency "relaton-cli"
31
30
 
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.4.pre.alpha.3
4
+ version: 0.3.1
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-02-26 00:00:00.000000000 Z
11
+ date: 2021-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -28,30 +28,16 @@ dependencies:
28
28
  name: lutaml
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 0.4.1.pre.alpha.2
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 0.4.1.pre.alpha.2
41
- - !ruby/object:Gem::Dependency
42
- name: lutaml-uml
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: 0.2.0
33
+ version: '0'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: 0.2.0
40
+ version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: metanorma
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -244,6 +230,7 @@ files:
244
230
  - ".github/workflows/rake.yml"
245
231
  - ".gitignore"
246
232
  - CODE_OF_CONDUCT.md
233
+ - Dockerfile
247
234
  - Gemfile
248
235
  - LICENSE
249
236
  - README.adoc
@@ -274,9 +261,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
274
261
  version: '0'
275
262
  required_rubygems_version: !ruby/object:Gem::Requirement
276
263
  requirements:
277
- - - ">"
264
+ - - ">="
278
265
  - !ruby/object:Gem::Version
279
- version: 1.3.1
266
+ version: '0'
280
267
  requirements: []
281
268
  rubygems_version: 3.0.3
282
269
  signing_key: