class Rack::Pagelime

Constants

ENV_KEYS

Public Class Methods

new(app) click to toggle source
# File lib/rack/pagelime.rb, line 82
def initialize(app)
  @app = app
  
  ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Rack Plugin Initialized"
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/pagelime.rb, line 88
def call(env)
  
  app_resp  = @app.call(env)
  req       = Rack::Request.new(env)
  resp      = handle_route(req)
  
  # only process original output if routing wasn't handled
  unless resp
    
    status, headers, response = app_resp
  
    ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Headers: #{headers}"
    ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Status: #{status.inspect}"
    ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Response: #{response}"
    
    if status == 200 && headers["Content-Type"].to_s.include?("text/html") && processing_enabled_for_request?(req)
        
      html = ""
      response.each{|part| html << part}
      
      ::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Processing For Path: #{req.path}"
      ::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Processing Body (size:#{html.length})"
      ::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Processing Body: #{html.inspect}"
    
      html = ::Pagelime.process_page(html, req.path)
  
      headers['content-length'] = html.length.to_s
  
      body = [html]
      
    else
  
      ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Not touching this request"
  
      body = response
  
    end
    
    resp = [status, headers, body]
    
  end
  
  resp
end