Class: Pray::Render::ContentBuilder
- Inherits:
-
Object
- Object
- Pray::Render::ContentBuilder
- Defined in:
- lib/pray/render.rb
Instance Method Summary collapse
- #append_body(body) ⇒ Object
- #append_empty_line ⇒ Object
- #append_line(line) ⇒ Object
- #finish ⇒ Object
-
#initialize ⇒ ContentBuilder
constructor
A new instance of ContentBuilder.
- #next_line_number ⇒ Object
Constructor Details
#initialize ⇒ ContentBuilder
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_line ⇒ Object
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 |
#finish ⇒ Object
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_number ⇒ Object
334 335 336 |
# File 'lib/pray/render.rb', line 334 def next_line_number @content.count("\n") + 1 end |