Class: Spirit::Render::Headers
- Inherits:
-
Object
- Object
- Spirit::Render::Headers
- 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
-
#add(text, level = 1) ⇒ Header
Adds a new header to the set.
-
#initialize ⇒ Headers
constructor
A new instance of Headers.
Constructor Details
#initialize ⇒ Headers
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.
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 |