coradoc 2.0.3 → 2.0.4

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: 7f2699bddcd303d5c58e2f3e6a7d4c4341a8f06dc06df44785a97aa48ad7e055
4
- data.tar.gz: 8e696cec10f047229d67806d5d93d21bcd02465ef57da243295f13906ccfc91d
3
+ metadata.gz: 69f496efd91c2d85e4e057be629f8ee00492c40497661c0af940be65f148e092
4
+ data.tar.gz: a2668ca45e7d23bf613d966c36b4c5da70311be0dcdbc0fba4d988844f49b65f
5
5
  SHA512:
6
- metadata.gz: 8b313846dc7365da7c399117c33119c28009df2009d478345157839c29e9bf30a152fb0000ab56c7202ea7cb784e661ba2a3b61bfa7a40f7616440182994f718
7
- data.tar.gz: 42118e1947a3c609110786b7f906412080a79e518b02e101a4cc19d696e790849d93cdc049334829837a44a18308a34a03e3d6caf8fac83628a8119c1d35cfcc
6
+ metadata.gz: '04584b5faee36ac872400d4d17458221931de4f733aae75839dc40f282d4f863948c9105eb80fefb84f6945639c76c55ccf62fd93d8fd442268f36698950625d'
7
+ data.tar.gz: 00c91cfd40f731c1fffab6ae507d326140e5c7830a8d10bf6a5bb75857ba0b69a552fc4a27d8bd3abb95d4a16159a516df62232bc538fd79fe55a7023e95af0b
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2026-05-07 12:19:03 UTC using RuboCop version 1.75.8.
3
+ # on 2026-05-08 04:52:25 UTC using RuboCop version 1.75.8.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -154,7 +154,7 @@ Metrics/BlockNesting:
154
154
  Metrics/ClassLength:
155
155
  Max: 556
156
156
 
157
- # Offense count: 181
157
+ # Offense count: 179
158
158
  # Configuration parameters: AllowedMethods, AllowedPatterns.
159
159
  Metrics/CyclomaticComplexity:
160
160
  Max: 32
@@ -175,7 +175,7 @@ Metrics/ParameterLists:
175
175
  Max: 7
176
176
  MaxOptionalParameters: 4
177
177
 
178
- # Offense count: 123
178
+ # Offense count: 122
179
179
  # Configuration parameters: AllowedMethods, AllowedPatterns.
180
180
  Metrics/PerceivedComplexity:
181
181
  Max: 27
@@ -238,6 +238,12 @@ Naming/VariableName:
238
238
  Exclude:
239
239
  - 'coradoc-markdown/lib/coradoc/markdown.rb'
240
240
 
241
+ # Offense count: 12
242
+ # This cop supports unsafe autocorrection (--autocorrect-all).
243
+ RSpec/BeEq:
244
+ Exclude:
245
+ - 'coradoc-adoc/spec/coradoc/asciidoc/model/element_classification_spec.rb'
246
+
241
247
  # Offense count: 1
242
248
  RSpec/BeforeAfterAll:
243
249
  Exclude:
@@ -246,11 +252,19 @@ RSpec/BeforeAfterAll:
246
252
  - '**/spec/support/**/*.rb'
247
253
  - 'spec/benchmark/performance_spec.rb'
248
254
 
249
- # Offense count: 19
255
+ # Offense count: 20
250
256
  # Configuration parameters: IgnoredMetadata.
251
257
  RSpec/DescribeClass:
252
258
  Enabled: false
253
259
 
260
+ # Offense count: 1
261
+ # This cop supports unsafe autocorrection (--autocorrect-all).
262
+ # Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
263
+ # SupportedStyles: described_class, explicit
264
+ RSpec/DescribedClass:
265
+ Exclude:
266
+ - 'coradoc-adoc/spec/coradoc/asciidoc/model/base_spec.rb'
267
+
254
268
  # Offense count: 485
255
269
  # Configuration parameters: CountAsOne.
256
270
  RSpec/ExampleLength:
@@ -302,7 +316,7 @@ RSpec/MessageSpies:
302
316
  RSpec/MultipleDescribes:
303
317
  Enabled: false
304
318
 
305
- # Offense count: 613
319
+ # Offense count: 619
306
320
  RSpec/MultipleExpectations:
