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

BACKSLASH =
'\\'
APOS =
'\''
BoundaryRxs =

Regular expressions for detecting the boundary of a value

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

Regular expressions for unescaping quoted characters

{
  '"' => '\\"',
  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]+/
SkipRxs =

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.



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

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

Class Method Details

.rekey(attributes, positional_attrs) ⇒ Object



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

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

Instance Method Details

#parse(positional_attrs = []) ⇒ Object



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

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

  @attributes = {}
  # QUESTION do we want to store the attribute list as the zero-index attribute?
  #attributes[0] = @scanner.string
  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



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

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

#rekey(positional_attrs) ⇒ Object



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

def rekey positional_attrs
  AttributeList.rekey @attributes, positional_attrs
end