Sha256: dd3a2ba1a650837df493ed1cb2abf036b8cf537ce9b507080cc43144f4ea2041

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require "caches_page_with_host/engine"
require "caches_page_with_host/version"

module CachesPageWithHost
  module ClassMethods
    def page_cache_file(path, extension)
      name = if path.empty?
        "/index"
      elsif path.end_with?("/")
        "#{path}index"
      else
        URI.parser.unescape(path.chomp('/'))
      end
      unless (name.split('/').last || name).include? '.'
        name << (extension || self.page_cache_extension)
      end
      return name
    end
  end

  module InstanceMethods
    def cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION)
      return unless self.class.perform_caching && caching_allowed?
      path = "/#{request.host}"
      path << case options
        when Hash
          url_for(options.merge(:only_path => true, :format => params[:format]))
        when String
          options
        else
          request.path
      end
      if (type = Mime::LOOKUP[self.content_type]) && (type_symbol = type.symbol).present?
        extension = ".#{type_symbol}"
      end
      self.class.cache_page(content || response.body, path, extension, gzip)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
caches_page_with_host-0.0.1 lib/caches_page_with_host.rb