307
321
  Max: 12
308
322
 
@@ -381,7 +395,7 @@ Style/ClassVars:
381
395
  - 'coradoc-adoc/lib/coradoc/asciidoc/serializer/element_registry.rb'
382
396
  - 'coradoc-html/lib/coradoc/html/input/converters.rb'
383
397
 
384
- # Offense count: 291
398
+ # Offense count: 292
385
399
  # Configuration parameters: AllowedConstants.
386
400
  Style/Documentation:
387
401
  Enabled: false
@@ -17,6 +17,9 @@ module Coradoc
17
17
  # @see Coradoc::AsciiDoc::Model::Block::Core
18
18
  #
19
19
  class Attached < Base
20
+ def block_level?
21
+ true
22
+ end
20
23
  end
21
24
  end
22
25
  end
@@ -35,6 +35,16 @@ module Coradoc
35
35
 
36
36
  attribute :id, :string
37
37
 
38
+ # Element classification for spacing and serialization decisions.
39
+ # Subclasses override these to declare their level.
40
+ def block_level?
41
+ false
42
+ end
43
+
44
+ def inline?
45
+ false
46
+ end
47
+
38
48
  # Generate a warning message whenever this method is called.
39
49
  def simplify_block_content(content)
40
50
  warn '[DEPRECATION] #simplify_block_content is called inside a Lutaml Model. This is still a WIP.'
@@ -21,6 +21,10 @@ module Coradoc
21
21
  # @see Coradoc::AsciiDoc::Model::CommentLine Single-line comments
22
22
  #
23
23
  class CommentBlock < Base
24
+ def block_level?
25
+ true
26
+ end
27
+
24
28
  attribute :text, :string
25
29
  attribute :line_break, :string, default: -> { "\n" }
26
30
  end
@@ -5,6 +5,10 @@ module Coradoc
5
5
  module Model
6
6
  module Image
7
7
  class BlockImage < Coradoc::AsciiDoc::Model::Image::Core
8
+ def block_level?
9
+ true
10
+ end
11
+
8
12
  # Autoload nested AttributeList class
9
13
  autoload :AttributeList, 'coradoc/asciidoc/model/image/block_image/attribute_list'
10
14
 
@@ -5,6 +5,10 @@ module Coradoc
5
5
  module Model
6
6
  module Image
7
7
  class InlineImage < Coradoc::AsciiDoc::Model::Image::Core
8
+ def inline?
9
+ true
10
+ end
11
+
8
12
  attribute :colons, :string, default: -> { ':' }
9
13
  end
10
14
  end
@@ -5,6 +5,9 @@ module Coradoc
5
5
  module Model
6
6
  module Inline
7
7
  class Base < Coradoc::AsciiDoc::Model::Base
8
+ def inline?
9
+ true
10
+ end
8
11
  end
9
12
  end
10
13
  end
@@ -14,6 +14,9 @@ module Coradoc
14
14
  # break.to_adoc # => " +"
15
15
  #
16
16
  class HardLineBreak < Base
17
+ def inline?
18
+ :hardbreak
19
+ end
17
20
  end
18
21
  end
19
22
  end
@@ -29,6 +29,10 @@ module Coradoc
29
29
  class Core < Nestable
30
30
  include Coradoc::AsciiDoc::Model::Anchorable
31
31
 
32
+ def block_level?
33
+ true
34
+ end
35
+
32
36
  attribute :id, :string
33
37
  attribute :prefix, :string
34
38
  # attribute :anchor, Inline::Anchor, default: -> {
@@ -65,23 +65,6 @@ module Coradoc
65
65
  initialize_empty: true
66
66
 
67
67
  attribute :nested, Coradoc::AsciiDoc::Model::List::Nestable
68
-
69
- HARDBREAK_MARKERS = %i[hardbreak init].freeze
70
- STRIP_UNICODE_BEGIN_MARKERS = (HARDBREAK_MARKERS.dup + [false]).freeze
71
- STRIP_UNICODE_END_MARKERS = [:hardbreak, :end, false].freeze
72
-
73
- def inline?(elem)
74
- case elem
75
- when Inline::HardLineBreak
76
- :hardbreak
77
- when ->(i) { i.class.name.to_s.include? '::Inline::' }
78
- true
79
- when String, TextElement, Image::InlineImage
80
- true
81
- else
82
- false
83
- end
84
- end
85
68
  end
