metanorma-plugin-lutaml 0.2.4 → 0.4.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: fedcbe218c7a2e414eeac2dff54a798c0fcb2df287f8c516c81cb2cf8484848b
4
- data.tar.gz: 343ba55ae29367376bae9c0175698fe241e8d2c533d420d0becab9cc2f1fdfe9
3
+ metadata.gz: a69cd9fc268fc930ee6a904fded7ff1b9a8e8bc9d168692723a8e288c153a1b9
4
+ data.tar.gz: e0c0f656845153953ea5b157a896a2c080701bd4201807bd588b98813aa5a408
5
5
  SHA512:
6
- metadata.gz: 38554d8cef5c12bb9650bbbbf270be3f34f4f4672868a6625966fc2c356bd686bb8e0b585cd9cb466acdc765abc7facce5ef6752ba632014910f1c7f0bc333b1
7
- data.tar.gz: 46a0bd0c726fdb101783b376a79b633db26ece0b10272d934f4a349a62e8d4f99d5fe881728ed1713599d9e33dcc706ddfcd51205708a4762a1f44f1e236fbeb
6
+ metadata.gz: 47ae06e3671be20040af10541394b7876be02fa955dbecd8eab8983b2350fa12e62b1375276e3ff48671b0e38bc91bc8b7c758cdb6cc162d7fa4c35a6a665288
7
+ data.tar.gz: da04ecfba6f48f522294d733e6b16d0199657130c69f6407e77c702b8f94dceda641c528d323987f5b3e61b90ace50963e878c48c7f3aa6dda83313fd378e0d2
@@ -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/Makefile ADDED
@@ -0,0 +1,2 @@
1
+ fix-lint-staged:
2
+ git status --short | egrep '^(A|M)' | awk '{ print $$2}' | grep -v db/schema.rb | xargs bundle exec rubocop -a
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:
@@ -0,0 +1,15 @@
1
+ require "reverse_adoc"
2
+
3
+ module Metanorma
4
+ module Plugin
5
+ module Lutaml
6
+ module Liquid
7
+ module CustomFilters
8
+ def html2adoc(input)
9
+ ReverseAdoc.convert(input)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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)
@@ -144,7 +154,8 @@ module Metanorma
144
154
  render_result, errors = Utils.render_liquid_string(
145
155
  template_string: context_lines.join("\n"),
146
156
  context_items: context_items,
147
- context_name: context_name
157
+ context_name: context_name,
158
+ document: document
148
159
  )
149
160
  Utils.notify_render_errors(document, errors)
150
161
  render_result.split("\n")
@@ -60,7 +60,8 @@ module Metanorma
60
60
  render_result, errors = Utils.render_liquid_string(
61
61
  template_string: table_template,
62
62
  context_items: entity_definition,
63
- context_name: "definition"
63
+ context_name: "definition",
64
+ document: document
64
65
  )
65
66
  Utils.notify_render_errors(document, errors)
66
67
  render_result.split("\n")
@@ -1,8 +1,15 @@
1
+ require "expressir/express/cache"
2
+ require "metanorma/plugin/lutaml/liquid/custom_filters"
3
+
4
+ ::Liquid::Template.register_filter(Metanorma::Plugin::Lutaml::Liquid::CustomFilters)
5
+
1
6
  module Metanorma
2
7
  module Plugin
3
8
  module Lutaml
4
9
  # Helpers for lutaml macroses
5
10
  module Utils
11
+ LUTAML_EXP_IDX_TAG = /^:lutaml-express-index:(?<index_name>.+?);(?<index_path>.+?);?(\s*cache=(?<cache_path>.+))?$/.freeze
12
+
6
13
  module_function
7
14
 
8
15
  def relative_file_path(document, file_path)
@@ -15,8 +22,10 @@ module Metanorma
15
22
  end
16
23
 
17
24
  def render_liquid_string(template_string:, context_items:,
18
- context_name:)
19
- liquid_template = Liquid::Template.parse(template_string)
25
+ context_name:, document:)
26
+ liquid_template = ::Liquid::Template.parse(template_string)
27
+ # Allow includes for the template
28
+ liquid_template.registers[:file_system] = ::Liquid::LocalFileSystem.new(Utils.relative_file_path(document, ""))
20
29
  rendered_string = liquid_template
