Class: Asciidoctor::AttributeList

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor/attribute_list.rb

Overview

> { ‘style’ => ‘quote’, ‘attribution’ => ‘Famous Person’, ‘citetitle’ => ‘Famous Book (2001)’ }

Constant Summary collapse

APOS =
'\''
BACKSLASH =
'\\'
QUOT =
'"'
BoundaryRx =

Regular expressions for detecting the boundary of a value

{
  QUOT => /.*?[^\\](?=")/,
  APOS => /.*?[^\\](?=')/,
  ',' => /.*?(?=[ \t]*(,|$))/,
}
EscapedQuotes =

Regular expressions for unescaping quoted characters

{
  QUOT => '\\"',
  APOS => '\\\'',
}
NameRx =

A regular expression for an attribute name (matches syntax of a document attribute)

/#{CG_WORD}[#{CC_WORD}-]*/
BlankRx =
/[ \t]+/
SkipRx =

Regular expressions for skipping delimiters

{ ',' => /[ \t]*(,|$)/ }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, block = nil, delimiter = ',') ⇒ AttributeList

Returns a new instance of AttributeList.



51
52
53
54
55
56
57
58
# File 'lib/asciidoctor/attribute_list.rb', line 51

def initialize source, block = nil, delimiter = ','
  @scanner = ::StringScanner.new source
  @block = block
  @delimiter = delimiter
  @delimiter_skip_pattern = SkipRx[delimiter]
  @delimiter_boundary_pattern = BoundaryRx[delimiter]
  @attributes = nil
end

Class Method Details

.rekey(attributes, positional_attrs) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/asciidoctor/attribute_list.rb', line 84

def self.rekey attributes, positional_attrs
  positional_attrs.each_with_index do |key, index|
    if key && (val = attributes[index + 1])
      # QUESTION should we delete the positional key?
      attributes[key] = val
    end
  end
  attributes
end

Instance Method Details

#parse(positional_attrs = []) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/asciidoctor/attribute_list.rb', line 64

def parse positional_attrs = []
  # return if already parsed
  return @attributes if @attributes

  @attributes = {}
  index = 0

  while parse_attribute index, positional_attrs
    break if @scanner.eos?
    skip_delimiter
    index += 1
  end

  @attributes
end

#parse_into(attributes, positional_attrs = []) ⇒ Object



60
61
62
# File 'lib/asciidoctor/attribute_list.rb', line 60

def parse_into attributes, positional_attrs = []
  attributes.update parse positional_attrs
end

#rekey(positional_attrs) ⇒ Object



80
81
82
# File 'lib/asciidoctor/attribute_list.rb', line 80

def rekey positional_attrs
  AttributeList.rekey @attributes, positional_attrs
end