asciidoctor-defmastership 1.0.5 → 1.0.6

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: 0425e34011a043292dc14256c4649ec16f0bdade8f2a746e586c3011dc4ad1fc
4
- data.tar.gz: c30c83e7c430f0b20889011ef5fd8b8fa5ff21419cd48dfef7f8be0302ca7832
3
+ metadata.gz: f825b6fb724d99888fe587ad2dbe429a7f97c2290326290dcbaabaadff69e3f9
4
+ data.tar.gz: 4e8f7f867972f71d64a2c9136c7ec8089dbf285136450b05bceb748c252495a4
5
5
  SHA512:
6
- metadata.gz: 8084b8fbe8836c2bcd30b8b9afc754879f53341d7b117234183be59dcdab6c6d87e5fef7f534b673f9f13283f6e4f398decd341c4c6cc185b138ee35134f118c
7
- data.tar.gz: '0869b435d1224cab6ffe0637b87bedf6f9080e991b9382331d72e2238270eaa7b286997a071fc161f54249794e0afd9d8eb91b94d1f288cc654501934db1c159'
6
+ metadata.gz: 79733c6918d4388c0b29e04cdecbe86bb997feb247542a912da88cef9b7cf11bf6a617b140ad8f7ba55291e33eda64589c7f252f91f3c0e9aec1dccf8f67ca5d
7
+ data.tar.gz: f427abf34766580362e79846e152a96365b44eb2de3ba2712d66fc80e3dff1c991a5c42268613d9e7cb3c9841b541dbb4d253769f5bc986af98f6efb881ad38a
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.csv
14
14
  *.gem
15
15
  /Gemfile.lock
16
+ /.ruby-version
data/.gitlab-ci.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  default:
2
- image: ruby:2.5
2
+ image: ruby:3.2
3
3
  before_script:
4
4
  - apt-get update
5
5
  - ruby -v
@@ -7,10 +7,25 @@ default:
7
7
  - gem install bundler --no-document
8
8
  - bundle install --jobs $(nproc) "${FLAGS[@]}"
9
9
 
10
- rspec:
10
+ unit tests:
11
11
  script:
12
12
  - bundle exec rake spec
13
13
 
14
14
  rubocop:
15
15
  script:
16
16
  - bundle exec rake rubocop
17
+
18
+ unit tests ruby2.7:
19
+ image: ruby:2.7
20
+ script:
21
+ - bundle exec rake spec
22
+
23
+ unit tests ruby3.0:
24
+ image: ruby:3.0
25
+ script:
26
+ - bundle exec rake spec
27
+
28
+ unit tests ruby3.1:
29
+ image: ruby:3.1
30
+ script:
31
+ - bundle exec rake spec
data/.rubocop.yml CHANGED
@@ -10,26 +10,30 @@
10
10
  # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
11
11
 
12
12
  require:
13
+ - rubocop-performance
13
14
  - rubocop-rspec
15
+ - rubocop-rake
14
16
 
15
17
  AllCops:
16
- TargetRubyVersion: 2.5
18
+ TargetRubyVersion: 2.7
17
19
  EnabledByDefault: true
18
20
  DisplayCopNames: true
19
21
 
20
22
  Style/Copyright:
21
23
  Enabled: true
22
- Notice: 'Copyright (\(c\) )?2020 Jerome Arbez-Gindre'
24
+ Notice: 'Copyright (\(c\) )?202[0-9] Jerome Arbez-Gindre'
23
25
  AutocorrectNotice: '# Copyright (c) 2020 Jerome Arbez-Gindre'
24
26
 
25
- Lint/ConstantResolution:
27
+ Lint/ConstantResolution: # Not available ins rubocop 0.81
26
28
  Enabled: false
27
29
 
28
- # Style/DocumentationMethod:
29
- # Enabled: false
30
+ Style/DocumentationMethod:
31
+ Enabled: false
30
32
 
31
- # Style/StringHashKeys :
32
- # Enabled: false
33
+ Style/StringHashKeys :
34
+ Enabled: true
35
+ Exclude:
36
+ - '*.gemspec'
33
37
 
