Class: Spirit::Render::Headers

Inherits:
Object
  • Object
show all
Defined in:
lib/spirit/render/templates/header.rb

Overview

Keeps track of headers within the same document. It’s responsible for assigning unique names that can be used in the anchors.

Instance Method Summary collapse

Constructor Details

#initializeHeaders

Returns a new instance of Headers.



12
13
14
# File 'lib/spirit/render/templates/header.rb', line 12

def initialize
  @headers = {}
end

Instance Method Details

#add(text, level = 1) ⇒ Header

Adds a new header to the set.

Returns:



18
19
20
21
22
23
24
# File 'lib/spirit/render/templates/header.rb', line 18

def add(text, level=1)
  name = text.parameterize
  if @headers.include? name
    name += '-%d' % (@headers[name] += 1)
  else @headers[name] = 0 end
  Header.new(text, level, name)
end