Class: ESI::Parser

Inherits:
CParser show all
Defined in:
lib/esi/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from CParser

#depth, #depth=, #end_tag_handler, #esi_tag, #esi_tag=, #flush, #output, #output<<, #output=, #output_handler, #process, #start_tag_handler

Constructor Details

#initialize(output, router, cache, max_depth) ⇒ Parser

Returns a new instance of Parser.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/esi/parser.rb', line 15

def initialize( output, router, cache, max_depth )
  super()
  @router = router
  @cache = cache
  @max_depth = max_depth
  @response = ESI::Response.new( output )
 
  end_tag_handler do|tag_name|
    #puts "rb end #{tag_name.inspect}"
    if self.esi_tag.name == tag_name.sub(/esi:/,'')

      if tag_name.match(/try|include/) # run these in parallel
        tag = self.esi_tag.clone
        tag_buffer = @response.partial_buffer

        #puts "start #{tag_name}"
        thread = Thread.new(tag,tag_buffer) do|tag,buffer|
          begin
            tag.close(buffer)
          ensure
            buffer.close_write
            #puts "finish #{tag_name}"
          end
        end
        @response.wait_thread( thread )
      else
        self.esi_tag.close( @response.active_buffer )
      end

      self.esi_tag = nil

    else
      self.esi_tag.close_child(self.output,tag_name)
    end
  end
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



13
14
15
# File 'lib/esi/parser.rb', line 13

def response
  @response
end

Instance Method Details

#finishObject



77
78
79
80
# File 'lib/esi/parser.rb', line 77

def finish
  super
  @response.flush
end

#prepare(request_params, http_params) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/esi/parser.rb', line 52

def prepare( request_params, http_params )
  start_tag_handler do|tag_name, attrs|
    #puts "rb start #{tag_name.inspect}"
    tag = ESI::Tag::Base.create( @router,
                                 request_params,
                                 http_params,
                                 tag_name.gsub(/esi:/,''),
                                 attrs,
                                 @cache )
    # set the tag depth
    tag.depth = self.depth if tag.respond_to?(:depth=)
    tag.max_depth = @max_depth if tag.respond_to?(:max_depth=)

    if self.esi_tag and self.esi_tag.respond_to?(:add_child)
      self.esi_tag.add_child(tag)
    else
      self.esi_tag = tag
    end
  end
  self.output_handler do|chars|
    @response.active_buffer << chars
    @response.send
  end
end