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 (approx. name token from XML) TODO named attributes cannot contain dash characters

/#{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.



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

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



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

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



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

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



62
63
64
# File 'lib/asciidoctor/attribute_list.rb', line 62

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

#rekey(positional_attrs) ⇒ Object



82
83
84
# File 'lib/asciidoctor/attribute_list.rb', line 82

def rekey positional_attrs
  AttributeList.rekey @attributes, positional_attrs
end