expressir 2.1.3 → 2.1.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: 8748267e0eee4976d8920a39894eb6ecc70439b0c3b54acd224ec2b5511a8726
4
- data.tar.gz: 06f7292f40061e983550ce9761585fe13dc33f2fa3aacda52f9310b6bd2e964c
3
+ metadata.gz: fbb7fb563aa44a7d916ef48ccd2b5e865ced0776ce36e5c238fddaf3c2dd61ac
4
+ data.tar.gz: 487913925a727a1e20fa4651ffc3a3af669f3ba094655bb232c39dde6b92b4e2
5
5
  SHA512:
6
- metadata.gz: b714aac2b8a1ddf5561e45998d06a99b11dec2b45c0403984b4c4c4e245d4d8d39b4166e590d9a0d9e098da41ed6a13525386bc13bea9334e5fbce7295518d74
7
- data.tar.gz: cef3bcbdf1329cd2a9c2f2aaba1c79f1038af1ffb62c8ee97efdf652dc1162aea3152e9348cc3d8c3472c333aeda93d1e438c097b368091cb3f34bdeaf5e580d
6
+ metadata.gz: 979411f7682a574f9743ea7129bbf826d9c11657b97c2a9a95e9e9d066d530b99f95ffc228366f09fc8f86db3ec7596d4870bdab33de55aca094ef6ebef3d7ff
7
+ data.tar.gz: dfd514fdfc7fd31dfddb4886545d2b763b1c53bea7b2eeed9a95b88274953f5996c5f606b180f5a783e5bb32e24a043903101315bc9de0b8d231bf89ac2f38fc
@@ -0,0 +1,48 @@
1
+ name: "validate_schemas"
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ concurrency:
10
+ group: '${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.ref_name }}'
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ schemas:
15
+ name: Validate schemas
16
+ runs-on: ubuntu-latest
17
+ strategy:
18
+ fail-fast: false
19
+ matrix:
20
+ test-group:
21
+ [
22
+ 'iso-10303/schemas-srl.yml',
23
+ 'iso-10303/schemas_module.yml',
24
+ 'iso-10303/schemas_bom.yml',
25
+ ]
26
+
27
+ steps:
28
+ - name: Checkout
29
+ uses: actions/checkout@v4
30
+
31
+ - name: Checkout
32
+ uses: actions/checkout@v4
33
+ with:
34
+ repository: 'metanorma/iso-10303'
35
+ path: iso-10303
36
+ token: ${{ secrets.LUTAML_CI_PAT_TOKEN }}
37
+
38
+ - name: Install Ruby
39
+ uses: ruby/setup-ruby@master
40
+ with:
41
+ ruby-version: 3.2
42
+ bundler-cache: true
43
+ cache-version: 0 # Increment this number if you need to re-download cached gems
44
+
45
+ - name: Validate schemas ${{ matrix.test-group }}
46
+ run: |
47
+ yq '.schemas[].path | sub("schemas", "iso-10303/schemas")' ${{ matrix.test-group }} | xargs bundle exec ./exe/expressir validate
48
+
@@ -37,7 +37,7 @@ module Expressir
37
37
 
38
38
  yaml_compressed = File.binread(file)
39
39
  yaml = Zlib::Inflate.inflate(yaml_compressed)
40
- hash = YAML.safe_load(yaml)
40
+ hash = YAML.safe_load(yaml, permitted_classes: [Symbol])
41
41
  cache = Model::ModelElement.from_hash(hash, root_path: root_path)
42
42
 
43
43
  if cache.version != version