34
38
  Style/MissingElse:
35
39
  EnforcedStyle: case
@@ -43,9 +47,9 @@ Metrics/BlockLength :
43
47
  - 'spec/**/*'
44
48
  - '*.gemspec'
45
49
 
46
- # Security/Eval :
47
- # Exclude:
48
- # - 'Rakefile'
50
+ Security/Eval :
51
+ Exclude:
52
+ - 'Rakefile'
49
53
 
50
54
  Style/ConstantVisibility :
51
55
  Exclude:
@@ -53,15 +57,15 @@ Style/ConstantVisibility :
53
57
  # constants
54
58
  - 'lib/asciidoctor/defmastership/extension.rb'
55
59
 
56
- # # rubocop-rspec options
57
- # RSpec/MessageExpectation :
58
- # Enabled: false
60
+ # rubocop-rspec options
61
+ RSpec/MessageExpectation :
62
+ Enabled: true
59
63
 
60
64
  RSpec/FilePath :
61
- Enabled: false
65
+ Enabled: true
62
66
 
63
- # RSpec/NestedGroups:
64
- # Max: 4
67
+ RSpec/NestedGroups:
68
+ Max: 4
65
69
 
66
70
  Layout/RedundantLineBreak:
67
71
  Enabled: false
@@ -69,3 +73,7 @@ Layout/RedundantLineBreak:
69
73
  Style/DisableCopsWithinSourceCodeDirective:
70
74
  Enabled: true
71
75
  AllowedCops: ['Lint/InterpolationCheck']
76
+
77
+ Layout/EndOfLine:
78
+ EnforcedStyle: lf
79
+
data/Gemfile CHANGED
@@ -3,3 +3,18 @@
3
3
 
4
4
  source('https://rubygems.org')
5
5
  gemspec
6
+
7
+ # to parse provided Rakefile
8
+ gem 'rake', '~> 13'
9
+ # tdd
10
+ gem 'rspec', '~> 3'
11
+ # code need to be clean
12
+ gem 'rubocop', '1.54'
13
+ # code need to be clean
14
+ gem 'rubocop-performance', '~> 1.18'
15
+ # Rakile needs to be clean
16
+ gem 'rubocop-rake', '~> 0.6'
17
+ # unit tests need to be clean
18
+ gem 'rubocop-rspec', '~> 2.22'
19
+ # What is tdd without code coverage ?
20
+ gem 'simplecov', '~> 0'
data/Rakefile CHANGED
@@ -7,6 +7,10 @@ require('rspec/core/rake_task')
7
7
  RSpec::Core::RakeTask.new(:spec)
8
8
  require('rubocop/rake_task')
9
9
 
10
- ::RuboCop::RakeTask.new
10
+ RuboCop::RakeTask.new do |task|
11
+ task.requires << 'rubocop-performance'
12
+ task.requires << 'rubocop-rspec'
13
+ task.requires << 'rubocop-rake'
14
+ end
11
15
 
12
- task(default: %i[spec rubocop])
16
+ task(default: %i[rubocop spec])
@@ -6,7 +6,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
  require('asciidoctor/defmastership/version')
7
7
 
8
8
  Gem::Specification.new do |spec|
9
- spec.required_ruby_version = '>= 2.5'
9
+ spec.metadata = {
10
+ 'rubygems_mfa_required' => 'true'
11
+ }
12
+
13
+ spec.required_ruby_version = '>= 2.7'
10
14
  spec.name = 'asciidoctor-defmastership'
11
15
  spec.version = Asciidoctor::DefMastership::VERSION
12
16
  spec.authors = ['Jérôme Arbez-Gindre']
@@ -33,13 +37,6 @@ Gem::Specification.new do |spec|
33
37
  end
34
38
  spec.require_paths = ['lib']
35
39
 
36
- spec.add_development_dependency('aruba')
37
- spec.add_development_dependency('rake')
38
- spec.add_development_dependency('rspec')
39
- spec.add_development_dependency('rubocop', '1.13')
40
- spec.add_development_dependency('rubocop-rake', '~> 0.5')
41
- spec.add_development_dependency('rubocop-rspec', '~> 2.0')
42
-
43
40
  spec.add_dependency('asciidoctor', '~> 2.0')
