Class: AsciidoctorVaped::Parser::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor_vaped/parser/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, reader, parent: nil) ⇒ Context

Returns a new instance of Context.



8
9
10
11
12
13
14
# File 'lib/asciidoctor_vaped/parser/context.rb', line 8

def initialize(document, reader, parent: nil)
  @document = document
  @reader = reader
  @parent = parent
  @sections = []
  @pending_attributes = {}
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



6
7
8
# File 'lib/asciidoctor_vaped/parser/context.rb', line 6

def document
  @document
end

#pending_attributesObject (readonly)

Returns the value of attribute pending_attributes.



6
7
8
# File 'lib/asciidoctor_vaped/parser/context.rb', line 6

def pending_attributes
  @pending_attributes
end

#readerObject (readonly)

Returns the value of attribute reader.



6
7
8
# File 'lib/asciidoctor_vaped/parser/context.rb', line 6

def reader
  @reader
end

Instance Method Details

#add_pending_attributes(attributes) ⇒ Object



32
33
34
# File 'lib/asciidoctor_vaped/parser/context.rb', line 32

def add_pending_attributes(attributes)
  @pending_attributes.merge!(attributes)
end

#append(node) ⇒ Object



20
21
22
23
# File 'lib/asciidoctor_vaped/parser/context.rb', line 20

def append(node)
  node.attributes.merge!(consume_attributes)
  parent << node
end

#nested(parent, reader = @reader) ⇒ Object



16
17
18
# File 'lib/asciidoctor_vaped/parser/context.rb', line 16

def nested(parent, reader = @reader)
  self.class.new(document, reader, parent:)
end

#open_section(section) ⇒ Object



25
26
27
28
29
30
# File 'lib/asciidoctor_vaped/parser/context.rb', line 25

def open_section(section)
  level = section.attributes.fetch(:level)
  @sections.pop while @sections.any? && @sections.last.attributes.fetch(:level) >= level
  parent << section
  @sections << section
end

#pending_title=(title) ⇒ Object



36
37
38
# File 'lib/asciidoctor_vaped/parser/context.rb', line 36

def pending_title=(title)
  @pending_attributes[:title] = title
end