21
30
  .render(context_name => context_items,
22
31
  strict_variables: true,
@@ -32,20 +41,76 @@ module Metanorma
32
41
  end
33
42
  end
34
43
 
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}")
44
+ def process_express_index(path, cache_path, document, force_read = false)
45
+ cache_full_path = Utils.relative_file_path(document, cache_path) if cache_path
46
+ if !force_read && cache_full_path && File.file?(cache_full_path)
47
+ return express_from_cache(cache_full_path)
48
+ end
49
+
50
+ full_path = Utils.relative_file_path(document, path)
51
+ wrapper = express_from_path(document, full_path)
52
+ if cache_full_path && !File.file?(cache_full_path)
53
+ express_write_cache(cache_full_path, wrapper.original_document, document)
54
+ end
55
+ wrapper
56
+ rescue Expressir::Error
57
+ FileUtils.rm_rf(cache_full_path)
58
+ process_express_index(path, cache_path, document, true)
59
+ rescue StandardError => e
60
+ document.logger.warn("Failed to load #{full_path}: #{e.message}")
61
+ nil
62
+ end
63
+
64
+ def express_from_cache(path)
65
+ ::Lutaml::Parser
66
+ .parse(File.new(path), ::Lutaml::Parser::EXPRESS_CACHE_PARSE_TYPE)
67
+ end
68
+
69
+ def express_write_cache(path, repository, document)
70
+ root_path = Pathname.new(relative_file_path(document, ""))
71
+ Expressir::Express::Cache
72
+ .to_file(path,
73
+ repository,
74
+ root_path: root_path)
75
+ end
76
+
77
+ def express_from_path(document, path)
78
+ if File.directory?(path)
79
+ return express_from_folder(path)
80
+ end
81
+
82
+ express_from_index(document, path)
83
+ end
84
+
85
+ def express_from_folder(folder)
86
+ files = Dir["#{folder}/*.exp"].map { |nested_path| File.new(nested_path, encoding: "UTF-8") }
87
+ ::Lutaml::Parser.parse(files)
88
+ end
89
+
90
+ def express_decorate_wrapper(wrapper, document)
91
+ serialized = wrapper.to_liquid
92
+ serialized["schemas"] = serialized["schemas"].map do |j|
93
+ j.merge("relative_path_prefix" => Utils.relative_file_path(document, File.dirname(j["file"])))
94
+ end
95
+ serialized
96
+ end
97
+
98
+ def express_from_index(document, path)
99
+ yaml_content = YAML.safe_load(File.read(path))
100
+ root_path = yaml_content["path"]
101
+ schemas_paths = yaml_content
102
+ .fetch("schemas")
103
+ .map do |(schema_name, schema_values)|
104
+ if schema_values["path"]
105
+ schema_values["path"]
106
+ else
107
+ File.join(root_path.to_s, "#{schema_name}.exp")
47
108
  end
48
109
  end
110
+ files_to_load = schemas_paths.map do |path|
111
+ File.new(Utils.relative_file_path(document, path), encoding: "UTF-8")
112
+ end
113
+ ::Lutaml::Parser.parse(files_to_load)
49
114
  end
50
115
 
51
116
  def parse_document_express_indexes(document, input_lines)
@@ -54,14 +119,15 @@ module Metanorma
54
119
  line = input_lines.next
55
120
  break if line.length.zero?
56
121
 
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
- )
122
+ match = line.match(LUTAML_EXP_IDX_TAG)
123
+ if match
124
+ name = match[:index_name]
125
+ path = match[:index_path]
126
+ cache = match[:cache_path]
127
+ repositories = process_express_index(path.strip, cache, document)
128
+ if repositories
129
+ express_indexes[name.strip] = express_decorate_wrapper(repositories, document)
130
+ end
65
131
  end
66
132
  end
67
133
  express_indexes
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.2.4".freeze
4
+ VERSION = "0.4.0".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -24,10 +24,10 @@ 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"
30
+ spec.add_dependency "reverse_adoc"
31
31
 
32
32
  spec.add_development_dependency "byebug"
33
33
  spec.add_development_dependency "equivalent-xml"
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
4
+ version: 0.4.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-05 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -28,32 +28,32 @@ dependencies:
28
28
  name: lutaml
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.1.pre.alpha.2
33
+ version: '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.1.pre.alpha.2
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: lutaml-uml
42
+ name: metanorma
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.0
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.2.0
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: metanorma
56
+ name: relaton-cli
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: relaton-cli
70
+ name: reverse_adoc
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -244,14 +244,17 @@ files:
244
244
  - ".github/workflows/rake.yml"
245
245
  - ".gitignore"
246
246
  - CODE_OF_CONDUCT.md
247
+ - Dockerfile
247
248
  - Gemfile
248
249
  - LICENSE
250
+ - Makefile
249
251
  - README.adoc
250
252
  - Rakefile
251
253
  - bin/console
252
254
  - bin/setup
253
255
  - lib/metanorma-plugin-lutaml.rb
254
256
  - lib/metanorma/plugin/lutaml/express_remarks_decorator.rb
257
+ - lib/metanorma/plugin/lutaml/liquid/custom_filters.rb
255
258
  - lib/metanorma/plugin/lutaml/lutaml_diagram_block.rb
256
259
  - lib/metanorma/plugin/lutaml/lutaml_preprocessor.rb
257
260
  - lib/metanorma/plugin/lutaml/lutaml_uml_attributes_table_preprocessor.rb