Class: Coradoc::AsciiDoc::Serializer::SpacingStrategy
- Inherits:
-
Object
- Object
- Coradoc::AsciiDoc::Serializer::SpacingStrategy
- Defined in:
- lib/coradoc/asciidoc/serializer/spacing_strategy.rb
Overview
Handles spacing logic for AsciiDoc serialization. Determines appropriate spacing between different element types.
Class Method Summary collapse
-
.apply(elements, _options = {}) ⇒ String
Apply spacing to elements based on their types.
- .block_level?(element) ⇒ Boolean
-
.inline_level?(element) ⇒ Boolean
Check if element is inline-level.
-
.spacing_between(current, next_elem) ⇒ String?
Determine spacing between two elements.
Class Method Details
.apply(elements, _options = {}) ⇒ String
Apply spacing to elements based on their types
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/coradoc/asciidoc/serializer/spacing_strategy.rb', line 14 def apply(elements, = {}) return '' if elements.nil? || elements.empty? return elements.first.to_s if elements.size == 1 result = [] elements.each_with_index do |element, index| result << element.to_s # Add spacing between current and next element next unless index < elements.size - 1 next_element = elements[index + 1] spacing = spacing_between(element, next_element) result << spacing if spacing end result.join end |
.block_level?(element) ⇒ Boolean
50 51 52 53 54 55 |
# File 'lib/coradoc/asciidoc/serializer/spacing_strategy.rb', line 50 def block_level?(element) return false if element.nil? return true if element.is_a?(String) element.block_level? end |
.inline_level?(element) ⇒ Boolean
Check if element is inline-level
60 61 62 63 64 65 |
# File 'lib/coradoc/asciidoc/serializer/spacing_strategy.rb', line 60 def inline_level?(element) return false if element.nil? return true if element.is_a?(String) element.inline? end |
.spacing_between(current, next_elem) ⇒ String?
Determine spacing between two elements
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/coradoc/asciidoc/serializer/spacing_strategy.rb', line 37 def spacing_between(current, next_elem) # Block-level elements typically need double newline spacing if block_level?(current) && block_level?(next_elem) "\n\n" # Inline elements don't need extra spacing elsif inline_level?(current) && inline_level?(next_elem) nil # Mixed block/inline needs single newline elsif block_level?(current) || block_level?(next_elem) "\n" end end |