44
- spec.add_dependency('defmastership', '>= 1.0.13', '< 2.0')
41
+ spec.add_dependency('defmastership', '>= 1.0.16', '< 2.0')
45
42
  end
data/bin/console CHANGED
@@ -2,8 +2,8 @@
2
2
  # Copyright (c) 2020 Jerome Arbez-Gindre
3
3
  # frozen_string_literal: true
4
4
 
5
- require('bundler/setup')
6
5
  require('asciidoctor/defmastership')
6
+ require('bundler/setup')
7
7
 
8
8
  # You can add fixtures and/or initialization code here to make experimenting
9
9
  # with your gem easier. You can also use a different console, if you like.
@@ -20,6 +20,7 @@ require('asciidoctor/extensions') unless RUBY_ENGINE == 'opal'
20
20
  # [define, requirement, TOTO-0001]
21
21
  # This shall be nice.
22
22
  #
23
+ require('asciidoctor/defmastership/regexp_dispatcher')
23
24
  require('defmastership/constants')
24
25
  require('defmastership/parsing_state')
25
26
 
@@ -27,38 +28,18 @@ module Asciidoctor
27
28
  module DefMastership
28
29
  # Preprocessor to replace adoc statements
29
30
  class Preprocessor < Asciidoctor::Extensions::Preprocessor
30
- EREF_CONFIG_REGEXP = ::DefMastership::DMRegexp::EREF_CONFIG
31
- DEFINITION_REGEXP = ::DefMastership::DMRegexp::DEFINITION
32
- EREF_DEF_REGEXP = ::DefMastership::DMRegexp::EREF_DEF
33
- IREF_DEF_REGEXP = ::DefMastership::DMRegexp::IREF_DEF
34
- ATTR_CONFIG_REGEXP = ::DefMastership::DMRegexp::ATTR_CONFIG
35
- ATTR_SET_REGEXP = ::DefMastership::DMRegexp::ATTR_SET
36
-
37
- private_constant :EREF_CONFIG_REGEXP,
38
- :DEFINITION_REGEXP,
39
- :EREF_DEF_REGEXP,
40
- :IREF_DEF_REGEXP,
41
- :ATTR_CONFIG_REGEXP,
42
- :ATTR_SET_REGEXP
43
-
44
- Filter = Struct.new(:regex, :apply)
45
-
46
- FILTERS = [
47
- Filter.new(EREF_CONFIG_REGEXP, :set_eref_url_if_any),
48
- Filter.new(DEFINITION_REGEXP, :build_definition),
49
- Filter.new(EREF_DEF_REGEXP, :build_external_ref),
50
- Filter.new(IREF_DEF_REGEXP, :build_internal_ref),
51
- Filter.new(ATTR_SET_REGEXP, :attribute_setting)
52
- ].freeze
53
-
54
- private_constant :FILTERS
55
-
56
- # class initialization
31
+ EREF_CONFIG_REGEXP = ::DefMastership::DMRegexp::EREF_CONFIG
32
+ DEFINITION_REGEXP = ::DefMastership::DMRegexp::DEFINITION
33
+ EREF_DEF_REGEXP = ::DefMastership::DMRegexp::EREF_DEF
34
+ IREF_DEF_REGEXP = ::DefMastership::DMRegexp::IREF_DEF
35
+ ATTR_SET_REGEXP = ::DefMastership::DMRegexp::ATTR_SET
36
+ VARIABLE_DEF_REGEXP = ::DefMastership::DMRegexp::VARIABLE_DEF
37
+
57
38
  def initialize(config = {})
58
39
  super(config)
59
- # This is a preprocessor: we need to parse tag attributes
60
- @parsing_is_enabled = true
40
+
61
41
  @has_url = {}
42
+ @variables = {}
62
43
  @parsing_state = ::DefMastership::ParsingState.new
63
44
  end
64
45
 
@@ -72,15 +53,23 @@ module Asciidoctor
72
53
 
