Basic fragment class and renderer code. Need to be tested
This commit is contained in:
parent
1f36248f13
commit
79d6bb9c81
41
lib/rabl-fast-json/fragment.rb
Normal file
41
lib/rabl-fast-json/fragment.rb
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
require 'active_support/cache'
|
||||||
|
|
||||||
|
module RablFastJson
|
||||||
|
class Fragment
|
||||||
|
|
||||||
|
attr_reader :compiled_source, :options
|
||||||
|
|
||||||
|
def initialize(key, source, options = {})
|
||||||
|
@key = key
|
||||||
|
@compiled_source = source
|
||||||
|
@options = options
|
||||||
|
end
|
||||||
|
|
||||||
|
def expand_cache_key(data)
|
||||||
|
@key.call(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fetch_and_render
|
||||||
|
Rails.cache.fetch(key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# def cache(options = {}, &block)
|
||||||
|
# return unless block_given?
|
||||||
|
# key = options.delete(:key)
|
||||||
|
# source = sub_compiler { compile_block(&block) }
|
||||||
|
# @template[:"_cache#{cache_count}"] = Fragment.new(key, source, options)
|
||||||
|
# end
|
||||||
|
|
||||||
|
#
|
||||||
|
# when Fragment
|
||||||
|
# render_fragment(value)
|
||||||
|
#
|
||||||
|
|
||||||
|
# def render_fragment(data, fragment)
|
||||||
|
# Rails.cache.fetch(fragment.expand_cache_key(data), fragment.options) do
|
||||||
|
# render_resource(data, fragment.compiled_source)
|
||||||
|
# end
|
||||||
|
# end
|
Loading…
Reference in New Issue
Block a user