86
69
  end
87
70
  end
@@ -39,6 +39,10 @@ module Coradoc
39
39
  class Section < Base
40
40
  include Coradoc::AsciiDoc::Model::Anchorable
41
41
 
42
+ def block_level?
43
+ true
44
+ end
45
+
42
46
  attribute :id, :string
43
47
  attribute :content, :string
44
48
  attribute :title, Coradoc::AsciiDoc::Model::Title
@@ -26,6 +26,10 @@ module Coradoc
26
26
  class Table < Base
27
27
  include Coradoc::AsciiDoc::Model::Anchorable
28
28
 
29
+ def block_level?
30
+ true
31
+ end
32
+
29
33
  attribute :id, :string
30
34
  attribute :title, :string
31
35
  attribute :rows, Coradoc::AsciiDoc::Model::TableRow, collection: true
@@ -4,6 +4,10 @@ module Coradoc
4
4
  module AsciiDoc
5
5
  module Model
6
6
  class TextElement < Base
7
+ def inline?
8
+ true
9
+ end
10
+
7
11
  attribute :id, :string
8
12
  attribute :content,
9
13
  Lutaml::Model::Serializable,
@@ -120,17 +120,6 @@ module Coradoc
120
120
  end
121
121
  end
122
122
 
123
- # Helper to check if element is block-level
124
- # @param element [Object] Element to check
125
- # @return [Boolean] True if block-level
126
- def block_level_element?(element)
127
- element.is_a?(Coradoc::AsciiDoc::Model::Block::Core) ||
128
- element.is_a?(Coradoc::AsciiDoc::Model::Section) ||
129
- element.is_a?(Coradoc::AsciiDoc::Model::Paragraph) ||
130
- element.is_a?(Coradoc::AsciiDoc::Model::List) ||
131
- element.is_a?(Coradoc::AsciiDoc::Model::Table)
132
- end
133
-
134
123
  # Helper to add spacing between elements
135
124
  # @param elements [Array] Elements to space
136
125
  # @param options [Hash] Spacing options
@@ -94,16 +94,10 @@ module Coradoc
94
94
  private
95
95
 
96
96
  def inline?(elem)
97
- case elem
98
- when Coradoc::AsciiDoc::Model::Inline::HardLineBreak
99
- :hardbreak
100
- when ->(i) { i.class.name.to_s.include?('::Inline::') }
101
- true
102
- when String, Coradoc::AsciiDoc::Model::TextElement, Coradoc::AsciiDoc::Model::Image::InlineImage
103
- true
104
- else
105
- false
106
- end
97
+ return true if elem.is_a?(String)
98
+ return false unless elem.is_a?(Coradoc::AsciiDoc::Model::Base)
99
+
100
+ elem.inline?
107
101
  end
108
102
 
109
103
  def gen_anchor(inline: false)
@@ -47,19 +47,11 @@ module Coradoc
47
47
  end
48
48
  end
49
49
 
50
- # Check if element is block-level
51
- # @param element [Object] Element to check
52
- # @return [Boolean] True if block-level
53
50
  def block_level?(element)
54
51
  return false if element.nil?
52
+ return true if element.is_a?(String)
55
53
 
56
- element.is_a?(Coradoc::AsciiDoc::Model::Block::Core) ||
57
- element.is_a?(Coradoc::AsciiDoc::Model::Section) ||
58
- element.is_a?(Coradoc::AsciiDoc::Model::Paragraph) ||
59
- element.is_a?(Coradoc::AsciiDoc::Model::List) ||
60
- element.is_a?(Coradoc::AsciiDoc::Model::Table) ||
61
- element.is_a?(Coradoc::AsciiDoc::Model::CommentBlock) ||
62
- element.is_a?(Coradoc::AsciiDoc::Model::Admonition)
54
+ element.block_level?
63
55
  end
64
56
 
65
57
  # Check if element is inline-level
@@ -67,15 +59,9 @@ module Coradoc
67
59
  # @return [Boolean] True if inline-level
68
60
  def inline_level?(element)
69
61
  return false if element.nil?
62
+ return true if element.is_a?(String)
70
63
 
