Class: Web::Unit::MemWriter

Inherits:
NullWriter show all
Defined in:
lib/web/unit/response.rb

Instance Method Summary collapse

Methods inherited from NullWriter

#flush, #new_alignment, #new_font, #new_margin, #new_spacing, #new_styles, #send_label_data

Constructor Details

#initializeMemWriter

Returns a new instance of MemWriter.



395
396
397
398
399
400
# File 'lib/web/unit/response.rb', line 395

def initialize
  @body = ''
  @maxcol = 72
  super()
  reset
end

Instance Method Details

#resetObject



402
403
404
405
# File 'lib/web/unit/response.rb', line 402

def reset
  @col = 0
  @atbreak = false
end

#send_flowing_data(data) ⇒ Object



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/web/unit/response.rb', line 443

def send_flowing_data(data)
  return if not data
  atbreak = (@atbreak || (/^\s/ =~ data))
  col = @col
  maxcol = @maxcol
  for word in data.split
    if atbreak
      if col + word.length >= maxcol
        @body << ("\n")
        col = 0
      else
        @body << (' ')
        col = col + 1
      end
    end
    @body << (word)
    col = col + word.length
    atbreak = true
  end
  @col = col
  @atbreak = (/\s$/ =~ data)
end

#send_hor_ruleObject

(*args, **kw)



423
424
425
426
427
428
429
# File 'lib/web/unit/response.rb', line 423

def send_hor_rule #(*args, **kw)
  @body << ("\n")
  @body << ('-'*@maxcol)
  @body << ("\n")
  @col = 0
  @atbreak = false
end

#send_line_breakObject



417
418
419
420
421
# File 'lib/web/unit/response.rb', line 417

def send_line_break
  @body << ("\n")
  @col = 0
  @atbreak = false
end

#send_literal_data(data) ⇒ Object



431
432
433
434
435
436
437
438
439
440
441
# File 'lib/web/unit/response.rb', line 431

def send_literal_data(data)
  @body << (data)
  i = data.rindex("\n")
  if i
    @col = 0
    data = data[i+1..-1]
    #data = string.expandtabs(data)
    @col = @col + data.length
    @atbreak = false
  end
end

#send_paragraph(blankline) ⇒ Object



411
412
413
414
415
# File 'lib/web/unit/response.rb', line 411

def send_paragraph(blankline)
  @body << ("\n" + "\n"*blankline)
  @col = 0
  @atbreak = false
end

#to_sObject



407
408
409
# File 'lib/web/unit/response.rb', line 407

def to_s
  @body.squeeze( "\n" )
end