Module: Coradoc::CoreModel::Builder::BlockBuilder Private

Included in:
Coradoc::CoreModel::Builder
Defined in:
lib/coradoc/core_model/builder/block_builder.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Block building module for Builder

Contains methods for building block elements from AST structures.

Instance Method Summary collapse

Instance Method Details

#build_annotation_block(ast) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build annotation block



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/coradoc/core_model/builder/block_builder.rb', line 13

def build_annotation_block(ast)
  annotation_type = extract_annotation_type(ast)

  AnnotationBlock.new(
    annotation_type: annotation_type,
    annotation_label: extract_annotation_label(ast),
    block_semantic_type: :annotation,
    delimiter_length: ast[:delimiter]&.to_s&.length || 4,
    content: extract_block_content(ast),
    lines: extract_block_lines(ast),
    title: ast[:title],
    id: ast[:id],
    attributes: build_attributes_private(ast[:attribute_list])
  )
end

#build_generic_block(ast) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build generic block



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/coradoc/core_model/builder/block_builder.rb', line 30

def build_generic_block(ast)
  semantic_type = delimiter_to_semantic_type(ast[:delimiter]&.to_s)

  Block.new(
    block_semantic_type: semantic_type,
    delimiter_length: ast[:delimiter]&.to_s&.length || 4,
    content: extract_block_content(ast),
    lines: extract_block_lines(ast),
    title: ast[:title],
    id: ast[:id],
    attributes: build_attributes_private(ast[:attribute_list])
  )
end

#delimiter_to_semantic_type(delimiter) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Map delimiter character to semantic type



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/coradoc/core_model/builder/block_builder.rb', line 45

def delimiter_to_semantic_type(delimiter)
  return nil unless delimiter && !delimiter.empty?

  char = delimiter[0]
  case char
  when '-' then :source_code
  when '=' then :example
  when '_' then :quote
  when '*' then :sidebar
  when '.' then :literal
  when '+' then :pass
  else nil
  end
end

#extract_block_content(ast) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract block content from various AST formats



61
62
63
64
65
66
67
68
69
70
# File 'lib/coradoc/core_model/builder/block_builder.rb', line 61

def extract_block_content(ast)
  return ast[:content] if ast[:content]

  if ast[:lines]
    lines = Array(ast[:lines])
    return lines.map { |line| extract_text_content(line) }.join("\n")
  end

  ''
end

#extract_block_lines(ast) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extract block lines



73
74
75
76
77
# File 'lib/coradoc/core_model/builder/block_builder.rb', line 73

def extract_block_lines(ast)
  return [] unless ast[:lines]

  Array(ast[:lines]).map { |line| extract_text_content(line) }
end