71
- element.is_a?(String) ||
72
- element.is_a?(Coradoc::AsciiDoc::Model::TextElement) ||
73
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Bold) ||
74
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Italic) ||
75
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Monospace) ||
76
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Highlight) ||
77
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Superscript) ||
78
- element.is_a?(Coradoc::AsciiDoc::Model::Inline::Subscript)
64
+ element.inline?
79
65
  end
80
66
  end
81
67
  end
@@ -33,10 +33,24 @@ RSpec.describe Coradoc::AsciiDoc::Model::Base do
33
33
  end
34
34
 
35
35
  describe '#to_adoc' do
36
- it 'is defined on Base' do
36
+ it 'serializes via ElementRegistry' do
37
37
  instance = test_class.new(name: 'test')
38
38
 
39
- expect(instance).to respond_to(:to_adoc)
39
+ expect(instance).to be_a(described_class)
40
+ end
41
+ end
42
+
43
+ describe 'element classification' do
44
+ it 'defaults block_level? to false' do
45
+ instance = test_class.new
46
+
47
+ expect(instance.block_level?).to be(false)
48
+ end
49
+
50
+ it 'defaults inline? to false' do
51
+ instance = test_class.new
52
+
53
+ expect(instance.inline?).to be(false)
40
54
  end
41
55
  end
