2012-02-22 18:14:00 +00:00
|
|
|
module RablFastJson
|
|
|
|
class CompiledTemplate
|
|
|
|
|
2012-02-23 11:56:45 +00:00
|
|
|
attr_accessor :source, :data, :root_name
|
2012-02-22 18:14:00 +00:00
|
|
|
|
|
|
|
delegate :[], :[]=, :to => :source
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@source = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# def render(data = nil)
|
|
|
|
# output = {}
|
|
|
|
# @data = data if data
|
|
|
|
#
|
|
|
|
# return render_collection if @data.respond_to?(:each)
|
|
|
|
#
|
|
|
|
# @template.each_pair { |key, value|
|
|
|
|
# out = case value
|
|
|
|
# when Symbol
|
|
|
|
# @data.send(value)
|
|
|
|
# end
|
|
|
|
# output[key] = out
|
|
|
|
# }
|
|
|
|
# output
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def render_collection
|
|
|
|
# output = []
|
|
|
|
# @data.each { |o|
|
|
|
|
# object = {}
|
|
|
|
# @template.each_pair { |key, value|
|
|
|
|
# out = case value
|
|
|
|
# when Symbol
|
|
|
|
# o.send(value)
|
|
|
|
# end
|
|
|
|
# object[key] = out
|
|
|
|
# }
|
|
|
|
# output << object
|
|
|
|
# }
|
|
|
|
# output
|
|
|
|
# end
|
|
|
|
end
|
|
|
|
end
|