Skip to content

Instantly share code, notes, and snippets.

@benburkert
Created July 29, 2008 05:13
Show Gist options
  • Save benburkert/3020 to your computer and use it in GitHub Desktop.
Save benburkert/3020 to your computer and use it in GitHub Desktop.
# implementation
module Merb::Cache::CacheMixin
def fetch_partial(template, opts={}, conditions = {})
template_id = template.to_s
if template_id =~ %r{^/}
template_path = File.dirname(template_id) / "_#{File.basename(template_id)}"
else
kontroller = (m = template_id.match(/.*(?=\/)/)) ? m[0] : controller_name
template_id = "_#{File.basename(template_id)}"
end
unused, template_key = _template_for(template_id, opts.delete(:format) || content_type, kontroller, template_path)
Merb::Cache[_lookup_store(conditions)].fetch(template_key, opts, conditions) { partial(template, opts) }
end
end
# use
.main
.posts
-@posts.each do |post|
=fetch_partial :view, :post => post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment