Class: Rack::Pagelime

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/rack/pagelime.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Pagelime

Returns a new instance of Pagelime.



10
11
12
13
14
15
# File 'lib/rack/pagelime.rb', line 10

def initialize(app, options = {})
  @app      = app
  @options  = options
  
  ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Rack Plugin Initialized"
end

Instance Method Details

#call(env) ⇒ Object



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
# File 'lib/rack/pagelime.rb', line 17

def call(env)

  status, headers, response = @app.call(env)

  ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Headers: #{headers}"
  ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Status: #{status}"
  ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Response: #{response}"

  if status == 200 && headers["content-type"].include?("text/html")
      
    body_content = StringIO.new
    response.each{|part| body_content << part}

    req = Rack::Request.new(env)

    ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Processing For Path: #{req.path}"
    ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Processing Body (size:#{body_content.length})"
  
    body = ::Pagelime.process_page(body_content, req.path)

    headers['content-length'] = body.length.to_s

    return [status, headers, [body]]

  else

    ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Not touching this request"

    return [status, headers, response]

  end

end