@@ -0,0 +1,76 @@
1
+ module Expressir
2
+ module Express
3
+ class ExpressRemarksDecorator
4
+ RELATIVE_PREFIX_MACRO_REGEXP = /^(link|image|video|audio|include)(:+)?(?![^\/:]+:\/\/|[A-Z]:\/|\/)([^:\[]+)(\[.*\])?$/.freeze
5
+
6
+ attr_reader :remark, :options
7
+
8
+ def self.call(remark, options)
9
+ new(remark, options).call
10
+ end
11
+
12
+ def initialize(remark, options)
13
+ @remark = remark
14
+ @options = options
15
+ end
16
+
17
+ def call
18
+ result = remark
19
+ if options["leveloffset"]
20
+ result = process_remark_offsets(result, options["leveloffset"].to_i)
21
+ end
22
+ if options["relative_path_prefix"]
23
+ result = update_relative_paths(result,
24
+ options["relative_path_prefix"])
25
+ end
26
+ result
27
+ end
28
+
29
+ private
30
+
31
+ def update_relative_paths(string, path_prefix)
32
+ string
33
+ .split("\n")
34
+ .map do |line|
35
+ if line.match?(RELATIVE_PREFIX_MACRO_REGEXP)
36
+ prefix_relative_paths(line, path_prefix)
37
+ else
38
+ line
39
+ end
40
+ end
41
+ .join("\n")
42
+ end
43
+
44
+ def prefix_relative_paths(line, path_prefix)
45
+ line.gsub(RELATIVE_PREFIX_MACRO_REGEXP) do |_match|
46
+ prefixed_path = File.join(path_prefix, $3.strip)
47
+ # When we are dealing with a relative path of a template:
48
+ # ../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}"
53
+ end
54
+ end
55
+
56
+ def process_remark_offsets(string, offset)
57
+ string
58
+ .split("\n")
59
+ .map do |line|
60
+ if line.match?(/^=/)
61
+ set_string_offsets(line, offset)
62
+ else
63
+ line
64
+ end
65
+ end
66
+ .join("\n")
67
+ end
68
+
69
+ def set_string_offsets(string, offset)
70
+ return "#{'=' * offset}#{string}" if offset.positive?
71
+
72
+ string.gsub(/^={#{offset * -1}}/, "")
73
+ end
74
+ end
75
+ end
76
+ end
@@ -6,9 +6,11 @@ module Expressir
6
6
  class SchemaDrop < ::Expressir::Liquid::DeclarationDrop
7
7
  include ::Expressir::Liquid::IdentifierDrop
8
8
 
9
- def initialize(model)
9
+ def initialize(model, selected_schemas: nil, options: {}) # rubocop:disable Lint/MissingSuper
10
10
  @model = model
11
- initialize_identifier(@model)
11
+ @selected_schemas = selected_schemas
12
+ @options = options
13
+ initialize_identifier(@model, @options)
12
14
  super
13
15
  end
14
16
 
@@ -16,6 +18,40 @@ module Expressir
16
18
  @model.file
17
19
  end
18
20
 
21
+ def file_basename
22
+ File.basename(@model.file, ".exp")
23
+ end
24
+
25
+ def selected
26
+ @selected_schemas&.include?(@model.id) ||
27
+ @selected_schemas&.include?(file_basename)
28
+ end
29
+
30
+ def relative_path_prefix
31
+ return nil if @options.nil? || @options["document"].nil?
32
+
33
+ document = @options["document"]
34
+ file_path = File.dirname(@model.file)
35
+ docfile_directory = File.dirname(
36
+ document.attributes["docfile"] || ".",
37
+ )
38
+ document
39
+ .path_resolver
40
+ .system_path(file_path, docfile_directory)
41
+ end
42
+
43
+ def remarks
44
+ return [] unless @model.remarks
45
+
46
+ options = @options || {}
47
+ options["relative_path_prefix"] = relative_path_prefix
48
+
49
+ @model.remarks.map do |remark|
50
+ ::Expressir::Express::ExpressRemarksDecorator
51
+ .call(remark, options)
52
+ end
53
+ end
54
+
19
55
  def version
20
56
  ::Expressir::Liquid::Declarations::SchemaVersionDrop.new(
21
57
  @model.version,
@@ -5,8 +5,9 @@ require_relative "declarations/remark_item_drop"
5
5
  module Expressir
6
6
  module Liquid
7
7
  module IdentifierDrop
8
- def initialize_identifier(model)
8
+ def initialize_identifier(model, options = {})
9
9
  @model = model
10
+ @options = options
10
11
  end
11
12
 
12
13
  def id
@@ -3,8 +3,10 @@
3
3
  module Expressir
4
4
  module Liquid
5
5
  class ModelElementDrop < ::Liquid::Drop
6
- def initialize(model) # rubocop:disable Lint/MissingSuper
6
+ def initialize(model, selected_schemas: nil, options: {}) # rubocop:disable Lint/MissingSuper
7
7
  @model = model
8
+ @selected_schemas = selected_schemas
9
+ @options = options
8
10
  end
9
11
 
10
12
  def _class
@@ -5,8 +5,10 @@ require_relative "declarations/schema_drop"
5
5
  module Expressir
6
6
  module Liquid
7
7
  class RepositoryDrop < ::Expressir::Liquid::ModelElementDrop
8
- def initialize(model)
8
+ def initialize(model, selected_schemas: nil, options: {}) # rubocop:disable Lint/MissingSuper
9
9
  @model = model
10
+ @selected_schemas = selected_schemas
11
+ @options = options
10
12
  super
11
13
  end
12
14
 
@@ -14,7 +16,11 @@ module Expressir
14
16
  return [] unless @model.schemas
15
17
 
16
18
  @model.schemas.map do |item|
17
- ::Expressir::Liquid::Declarations::SchemaDrop.new(item)
19
+ ::Expressir::Liquid::Declarations::SchemaDrop.new(
20
+ item,
21
+ selected_schemas: @selected_schemas,
22
+ options: @options,
23
+ )
18
24
  end
19
25
  end
20
26
  end
@@ -151,10 +151,10 @@ module Expressir
151
151
  end
152
152
 
153
153
  # @return [Liquid::Drop]
154
- def to_liquid
154
+ def to_liquid(selected_schemas: nil, options: nil)
155
155
  klass_name = "#{self.class.name.gsub('::Model::', '::Liquid::')}Drop"
156
156
  klass = Object.const_get(klass_name)
157
- klass.new(self)
157
+ klass.new(self, selected_schemas: selected_schemas, options: options)
158
158
  end
159
159
 
160
160
  def to_s(no_remarks: false, formatter: nil)
@@ -1,3 +1,3 @@
1
1
  module Expressir
2
- VERSION = "2.1.3".freeze
2
+ VERSION = "2.1.5".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressir
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.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: 2024-11-29 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -64,6 +64,7 @@ files:
64
64
  - ".github/workflows/rake.yml"
65
65
  - ".github/workflows/release.yml"
66
66
  - ".github/workflows/stress.yml"
67
+ - ".github/workflows/validate_schemas.yml"
67
68
  - ".gitignore"
68
69
  - ".hound.yml"
69
70
  - ".rspec"
@@ -85,6 +86,7 @@ files:
85
86
  - lib/expressir/cli.rb
86
87
  - lib/expressir/config.rb
87
88
  - lib/expressir/express/cache.rb
89
+ - lib/expressir/express/express_remarks_decorator.rb
88
90
  - lib/expressir/express/formatter.rb
89
91
  - lib/expressir/express/hyperlink_formatter.rb
90
92
  - lib/expressir/express/model_visitor.rb