Class: Tidewave::ToolbarBody

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

Instance Method Summary collapse

Constructor Details

#initialize(body, toolbar) ⇒ ToolbarBody

Returns a new instance of ToolbarBody.



33
34
35
36
37
# File 'lib/tidewave.rb', line 33

def initialize(body, toolbar)
  @body = body
  @toolbar = toolbar
  @closed = false
end

Instance Method Details

#closeObject



64
65
66
67
68
69
# File 'lib/tidewave.rb', line 64

def close
  return if @closed

  @closed = true
  @body.close if @body.respond_to?(:close)
end

#each {|pending| ... } ⇒ Object

Yields:

  • (pending)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tidewave.rb', line 39

def each
  return enum_for(:each) unless block_given?

  pending = +""
  injected = false

  @body.each do |part|
    if injected
      yield part
    else
      pending << part

      if closing_head = pending.downcase.index("</head>")
        toolbar = @toolbar.dup.force_encoding(pending.encoding)
        output = pending.insert(closing_head, toolbar)
        pending = nil
        injected = true
        yield output
      end
    end
  end

  yield pending unless injected || pending.empty?
end