73
54
  private
74
55
 
56
+ def build_subs
57
+ subs = RegexpDispatcher.new(self)
58
+ subs
59
+ .add_rule(EREF_CONFIG_REGEXP, :set_eref_url_if_any)
60
+ .add_rule(DEFINITION_REGEXP, :build_definition)
61
+ .add_rule(EREF_DEF_REGEXP, :build_external_ref)
62
+ .add_rule(IREF_DEF_REGEXP, :build_internal_ref)
63
+ .add_rule(ATTR_SET_REGEXP, :attribute_setting)
64
+ .add_rule(VARIABLE_DEF_REGEXP, :variable_set)
65
+ end
66
+
75
67
  def parse_and_replace(lines)
68
+ subs = build_subs
76
69
  lines.reduce([]) do |new_lines, line|
77
- shall_parse = @parsing_state.enabled?(line)
78
- filter = FILTERS.find { |onefilter| line.match(onefilter.regex) }
79
- if filter && shall_parse
80
- new_lines + __send__(filter.apply, line, Regexp.last_match)
81
- else
82
- new_lines + [line]
83
- end
70
+ next new_lines + [line] unless @parsing_state.enabled?(line)
71
+
72
+ next new_lines + subs.replace(line)
84
73
  end
85
74
  end
86
75
 
@@ -89,27 +78,33 @@ module Asciidoctor
89
78
  [line]
90
79
  end
91
80
 
81
+ def show_explicit_checksum(matches)
82
+ matches[:explicit_checksum] &&
83
+ @variables['show-explicit-checksum'] != 'disable' &&
84
+ @variables["show-#{matches[:type]}-explicit-checksum"] != 'disable'
85
+ end
86
+
92
87
  def build_definition(_line, matches)
93
88
  definition_lines = []
94
- explicit_checksum_str = " [.checksum]\#(#{matches[:explicit_checksum]})\#" if matches[:explicit_checksum]
95
- explicit_version_str = " [.version]\#(#{matches[:explicit_version]})\#" if matches[:explicit_version]
89
+ explicit_checksum_str = " [.checksum]#(#{matches[:explicit_checksum]})#" if show_explicit_checksum(matches)
90
+ explicit_version_str = " [.version]#(#{matches[:explicit_version]})#" if matches[:explicit_version]
96
91
  labels_str = " #{labels_strings(matches[:labels]).join(' ')}" if matches[:labels]
97
92
  definition_lines << ".#{matches[:reference]}#{explicit_version_str}#{explicit_checksum_str}#{labels_str}"
98
93
  definition_lines <<
99
- "[\##{matches[:reference]}.define.#{matches[:type]}]"
94
+ "[##{matches[:reference]}.define.#{matches[:type]}]"
100
95
  end
101
96
 
102
97
  def labels_strings(labels)
103
98
  labels_strs = []
104
99
  labels.split(/\s*,\s*/).reject(&:empty?).each do |label|
105
- labels_strs << "[.tag.{tag-#{label}-color}]\##{label}\#"
100
+ labels_strs << "[.tag.{tag-#{label}-color}]##{label}#"
106
101
  end
107
102
  labels_strs
108
103
  end
109
104
 
110
105
  def build_link(ref, matches)
111
106
  if @has_url[matches[:refname]]
112
- "link:{eref-#{matches[:refname]}-url}\##{ref}\[#{ref}]"
107
+ "link:{eref-#{matches[:refname]}-url}##{ref}[#{ref}]"
113
108
  else
114
109
  ref
115
110
  end
@@ -120,7 +115,7 @@ module Asciidoctor
120
115
  new_line = "[.external_reference]\#{eref-#{matches[:refname]}-prefix} "
121
116
  extref_line = extrefs.map { |ref| build_link(ref, matches) }
122
117
  @has_url[matches[:refname]]
123
- ["#{new_line}#{extref_line.join(', ')}.\#"]
118
+ ["#{new_line}#{extref_line.join(', ')}.#"]
124
119
  end
125
120
 
126
121
  def build_internal_ref(line, _matches)
