Class: Nyara::View::Buffer

Inherits:
Array show all
Defined in:
lib/nyara/view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#sum, #to_param, #to_query

Constructor Details

#initialize(parent = nil) ⇒ Buffer


37
38
39
# File 'lib/nyara/view.rb', line 37

def initialize parent=nil
  @parent = parent
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent


40
41
42
# File 'lib/nyara/view.rb', line 40

def parent
  @parent
end

Instance Method Details

#_joinObject


48
# File 'lib/nyara/view.rb', line 48

alias _join join

#append=(thingy) ⇒ Object


44
45
46
# File 'lib/nyara/view.rb', line 44

def append= thingy
  self << CGI.escape_html(thingy.to_s)
end

#flush(instance) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
# File 'lib/nyara/view.rb', line 63

def flush instance
  parents = [self]
  buf = self
  while buf = buf.parent
    parents << buf
  end
  parents.reverse_each do |buf|
    instance.send_chunk buf._join
    buf.clear
  end
end

#joinObject


49
50
51
52
53
# File 'lib/nyara/view.rb', line 49

def join
  r = super
  clear
  r
end

#pop_levelObject


59
60
61
# File 'lib/nyara/view.rb', line 59

def pop_level
  @parent << _join
end

#push_levelObject


55
56
57
# File 'lib/nyara/view.rb', line 55

def push_level
  Buffer.new self
end