| 1 | module ActionController::Caching::Fragments
|
|---|
| 2 | # Called by Markaby::Builder#cache. Imitate cache_erb_template.
|
|---|
| 3 | def cache_markaby_fragment(block, name = {}, options = nil)
|
|---|
| 4 | if perform_caching
|
|---|
| 5 | # check if already cached, otherwise calculate and write
|
|---|
| 6 | cache = read_fragment(name, options) ||
|
|---|
| 7 | write_fragment(name, block.call, options)
|
|---|
| 8 | else # don't cache
|
|---|
| 9 | cache = block.call
|
|---|
| 10 | end
|
|---|
| 11 | options[:builder] << cache
|
|---|
| 12 | end
|
|---|
| 13 | end
|
|---|
| 14 |
|
|---|
| 15 | class Markaby::Builder
|
|---|
| 16 | # Use this method like you would do in a rhtml template.
|
|---|
| 17 | #
|
|---|
| 18 | # See Rails' ActionController::Caching::Fragments for documentation:
|
|---|
| 19 | # http://api.rubyonrails.com/classes/ActionController/Caching/Fragments.html
|
|---|
| 20 | def cache name, &block
|
|---|
| 21 | @helpers.controller.cache_markaby_fragment(block, name, :builder => self)
|
|---|
| 22 | end
|
|---|
| 23 | end
|
|---|