@@ -137,6 +132,11 @@ module Asciidoctor
137
132
  "{attr-#{matches[:attr]}-prefix} #{matches[:value]}."
138
133
  ]
139
134
  end
135
+
136
+ def variable_set(line, matches)
137
+ @variables[matches[:varname]] = matches[:value]
138
+ [line]
139
+ end
140
140
  end
141
141
  end
142
142
  end
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2023 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('asciidoctor/extensions') unless RUBY_ENGINE == 'opal'
5
+ require('ostruct')
6
+
7
+ module Asciidoctor
8
+ module DefMastership
9
+ # Hosts several Text replacement rules
10
+ class RegexpDispatcher
11
+ Rule = Struct.new(:regexp, :method_symbol)
12
+ private_constant :Rule
13
+
14
+ def initialize(effective_subs)
15
+ @effective_subs = effective_subs
16
+ @rules = []
17
+ end
18
+
19
+ def add_rule(regexp, method_symbol)
20
+ @rules << Rule.new(regexp, method_symbol)
21
+ self
22
+ end
23
+
24
+ def replace(line)
25
+ @rules.each do |rule|
26
+ matches = rule.regexp.match(line)
27
+ return @effective_subs.__send__(rule.method_symbol, line, matches) if matches
28
+ end
29
+ [line]
30
+ end
31
+ end
32
+ end
33
+ end
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Asciidoctor
5
5
  module DefMastership
6
- VERSION = '1.0.5'
6
+ VERSION = '1.0.6'
7
7
  public_constant :VERSION
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,99 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-defmastership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérôme Arbez-Gindre
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-01 00:00:00.000000000 Z
11
+ date: 2023-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: aruba
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '='
60
- - !ruby/object:Gem::Version
61
- version: '1.13'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '='
67
- - !ruby/object:Gem::Version
68
- version: '1.13'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop-rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '0.5'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '0.5'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '2.0'
97
13
  - !ruby/object:Gem::Dependency
98
14
  name: asciidoctor
99
15
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +30,7 @@ dependencies:
114
30
  requirements:
115
31
  - - ">="
116
32
  - !ruby/object:Gem::Version
117
- version: 1.0.13
33
+ version: 1.0.16
118
34
  - - "<"
119
35
  - !ruby/object:Gem::Version
120
36
  version: '2.0'
@@ -124,7 +40,7 @@ dependencies:
124
40
  requirements:
125
41
  - - ">="
126
42
  - !ruby/object:Gem::Version
127
- version: 1.0.13
43
+ version: 1.0.16
128
44
  - - "<"
129
45
  - !ruby/object:Gem::Version
130
46
  version: '2.0'
@@ -163,12 +79,14 @@ files:
163
79
  - example/howto.sh
164
80
  - lib/asciidoctor/defmastership.rb
165
81
  - lib/asciidoctor/defmastership/extension.rb
82
+ - lib/asciidoctor/defmastership/regexp_dispatcher.rb
166
83
  - lib/asciidoctor/defmastership/version.rb
167
84
  homepage: https://gitlab.com/jjag/asciidoctor-defmastership/
168
85
  licenses:
169
86
  - MIT
170
- metadata: {}
171
- post_install_message:
87
+ metadata:
88
+ rubygems_mfa_required: 'true'
89
+ post_install_message:
172
90
  rdoc_options: []
173
91
  require_paths:
174
92
  - lib
@@ -176,15 +94,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
94
  requirements:
177
95
  - - ">="
178
96
  - !ruby/object:Gem::Version
179
- version: '2.5'
97
+ version: '2.7'
180
98
  required_rubygems_version: !ruby/object:Gem::Requirement
181
99
  requirements:
182
100
  - - ">="
183
101
  - !ruby/object:Gem::Version
184
102
  version: '0'
185
103
  requirements: []
186
- rubygems_version: 3.2.5
187
- signing_key:
104
+ rubygems_version: 3.4.1
105
+ signing_key:
188
106
  specification_version: 4
189
107
  summary: asciidoctor extension to handle applicable definition references
190
108
  test_files: []