module Rack::Pagelime::ClassMethods

Public Instance Methods

disable_processing_for_request(req) click to toggle source
# File lib/rack/pagelime.rb, line 19
def disable_processing_for_request(req)
  req.env[ENV_KEYS[:toggle_processing]] = "off"
end
enable_processing_for_request(req) click to toggle source
# File lib/rack/pagelime.rb, line 15
def enable_processing_for_request(req)
  req.env[ENV_KEYS[:toggle_processing]] = "on"
end
handle_publish_callback(req) click to toggle source
# File lib/rack/pagelime.rb, line 60
def handle_publish_callback(req)
  
  ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Route for publish callback called!"
  
  ::Pagelime.cache.clear_page(req.params["path"].to_s)
  ::Pagelime.cache.clear_shared
  
  [200, {"Content-Type" => "text/html"}, ["cache cleared"]]
end
handle_route(req) click to toggle source

responses

# File lib/rack/pagelime.rb, line 34
def handle_route(req)
  if req.get?
    path    = req.path.gsub(/\A\/+|\/+\Z/, "")
    prefix  = ::Pagelime.config.url_path.gsub(/\A\/+|\/+\Z/, "")
    action  = path["#{prefix}/".size..-1].to_s
    
    # hijack response if a pagelime route, otherwise process output if so required
    if path.start_with?("#{prefix}/") || path == prefix
      case action
      # handle publish callback
      when "after_publish_callback"
        resp = handle_publish_callback(req)
      # handle "index"
      when ""
        resp = handle_status_check(req)
      else
        ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Unable to route action! (URL prefix: #{::Pagelime.config.url_path}, Request path: #{req.path})"
      end
    else
      ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Unable to route prefix! (URL prefix: #{::Pagelime.config.url_path}, Request path: #{req.path})"
    end
  end
  
  resp
end
handle_status_check(req) click to toggle source
# File lib/rack/pagelime.rb, line 70
def handle_status_check(req)
  
  ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Route for index called!"
  
  [200, {"Content-Type" => "text/html"}, ["working"]]
end
processing_enabled_for_request?(req) click to toggle source
# File lib/rack/pagelime.rb, line 23
def processing_enabled_for_request?(req)
  config_option = ::Pagelime.config.toggle_processing
  config_option = req.env[ENV_KEYS[:toggle_processing]] if config_option == "per_request"
  
  ::Pagelime.logger.debug  "PAGELIME CMS RACK PLUGIN: Procesing enabled for request? (config: #{::Pagelime.config.toggle_processing}, env: #{req.env[ENV_KEYS[:toggle_processing]]}, evaluated as: #{config_option})"
  
  return config_option == "on"
end