@@ -24,8 +24,13 @@ def self.init_api(api_key, delivery_token, environment, host, branch, live_previ
24
24
end
25
25
26
26
def self . live_preview_query ( query = { } )
27
- @live_preview [ :content_type_uid ] = query [ :content_type_uid ]
28
- @live_preview [ :live_preview ] = query [ :live_preview ]
27
+ @live_preview [ :content_type_uid ] = query [ :content_type_uid ] || query [ "content_type_uid" ]
28
+ @live_preview [ :live_preview ] = query [ :live_preview ] || query [ "live_preview" ]
29
+ @live_preview [ :entry_uid ] = query [ :entry_uid ] || query [ "entry_uid" ]
30
+ if @live_preview [ :content_type_uid ] . present? && @live_preview [ :entry_uid ] . present?
31
+ path = "/content_types/#{ @live_preview [ :content_type_uid ] } /entries/#{ @live_preview [ :entry_uid ] } "
32
+ @live_preview_response = send_preview_request ( path )
33
+ end
29
34
end
30
35
31
36
def self . fetch_content_types ( uid = "" )
@@ -80,7 +85,7 @@ def self.fetch_retry(path, query=nil, count=0)
80
85
raise Contentstack ::Error . new ( response ) #Retry Limit exceeded
81
86
end
82
87
else
83
- response
88
+ to_render_content ( response )
84
89
end
85
90
end
86
91
@@ -184,5 +189,24 @@ def self.send_preview_request(path, q=nil)
184
189
raise Contentstack ::Error . new ( error . to_s )
185
190
end
186
191
end
192
+
193
+ def self . to_render_content ( resp )
194
+ if resp . class == Hash
195
+ if resp . key? ( 'uid' ) && resp [ 'uid' ] == @live_preview [ :entry_uid ]
196
+ resp = resp . merge ( @live_preview_response )
197
+ else
198
+ resp_keys = resp . keys
199
+ resp_keys . each { |key |
200
+ resp [ key ] = to_render_content ( resp [ key ] )
201
+ }
202
+ end
203
+ elsif resp . class == Array
204
+ resp . each_with_index { |value , index |
205
+ resp [ index ] = to_render_content ( value )
206
+ }
207
+ end
208
+ resp
209
+ end
210
+
187
211
end
188
212
end
0 commit comments