module ContentstackUtils::GQL

Public Class Methods

json_to_html(content, options) click to toggle source
# File lib/contentstack_utils/utils.rb, line 133
def self.json_to_html(content, options)
    embeddedItems = []
    if content.has_key? 'embedded_itemsConnection'
        embeddedItems = content['embedded_itemsConnection']['edges'] || []
    end            
    reference = -> (metadata){
        result = ""
        if embeddedItems != nil
            object = embeddedItems.select { |embedObject| embedObject['node']["system"]["uid"] == metadata.item_uid }
            if object != nil && object.length() > 0 
                result = options.render_option(object[0]["node"], metadata)
            end
        end
        result
    }         
   
    if content.has_key? 'json'
        json = content['json']
        if (json.instance_of? Array)
            result = []
            json.each do |n|
                result.push(ContentstackUtils.json_doc_to_html(n, options, reference))
            end
            result
        elsif json.instance_of? Hash
            ContentstackUtils.json_doc_to_html(json, options, reference)
        end
    end
end