Class: Orange::Middleware::Template

Inherits:
Base show all
Defined in:
lib/orange-core/middleware/template.rb

Instance Method Summary collapse

Methods inherited from Base

#call, #initialize, #inspect, #orange, #pass, #recapture

Constructor Details

This class inherits a constructor from Orange::Middleware::Base

Instance Method Details

#init(*args) ⇒ Object



7
8
9
10
11
# File 'lib/orange-core/middleware/template.rb', line 7

def init(*args)
  @core.add_pulp(Orange::Pulp::Template)
  @core.mixin(Orange::Mixins::Template)
  
end

#needs_wrapped?(packet) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/orange-core/middleware/template.rb', line 25

def needs_wrapped?(packet)
  return false if packet.request.xhr? && !packet['template.enable'] # don't wrap xhr unless specifically asked to
  packet['template.file'] && !packet['template.disable'] 
end

#packet_call(packet) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/orange-core/middleware/template.rb', line 13

def packet_call(packet)
  packet['template.file'] = orange.template_for packet
  status, headers, content = pass packet
  if needs_wrapped?(packet)
    content = wrap(packet, content)
    packet[:content] = content.first
    orange.fire(:wrapped, packet)
  end  
  orange.fire(:after_wrap, packet)
  packet.finish
end

#wrap(packet, content = false) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/orange-core/middleware/template.rb', line 30

def wrap(packet, content = false)
  content = packet.content unless content
  content = content.join
  content = orange[:parser].haml(packet['template.file'], packet, :wrapped_content => content, :template => true) do 
    content
  end
  [content]
end