metanorma-plugin-lutaml 0.2.4.pre.alpha.1 → 0.2.5

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: 3d9bb01b3f5a13668f541d4119e0830655c524be8bcfa9414b41004b2f6fbcc4
4
- data.tar.gz: a2851e63eece312d2b529aa3fe68de9fffa794768ab1e15a0eec97b86ca9c9f3
3
+ metadata.gz: 720c7f46803fd6650d13e51e6b1e5111a09c9cf3773c832e239020a8ea5cee75
4
+ data.tar.gz: d349fbb9970f16e8bbcf1396d71ec628b7cdbf0204dcdb50d14db8ba2727b0c2
5
5
  SHA512:
6
- metadata.gz: 1dd880cc2ac6829e851ad8165150af8905f8a558fda49e610a03af6c720d592c25695c135b3acc4c6be415a76c402060a7813b1783f6e3f8a6d0c580a53d4a63
7
- data.tar.gz: d78b7da3aad28bda7f8b2a1a891ca885068fe4b3261ad684a33e53afc83a5812a4bc13c30d7ef8ca34a0e3d6cc72a1482971ec63a5cec12b28283631cd455cc2
6
+ metadata.gz: 4a855cb5d2c1d7fa9878e0213c6e4ad53381afdaae8ac8cfaed1ed590c8b4a8d9784f12e148888a840c3829913d9a8ab4b0b1715339cade1320d8cfecb8f547c
7
+ data.tar.gz: 0dc60a360f2416481d42c369eb12fd4c73f7833b4904255117bfa1c787accbc58e5de74f29488d9c4456908497bd60ccc680788c1f78c324fcaaa955b6e0449d
@@ -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
 
@@ -45,7 +45,11 @@ module Metanorma
45
45
  def prefix_relative_paths(line, path_prefix)
46
46
  line.gsub(RELATIVE_PREFIX_MACRO_REGEXP) do |_match|
47
47
  prefixed_path = File.join(path_prefix, $3.strip)
48
- "#{$1}#{$2}#{prefixed_path}#{$4}"
48
+ # When we are dealing with arelative path of a template: ../path/to/file we need to transform it into
49
+ # the absolute one because `image::` macro wont understand it other way
50
+ prefixed_path = File.absolute_path(prefixed_path) if prefixed_path.start_with?('../')
51
+ full_path = File.expand_path(prefixed_path)
52
+ "#{$1}#{$2}#{full_path}#{$4}"
49
53
  end
50
54
  end
51
55
 
@@ -27,10 +27,11 @@ module Metanorma
27
27
 
28
28
  protected
29
29
 
30
- def content_from_file(document, file_path)
31
- ::Lutaml::Parser
32
- .parse(File.new(Utils.relative_file_path(document, file_path),
33
- encoding: "UTF-8"))
30
+ def content_from_files(document, file_paths)
31
+ file_list = file_paths.map do |file_path|
32
+ File.new(Utils.relative_file_path(document, file_path), encoding: "UTF-8")
33
+ end
34
+ ::Lutaml::Parser.parse(file_list)
34
35
  end
35
36
 
36
37
  private
@@ -72,28 +73,38 @@ module Metanorma
72
73
 
73
74
  def contexts_items(block_match, document, express_indexes)
74
75
  contexts_names = block_match[1].split(";").map(&:strip)
75
- contexts_names.each_with_object([]) do |path, res|
76
+ file_paths = []
77
+ result = contexts_names.each_with_object([]) do |path, res|
76
78
  if express_indexes[path]
77
79
  res.push(*express_indexes[path])
78
80
  else
79
- res.push(content_from_file(document, path).to_liquid)
81
+ file_paths.push(path)
80
82
  end
81
83
  end
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
91
+ end
92
+ result
82
93
  end
83
94
 
84
95
  def parse_template(document, current_block, block_match, express_indexes)
85
96
  options = parse_options(block_match[3])
86
- .merge("relative_path_prefix" => File.dirname(block_match[1]))
87
97
  contexts_items(block_match, document, express_indexes)
88
- .map do |context_items|
98
+ .map do |items|
99
+ opts = options.merge('relative_path_prefix' => items['relative_path_prefix'])
89
100
  parse_context_block(document: document,
90
101
  context_lines: current_block,
91
- context_items: decorate_context_items(context_items, options),
102
+ context_items: decorate_context_items(items, opts),
92
103
  context_name: block_match[2].strip)
93
104
  end.flatten
94
- rescue StandardError => e
95
- document.logger.warn("Failed to parse lutaml block: #{e.message}")
96
- []
105
+ # rescue StandardError => e
106
+ # document.logger.warn("Failed to parse lutaml block: #{e.message}")
107
+ # []
97
108
  end
98
109
 
99
110
  def parse_options(options_string)
@@ -29,6 +29,7 @@ module Metanorma
29
29
  ::Lutaml::Parser
30
30
  .parse(File.new(Utils.relative_file_path(document, file_path),
31
31
  encoding: "UTF-8"))
32
+ .first
32
33
  end
33
34
 
34
35
  def processed_lines(document, input_lines)
@@ -38,8 +38,10 @@ module Metanorma
38
38
  next if [".", ".."].include?(path)
39
39
 
40
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
41
43
  idxs[name]
42
- .push(::Lutaml::Parser.parse(File.new(path, encoding: "UTF-8")).to_liquid)
44
+ .push(*parsed)
43
45
  rescue StandardError => e
44
46
  document.logger.warn("Failed to load #{path}: #{e.message}")
45
47
  end
@@ -1,7 +1,7 @@
1
1
  module Metanorma
2
2
  module Plugin
3
3
  module Lutaml
4
- VERSION = "0.2.4-alpha.1".freeze
4
+ VERSION = "0.2.5".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.1.pre.alpha.1"
27
+ spec.add_dependency "lutaml", "~> 0.4.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.4.pre.alpha.1
4
+ version: 0.2.5
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-09 00:00:00.000000000 Z
11
+ date: 2021-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -28,16 +28,16 @@ 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.1
33
+ version: 0.4.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.1
40
+ version: 0.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: lutaml-uml
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -274,9 +274,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
274
274
  version: '0'
275
275
  required_rubygems_version: !ruby/object:Gem::Requirement
276
276
  requirements:
277
- - - ">"
277
+ - - ">="
278
278
  - !ruby/object:Gem::Version
279
- version: 1.3.1
279
+ version: '0'
280
280
  requirements: []
281
281
  rubygems_version: 3.0.3
282
282
  signing_key: