提交 69e72af6 编写于 作者: J Jeremy Kemper

Improve readability

上级 f6520b7d
...@@ -61,16 +61,18 @@ def fragment_cache_key(key) ...@@ -61,16 +61,18 @@ def fragment_cache_key(key)
end end
def fragment_for(block, name = {}, options = nil) #:nodoc: def fragment_for(block, name = {}, options = nil) #:nodoc:
unless perform_caching then block.call; return end if perform_caching
buffer = yield
buffer = yield
if cache = read_fragment(name, options)
if cache = read_fragment(name, options) buffer.concat(cache)
buffer.concat(cache) else
pos = buffer.length
block.call
write_fragment(name, buffer[pos..-1], options)
end
else else
pos = buffer.length
block.call block.call
write_fragment(name, buffer[pos..-1], options)
end end
end end
......
...@@ -53,7 +53,9 @@ def compile(template) ...@@ -53,7 +53,9 @@ def compile(template)
end end
def cache_fragment(block, name = {}, options = nil) #:nodoc: def cache_fragment(block, name = {}, options = nil) #:nodoc:
@view.fragment_for(block, name, options) { @view.response.template.output_buffer ||= '' } @view.fragment_for(block, name, options) do
@view.response.template.output_buffer
end
end end
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册