expressir 2.1.4 → 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: 6332097442bcc1944b232cb35d7087a77d53b6e5c4c774dfd8858b5e7e844d12
4
- data.tar.gz: ba77289decd02d53fd3af744b2285f4af560b080042024dedffba71a377768cc
3
+ metadata.gz: fbb7fb563aa44a7d916ef48ccd2b5e865ced0776ce36e5c238fddaf3c2dd61ac
4
+ data.tar.gz: 487913925a727a1e20fa4651ffc3a3af669f3ba094655bb232c39dde6b92b4e2
5
5
  SHA512:
6
- metadata.gz: 8570065d318a194afada69883530b4352695c5338dbddec69c3c63859a2352ba0a6c6eaf28dddc3025cdc18ea5e079e1a0cc3d3a35cc87161774912570e70f08
7
- data.tar.gz: 7af0380673d43c089b61f7845a3a4edaf3c824e1533f9703c1e2108fcf339f388fb25e449e34a109168328aedbf5cbddf54023b0b6d919298ba336011cb03ced
6
+ metadata.gz: 979411f7682a574f9743ea7129bbf826d9c11657b97c2a9a95e9e9d066d530b99f95ffc228366f09fc8f86db3ec7596d4870bdab33de55aca094ef6ebef3d7ff
7
+ data.tar.gz: dfd514fdfc7fd31dfddb4886545d2b763b1c53bea7b2eeed9a95b88274953f5996c5f606b180f5a783e5bb32e24a043903101315bc9de0b8d231bf89ac2f38fc
@@ -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.4".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.4
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-12-04 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
@@ -86,6 +86,7 @@ files:
86
86
  - lib/expressir/cli.rb
87
87
  - lib/expressir/config.rb
88
88
  - lib/expressir/express/cache.rb
89
+ - lib/expressir/express/express_remarks_decorator.rb
89
90
  - lib/expressir/express/formatter.rb
90
91
  - lib/expressir/express/hyperlink_formatter.rb
91
92
  - lib/expressir/express/model_visitor.rb