42
56
 
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'Element classification' do
6
+ describe 'block_level?' do
7
+ it 'Section is block-level' do
8
+ expect(Coradoc::AsciiDoc::Model::Section.new.block_level?).to be(true)
9
+ end
10
+
11
+ it 'Paragraph is block-level' do
12
+ expect(Coradoc::AsciiDoc::Model::Paragraph.new.block_level?).to be(true)
13
+ end
14
+
15
+ it 'Admonition is block-level' do
16
+ expect(Coradoc::AsciiDoc::Model::Admonition.new.block_level?).to be(true)
17
+ end
18
+
19
+ it 'CommentBlock is block-level' do
20
+ expect(Coradoc::AsciiDoc::Model::CommentBlock.new.block_level?).to be(true)
21
+ end
22
+
23
+ it 'Table is block-level' do
24
+ expect(Coradoc::AsciiDoc::Model::Table.new.block_level?).to be(true)
25
+ end
26
+
27
+ it 'Block::Core is block-level' do
28
+ expect(Coradoc::AsciiDoc::Model::Block::Core.new.block_level?).to be(true)
29
+ end
30
+
31
+ it 'Block::Listing is block-level (inherits from Core)' do
32
+ expect(Coradoc::AsciiDoc::Model::Block::Listing.new.block_level?).to be(true)
33
+ end
34
+
35
+ it 'Block::Quote is block-level (inherits from Core)' do
36
+ expect(Coradoc::AsciiDoc::Model::Block::Quote.new.block_level?).to be(true)
37
+ end
38
+
39
+ it 'List::Ordered is block-level' do
40
+ expect(Coradoc::AsciiDoc::Model::List::Ordered.new.block_level?).to be(true)
41
+ end
42
+
43
+ it 'List::Unordered is block-level' do
44
+ expect(Coradoc::AsciiDoc::Model::List::Unordered.new.block_level?).to be(true)
45
+ end
46
+
47
+ it 'BlockImage is block-level' do
48
+ expect(Coradoc::AsciiDoc::Model::Image::BlockImage.new.block_level?).to be(true)
49
+ end
50
+ end
51
+
52
+ describe 'inline?' do
53
+ it 'Inline::Bold is inline' do
54
+ expect(Coradoc::AsciiDoc::Model::Inline::Bold.new.inline?).to be(true)
55
+ end
56
+
57
+ it 'Inline::Italic is inline' do
58
+ expect(Coradoc::AsciiDoc::Model::Inline::Italic.new.inline?).to be(true)
59
+ end
60
+
61
+ it 'Inline::Monospace is inline' do
62
+ expect(Coradoc::AsciiDoc::Model::Inline::Monospace.new.inline?).to be(true)
63
+ end
64
+
65
+ it 'Inline::Highlight is inline' do
66
+ expect(Coradoc::AsciiDoc::Model::Inline::Highlight.new.inline?).to be(true)
67
+ end
68
+
69
+ it 'Inline::Superscript is inline' do
70
+ expect(Coradoc::AsciiDoc::Model::Inline::Superscript.new.inline?).to be(true)
71
+ end
72
+
73
+ it 'Inline::Subscript is inline' do
74
+ expect(Coradoc::AsciiDoc::Model::Inline::Subscript.new.inline?).to be(true)
75
+ end
76
+
77
+ it 'Inline::Link is inline' do
78
+ expect(Coradoc::AsciiDoc::Model::Inline::Link.new.inline?).to be(true)
79
+ end
80
+
81
+ it 'Inline::Anchor is inline' do
82
+ expect(Coradoc::AsciiDoc::Model::Inline::Anchor.new.inline?).to be(true)
83
+ end
84
+
85
+ it 'TextElement is inline' do
86
+ expect(Coradoc::AsciiDoc::Model::TextElement.new.inline?).to be(true)
87
+ end
88
+
89
+ it 'InlineImage is inline' do
90
+ expect(Coradoc::AsciiDoc::Model::Image::InlineImage.new.inline?).to be(true)
91
+ end
92
+
93
+ it 'HardLineBreak returns :hardbreak' do
94
+ expect(Coradoc::AsciiDoc::Model::Inline::HardLineBreak.new.inline?).to eq(:hardbreak)
95
+ end
96
+ end
97
+
98
+ describe 'non-block, non-inline elements' do
99
+ it 'Title is neither block nor inline' do
100
+ title = Coradoc::AsciiDoc::Model::Title.new
101
+ expect(title.block_level?).to be(false)
102
+ expect(title.inline?).to be(false)
103
+ end
104
+
105
+ it 'List::Item is neither block nor inline' do
106
+ item = Coradoc::AsciiDoc::Model::List::Item.new
107
+ expect(item.block_level?).to be(false)
108
+ expect(item.inline?).to be(false)
109
+ end
110
+
111
+ it 'AttributeList is neither block nor inline' do
112
+ attrs = Coradoc::AsciiDoc::Model::AttributeList.new
113
+ expect(attrs.block_level?).to be(false)
114
+ expect(attrs.inline?).to be(false)
115
+ end
116
+ end
117
+
118
+ describe 'SpacingStrategy integration' do
119
+ let(:strategy) { Coradoc::AsciiDoc::Serializer::SpacingStrategy }
120
+
121
+ it 'uses polymorphic block_level? for spacing' do
122
+ para = Coradoc::AsciiDoc::Model::Paragraph.new
123
+ section = Coradoc::AsciiDoc::Model::Section.new
124
+
125
+ expect(strategy.block_level?(para)).to be(true)
126
+ expect(strategy.block_level?(section)).to be(true)
127
+ end
128
+
129
+ it 'uses polymorphic inline? for spacing' do
130
+ bold = Coradoc::AsciiDoc::Model::Inline::Bold.new
131
+ text = Coradoc::AsciiDoc::Model::TextElement.new
132
+
133
+ expect(strategy.inline_level?(bold)).to be(true)
134
+ expect(strategy.inline_level?(text)).to be(true)
135
+ end
136
+
137
+ it 'returns false for nil' do
138
+ expect(strategy.block_level?(nil)).to be(false)
139
+ expect(strategy.inline_level?(nil)).to be(false)
140
+ end
141
+
142
+ it 'treats strings as inline' do
143
+ expect(strategy.inline_level?('text')).to be(true)
144
+ end
145
+ end
146
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coradoc
4
- VERSION = '2.0.3'
4
+ VERSION = '2.0.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coradoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -300,6 +300,7 @@ files:
300
300
  - coradoc-adoc/spec/coradoc/asciidoc/model/break_spec.rb
301
301
  - coradoc-adoc/spec/coradoc/asciidoc/model/document_attributes_spec.rb
302
302
  - coradoc-adoc/spec/coradoc/asciidoc/model/document_spec.rb
303
+ - coradoc-adoc/spec/coradoc/asciidoc/model/element_classification_spec.rb
303
304
  - coradoc-adoc/spec/coradoc/asciidoc/model/header_spec.rb
304
305
  - coradoc-adoc/spec/coradoc/asciidoc/model/image_spec.rb
305
306
  - coradoc-adoc/spec/coradoc/asciidoc/model/inline/extended_spec.rb