Sha256: bd38a8e95038bc1003b8ecd02a5d455d83e853667c97f4b664b0c17f54e5c207

Contents?: true

Size: 473 Bytes

Versions: 7

Compression:

Stored size: 473 Bytes

Contents

module ViewCaching
  def self.included(mod)
    mod.extend ClassMethods
  end
  module ClassMethods
    def view_cache
      @view_cache ||= {}
    end
  end

  def view_cache(&blk)
    cache = self.class.view_cache
    if cache.empty?
      cache[:body] = @body = yield
      cache[:doc] = @doc = Hpricot(@body)
    else
      @body = cache[:body]
      @doc = cache[:doc]
    end
  end

  def doc
    @doc
  end

  def body
    @body
  end
  alias_method :html, :body
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
erector-0.3.105 spec/view_caching.rb
erector-0.2.61 spec/view_caching.rb
erector-0.2.42 spec/view_caching.rb
erector-0.1.0 spec/view_caching.rb
erector-0.2.83 spec/view_caching.rb
erector-0.1.25 spec/view_caching.rb
erector-0.3.110 spec/view_caching.rb