Class: Pray::Render::ContentBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/pray/render.rb

Instance Method Summary collapse

Constructor Details

#initializeContentBuilder

Returns a new instance of ContentBuilder.



330
331
332
# File 'lib/pray/render.rb', line 330

def initialize
  @content = +""
end

Instance Method Details

#append_body(body) ⇒ Object



346
347
348
349
350
351
# File 'lib/pray/render.rb', line 346

def append_body(body)
  trimmed = body.sub(/\n+\z/, "")
  return if trimmed.empty?

  trimmed.each_line(chomp: true) { |line| append_line(line) }
end

#append_empty_lineObject



342
343
344
# File 'lib/pray/render.rb', line 342

def append_empty_line
  @content << "\n"
end

#append_line(line) ⇒ Object



338
339
340
# File 'lib/pray/render.rb', line 338

def append_line(line)
  @content << line << "\n"
end

#finishObject



353
354
355
356
357
# File 'lib/pray/render.rb', line 353

def finish
  @content.sub(/\n\n+\z/, "\n")
  @content << "\n" unless @content.end_with?("\n")
  @content
end

#next_line_numberObject



334
335
336
# File 'lib/pray/render.rb', line 334

def next_line_number
  @content.count("\n") + 1
end