Method: CacheReplace#render_cached
- Defined in:
- lib/cache_replace.rb
#render_cached(static_partial, options = {}) ⇒ Object
Supports 4 options:
-
Single partial to replace
render_cached "container", replace: "inner"
-
Array of partials to replace
render_cached "container", replace: ["inner"]
-
Map of keys to replace with values
render_cached "container", replace: {special_link: special_link(object)}
-
Yield to a hash of keys to replace with values
render_cached "container" do
{special_link: special_link(object)}
end
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cache_replace.rb', line 24 def render_cached(static_partial, ={}) replace = .delete(:replace) fragment = render(static_partial, ) case replace when Hash replace_from_hash fragment, replace when NilClass replace_from_hash fragment, yield else replace = *replace replace.each do |key| fragment.sub! cache_replace_key(key), render(key, ) end end raw fragment end |