Module: ContentstackUtils::GQL

Includes:
ContentstackUtils
Defined in:
lib/contentstack_utils/utils.rb

Constant Summary

Constants included from ContentstackUtils

VERSION

Class Method Summary collapse

Methods included from ContentstackUtils

json_doc_to_html, render_content

Class Method Details

.json_to_html(content, options) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/contentstack_utils/utils.rb', line 141

def self.json_to_html(content, options)
    embeddedItems = []
    if content.has_key? 'embedded_itemsConnection'
        embeddedItems = content['embedded_itemsConnection']['edges'] || []
    end            
    reference = -> (){
        result = ""
        if embeddedItems != nil
            object = embeddedItems.select { |embedObject| embedObject['node']["system"]["uid"] == .item_uid }
            if object != nil && object.length() > 0 
                result = options.render_option(object[0]["node"], )
            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