Class: Erubi::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/erubi/capture.rb

Overview

A buffer class used for templates that support captures

Instance Method Summary collapse

Constructor Details

#initializeBuffer

Returns a new instance of Buffer.



8
9
10
# File 'lib/erubi/capture.rb', line 8

def initialize
  @bufs = [new_buffer]
end

Instance Method Details

#<<(str) ⇒ Object

Append to the current buffer



18
19
20
# File 'lib/erubi/capture.rb', line 18

def <<(str)
  buffer << str
end

#append=(_) ⇒ Object

Take the current buffer and append it to the previous buffer.



28
29
30
31
# File 'lib/erubi/capture.rb', line 28

def append=(_)
  buf = @bufs.pop
  buffer << buf.to_s
end

#before_append!Object

Add a new buffer, that future appends will go to.



23
24
25
# File 'lib/erubi/capture.rb', line 23

def before_append!
  @bufs << new_buffer
end

#bufferObject

Return the current buffer



13
14
15
# File 'lib/erubi/capture.rb', line 13

def buffer
  @bufs.last
end

#escape=(_) ⇒ Object

Escape the current buffer and append it to the previous buffer,



34
35
36
37
# File 'lib/erubi/capture.rb', line 34

def escape=(_)
  buf = @bufs.pop
  buffer << escape(buf.to_s)
end

#to_sObject

Return the current buffer, as a string.



40
41
42
# File 'lib/erubi/capture.rb', line 40

def to_s
  buffer.to_s
end