Class: Ast::Crispr::Markdown::Markly::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/crispr/markdown/markly.rb

Instance Method Summary collapse

Instance Method Details

#comment_region_text(_document, _comment_region) ⇒ Object

Raises:

  • (Ast::Crispr::Error)


49
50
51
# File 'lib/ast/crispr/markdown/markly.rb', line 49

def comment_region_text(_document, _comment_region)
  raise Ast::Crispr::Error, 'Markdown CRISPR adapter does not expose comment regions'
end

#comment_regions_for(_document, _owner, region: :leading, owner_scope: :shared_default) ⇒ Object

Raises:

  • (Ast::Crispr::Error)


42
43
44
45
46
47
# File 'lib/ast/crispr/markdown/markly.rb', line 42

def comment_regions_for(_document, _owner, region: :leading, owner_scope: :shared_default)
  raise Ast::Crispr::Error.new(
    'Unsupported CRISPR comment region',
    details: { region: region, owner_scope: owner_scope }
  )
end

#read_ast(document) ⇒ Object

Raises:

  • (Ast::Crispr::Error)


14
15
16
17
18
19
20
# File 'lib/ast/crispr/markdown/markly.rb', line 14

def read_ast(document)
  analysis = ::Markly::Merge::FileAnalysis.new(document.content)
  return analysis if analysis.valid?

  raise Ast::Crispr::Error.new("Unable to read structural owners from #{document.source_label}",
                               details: { source_label: document.source_label })
end

#structural_owners(document, owner_scope: :shared_default) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ast/crispr/markdown/markly.rb', line 22

def structural_owners(document, owner_scope: :shared_default)
  analysis = document.ast
  case owner_scope
  when :shared_default, :heading_sections
    analysis.heading_section_owners
  when :link_definitions
    analysis.link_definition_owners
  when :html_comments
    analysis.html_comment_owners
  when :list_items
    analysis.list_item_owners
  when :inline_references
    analysis.inline_reference_owners
  when :table_rows
    analysis.table_row_owners
  else
    raise Ast::Crispr::Error.new('Unsupported CRISPR owner scope', details: { owner_scope: owner_scope })
  end
end

#structure_profile(owner_scope: :shared_default) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ast/crispr/markdown/markly.rb', line 53

def structure_profile(owner_scope: :shared_default)
  case owner_scope
  when :shared_default, :heading_sections
    Ast::Crispr::StructureProfile.new(
      owner_scope: owner_scope,
      owner_selector: :heading_sections,
      supported_comment_regions: [],
      metadata: { adapter: :markly }
    )
  when :link_definitions
    Ast::Crispr::StructureProfile.new(
      owner_scope: owner_scope,
      owner_selector: :link_definitions,
      supported_comment_regions: [],
      metadata: { adapter: :markly }
    )
  when :html_comments
    Ast::Crispr::StructureProfile.new(
      owner_scope: owner_scope,
      owner_selector: :line_bound_statements,
      supported_comment_regions: [],
      metadata: { adapter: :markly, markdown_owner: :html_comment }
    )
  when :list_items
    Ast::Crispr::StructureProfile.new(
      owner_scope: owner_scope,
      owner_selector: :list_items,
      supported_comment_regions: [],
      metadata: { adapter: :markly, markdown_owner: :list_item }
    )
  when :inline_references
    Ast::Crispr::StructureProfile.new(
      owner_scope: owner_scope,
      owner_selector: :inline_references,
      supported_comment_regions: [],
      metadata: { adapter: :markly, markdown_owner: :inline_reference }
    )
  when :table_rows
    Ast::Crispr::StructureProfile.new(
      owner_scope: owner_scope,
      owner_selector: :table_rows,
      supported_comment_regions: [],
      metadata: { adapter: :markly, markdown_owner: :table_row }
    )
  else
    raise Ast::Crispr::Error.new('Unsupported CRISPR owner scope', details: { owner_scope: owner_scope })
  end
end