diff --git a/.gitignore b/.gitignore
index 1cbd975..14f42c2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-contentstack-*
+contentstack_utils-*
build_doc.sh
test
doc
@@ -7,4 +7,4 @@ coverage
\.yardoc
.DS_Store
.bundle/
-*/rspec_results.html
\ No newline at end of file
+**/rspec_results.html
\ No newline at end of file
diff --git a/lib/contentstack_utils/model/metadata.rb b/lib/contentstack_utils/model/metadata.rb
index 79882b9..2412082 100644
--- a/lib/contentstack_utils/model/metadata.rb
+++ b/lib/contentstack_utils/model/metadata.rb
@@ -3,29 +3,46 @@ module ContentstackUtils
module Model
class Metadata
def initialize( element )
- @itemType = element.attribute('type')
- @styleType = element.attribute('sys-style-type')
- @itemUid ||= element.attribute('data-sys-entry-uid') || element.attribute('data-sys-asset-uid')
- @contentTypeUid = element.attribute('data-sys-content-type-uid')
- @text = element.text
- @element = element
- @attributes = element.attributes
+ if element.instance_of? Nokogiri::XML::Element
+ @itemType = element.attribute('type') ? element.attribute('type').value : nil
+ @styleType = element.attribute('sys-style-type') ? element.attribute('sys-style-type').value : nil
+ @itemUid ||= (element.attribute('data-sys-entry-uid') ? element.attribute('data-sys-entry-uid').value : nil) || (element.attribute('data-sys-asset-uid') ? element.attribute('data-sys-asset-uid').value : nil)
+ @contentTypeUid = element.attribute('data-sys-content-type-uid') ? element.attribute('data-sys-content-type-uid').value : nil
+ @text = element.text
+ @element = element
+ @attributes = element
+ else
+ @itemType = element["attrs"]['type']
+ @styleType = element["attrs"]['display-type']
+ @itemUid ||= element["attrs"]['entry-uid'] || element["attrs"]['asset-uid']
+ @contentTypeUid = element["attrs"]['content-type-uid']
+ if element["children"] && element["children"].length() > 0
+ child = element["children"]
+ for item in child do
+ if item["type"] == nil && item["text"]
+ @text = item["text"]
+ end
+ end
+ end
+ @element = element
+ @attributes = element["attrs"]
+ end
end
def item_type
- @itemType ? @itemType.value : nil
+ @itemType ? @itemType : nil
end
def style_type
- @styleType ? @styleType.value : nil
+ @styleType ? @styleType : nil
end
def item_uid
- @itemUid ? @itemUid.value : nil
+ @itemUid ? @itemUid : nil
end
def content_type_uid
- @contentTypeUid ? @contentTypeUid.value : nil
+ @contentTypeUid ? @contentTypeUid : nil
end
def text
@@ -39,6 +56,14 @@ def element
def attributes
@attributes
end
+
+ def get_attribute_value(string)
+ if @attributes.instance_of? Nokogiri::XML::Element
+ @attributes.attribute(string) ? @attributes.attribute(string).value : nil
+ else
+ @attributes[string]
+ end
+ end
end
end
end
\ No newline at end of file
diff --git a/lib/contentstack_utils/model/options.rb b/lib/contentstack_utils/model/options.rb
index 857057c..0c6f818 100644
--- a/lib/contentstack_utils/model/options.rb
+++ b/lib/contentstack_utils/model/options.rb
@@ -5,7 +5,7 @@ module ContentstackUtils
module Model
class Options < Interface::Rendarable
- def initialize(entry)
+ def initialize(entry = nil)
@entry = entry
end
@@ -21,11 +21,90 @@ def render_option(embeddedObject, metadata)
when 'inline'
renderString = "#{embeddedObject["title"] || embeddedObject["uid"]}";
when 'link'
- renderString = "#{(metadata.text && metadata.text != '' ? metadata.text : (embeddedObject["title"] || embeddedObject["uid"]))}";
+ metadata.get_attribute_value("href")
+ renderString = "#{(metadata.text && metadata.text != '' ? metadata.text : (embeddedObject["title"] || embeddedObject["uid"]))}";
when 'display'
- renderString = "";
+ renderString = "";
when 'download'
- renderString = "#{(metadata.text && metadata.text != '' ? metadata.text : (embeddedObject["filename"] || embeddedObject["title"] || embeddedObject["uid"]))}";
+ renderString = "#{(metadata.text && metadata.text != '' ? metadata.text : (embeddedObject["filename"] || embeddedObject["title"] || embeddedObject["uid"]))}";
+ end
+ renderString
+ end
+
+ def render_mark(mark_type, text)
+ renderString = text
+ case mark_type
+ when 'bold'
+ renderString = "#{text}"
+ when 'italic'
+ renderString = "#{text}"
+ when 'underline'
+ renderString = "#{text}"
+ when 'strikethrough'
+ renderString = "#{text}"
+ when 'inlineCode'
+ renderString = "#{text}"
+ when 'subscript'
+ renderString = "#{text}"
+ when 'superscript'
+ renderString = "#{text}"
+ end
+ renderString
+ end
+
+ def render_node(node_type, node, inner_html)
+ renderString = ""
+ case node_type
+ when 'doc'
+ renderString = ""
+ when 'p'
+ renderString = "
#{inner_html}
"
+ when 'a'
+ renderString = "#{inner_html}"
+ when 'img'
+ renderString = "#{inner_html}"
+ when 'embed'
+ renderString = ""
+ when 'h1'
+ renderString = "
#{inner_html}
"
+ when 'h2'
+ renderString = "
#{inner_html}
"
+ when 'h3'
+ renderString = "
#{inner_html}
"
+ when 'h4'
+ renderString = "
#{inner_html}
"
+ when 'h5'
+ renderString = "
#{inner_html}
"
+ when 'h6'
+ renderString = "
#{inner_html}
"
+ when 'ol'
+ renderString = "#{inner_html}"
+ when 'ul'
+ renderString = "
#{inner_html}
"
+ when 'li'
+ renderString = "
#{inner_html}
"
+ when 'hr'
+ renderString = ""
+ when 'table'
+ renderString = "
#{inner_html}
"
+ when 'thead'
+ renderString = "#{inner_html}"
+ when 'tbody'
+ renderString = "#{inner_html}"
+ when 'tfoot'
+ renderString = "#{inner_html}"
+ when 'tr'
+ renderString = "
#{inner_html}
"
+ when 'th'
+ renderString = "
#{inner_html}
"
+ when 'td'
+ renderString = "
#{inner_html}
"
+ when 'blockquote'
+ renderString = "
#{inner_html}
"
+ when 'code'
+ renderString = "#{inner_html}"
+ when 'reference'
+ renderString = ""
end
renderString
end
diff --git a/lib/contentstack_utils/utils.rb b/lib/contentstack_utils/utils.rb
index 5e745bb..5b103fc 100644
--- a/lib/contentstack_utils/utils.rb
+++ b/lib/contentstack_utils/utils.rb
@@ -16,6 +16,83 @@ def self.render_content(content, options)
end
end
+ def self.json_to_html(content, options)
+ if (content.instance_of? Array)
+ result = []
+ content.each do |n|
+ result.push(json_doc_to_html(n, options))
+ end
+ result
+ elsif content.instance_of? Hash
+ json_doc_to_html(content, options)
+ end
+ end
+
+ private_class_method def self.json_doc_to_html(node, options)
+ result = ""
+ if node["children"] && node["children"].length() > 0
+ result = node_children_to_html(node["children"], options)
+ end
+ result
+ end
+
+ private_class_method def self.node_children_to_html(nodes, options)
+ nodes.map {|node| node_to_html(node, options)}.join("")
+ end
+
+ private_class_method def self.node_to_html(node, options)
+ html_result = ""
+ if node["type"] == nil && node["text"]
+ html_result = text_to_htms(node, options)
+ elsif node["type"]
+ if node["type"] == "reference"
+ html_result = reference_to_html(node, options)
+ else
+ inner_html = json_doc_to_html(node, options)
+ html_result = options.render_node(node["type"], node, inner_html)
+ end
+ end
+ html_result
+ end
+
+ private_class_method def self.text_to_htms(node, options)
+ text = node["text"]
+ if node["superscript"]
+ text = options.render_mark("superscript", text)
+ end
+ if node["subscript"]
+ text = options.render_mark("subscript", text)
+ end
+ if node["inlineCode"]
+ text = options.render_mark("inlineCode", text)
+ end
+ if node["strikethrough"]
+ text = options.render_mark("strikethrough", text)
+ end
+ if node["underline"]
+ text = options.render_mark("underline", text)
+ end
+ if node["italic"]
+ text = options.render_mark("italic", text)
+ end
+ if node["bold"]
+ text = options.render_mark("bold", text)
+ end
+ text
+ end
+
+ private_class_method def self.reference_to_html(node, options)
+ result = ""
+ if options.entry != nil
+ metadata = Model::Metadata.new(node)
+ object = findObject(metadata, options.entry)
+ if object!= nil && object.length() > 0
+ result = options.render_option(object[0], metadata)
+ end
+ end
+ result
+ end
+
private_class_method def self.render_string(string, options)
xml_doc = Nokogiri::HTML(appendFrame(string))
result = xml_doc.xpath('//documentfragmentcontainer').inner_html
diff --git a/spec/lib/model/metadata_spec.rb b/spec/lib/model/metadata_spec.rb
index ac9698a..6c4aa65 100644
--- a/spec/lib/model/metadata_spec.rb
+++ b/spec/lib/model/metadata_spec.rb
@@ -51,5 +51,45 @@
expect(metadata.text).to eq 'TEST'
end
end
+
+ it 'Asset Json To metadata' do
+ doc = getJson(AssetReferenceJson)
+ metadata = ContentstackUtils::Model::Metadata.new(doc["children"][0])
+ expect(metadata.item_type).to eq "asset"
+ expect(metadata.style_type).to eq "display"
+ expect(metadata.item_uid).to eq "blt44asset"
+ expect(metadata.content_type_uid).to eq 'sys_assets'
+ expect(metadata.text).to eq ''
+ end
+
+ it 'Entry Block Json To metadata' do
+ doc = getJson(EntryReferenceBlockJson)
+ metadata = ContentstackUtils::Model::Metadata.new(doc["children"][0])
+ expect(metadata.item_type).to eq "entry"
+ expect(metadata.style_type).to eq "block"
+ expect(metadata.item_uid).to eq "blttitleuid"
+ expect(metadata.content_type_uid).to eq 'content_block'
+ expect(metadata.text).to eq ''
+ end
+
+ it 'Entry Link Json To metadata' do
+ doc = getJson(EntryReferenceLinkJson)
+ metadata = ContentstackUtils::Model::Metadata.new(doc["children"][0])
+ expect(metadata.item_type).to eq "entry"
+ expect(metadata.style_type).to eq "link"
+ expect(metadata.item_uid).to eq "bltemmbedEntryuid"
+ expect(metadata.content_type_uid).to eq 'embeddedrte'
+ expect(metadata.text).to eq "/copy-of-entry-final-02"
+ end
+
+ it 'Entry Inline Json To metadata' do
+ doc = getJson(EntryReferenceInlineJson)
+ metadata = ContentstackUtils::Model::Metadata.new(doc["children"][0])
+ expect(metadata.item_type).to eq "entry"
+ expect(metadata.style_type).to eq "inline"
+ expect(metadata.item_uid).to eq "blttitleUpdateuid"
+ expect(metadata.content_type_uid).to eq 'embeddedrte'
+ expect(metadata.text).to eq ''
+ end
end
end
\ No newline at end of file
diff --git a/spec/lib/model/option_spec.rb b/spec/lib/model/option_spec.rb
index db6e828..20b2807 100644
--- a/spec/lib/model/option_spec.rb
+++ b/spec/lib/model/option_spec.rb
@@ -82,5 +82,221 @@ def getMetadata(itemType=nil, styleType=nil, linkText=nil)
expect(subject.render_option(ASSET_CONTENT_URL, getMetadata('entry', 'download', linkText))).
to eq "#{linkText}"
end
+
+ it 'Should return Mark text html' do
+ expect(subject.render_mark('bold', linkText)).
+ to eq "#{linkText}"
+ expect(subject.render_mark('italic', linkText)).
+ to eq "#{linkText}"
+ expect(subject.render_mark('underline', linkText)).
+ to eq "#{linkText}"
+ expect(subject.render_mark('strikethrough', linkText)).
+ to eq "#{linkText}"
+ expect(subject.render_mark('inlineCode', linkText)).
+ to eq "#{linkText}"
+ expect(subject.render_mark('subscript', linkText)).
+ to eq "#{linkText}"
+ expect(subject.render_mark('superscript', linkText)).
+ to eq "#{linkText}"
+ expect(subject.render_mark('', linkText)).
+ to eq linkText
+ end
+
+ it 'Should return blank string for doc node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('doc', doc, linkText)
+ expect(result).to eq ""
+ end
+
+ it 'Should return paragraph string for paragrpah node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('p', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return link string with blank href for link node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('a', doc, linkText)
+ expect(result).to eq "#{linkText}"
+ end
+
+ it 'Should return link string for link node type' do
+ doc = getJson(LinkInPJson)["children"][0]
+
+ result = subject.render_node('a', doc, linkText)
+ expect(result).to eq "#{linkText}"
+ end
+
+ it 'Should return image string with blank src for image node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('img', doc, linkText)
+ expect(result).to eq "#{linkText}"
+ end
+
+ it 'Should return link string for link node type' do
+ doc = getJson(ImgJson)["children"][0]
+
+ result = subject.render_node('img', doc, linkText)
+ expect(result).to eq "#{linkText}"
+ end
+
+ it 'Should return embed string with blank src for embed node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('embed', doc, linkText)
+ expect(result).to eq ""
+ end
+
+ it 'Should return embed string for embed node type' do
+ doc = getJson(EmbedJson)["children"][0]
+
+ result = subject.render_node('embed', doc, linkText)
+ expect(result).to eq ""
+ end
+
+ it 'Should return Heading 1 string for Heading 1 node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('h1', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return Heading 2 string for Heading 2 node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('h2', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return Heading 3 string for Heading 3 node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('h3', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return Heading 4 string for Heading 4 node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('h4', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return Heading 5 string for Heading 5 node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('h5', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return Heading 6 string for Heading 6 node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('h6', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return Hr string for Hr node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('hr', doc, linkText)
+ expect(result).to eq ""
+ end
+
+ it 'Should return order list string for order list node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('ol', doc, linkText)
+ expect(result).to eq "#{linkText}"
+ end
+
+ it 'Should return Unorder list string for Unorder list node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('ul', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return list item string for list item node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('li', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return table string for table node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('table', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return thead string for thead node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('thead', doc, linkText)
+ expect(result).to eq "#{linkText}"
+ end
+
+ it 'Should return tfoot string for tfoot node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('tfoot', doc, linkText)
+ expect(result).to eq "#{linkText}"
+ end
+
+ it 'Should return tbody string fortbody node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('tbody', doc, linkText)
+ expect(result).to eq "#{linkText}"
+ end
+
+ it 'Should return table row string for table row node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('tr', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return table head string for table head node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('th', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return table data string for table data node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('td', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return blockquote string for blockquote node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('blockquote', doc, linkText)
+ expect(result).to eq "
#{linkText}
"
+ end
+
+ it 'Should return code string for code node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('code', doc, linkText)
+ expect(result).to eq "#{linkText}"
+ end
+
+ it 'Should return blank string for reference node type' do
+ doc = getJson(BlankDocument)
+
+ result = subject.render_node('reference', doc, linkText)
+ expect(result).to eq ""
+ end
+
end
end
\ No newline at end of file
diff --git a/spec/lib/utils_spec.rb b/spec/lib/utils_spec.rb
index 2966e9a..2fcb3b1 100644
--- a/spec/lib/utils_spec.rb
+++ b/spec/lib/utils_spec.rb
@@ -59,6 +59,350 @@
end
end
+
+ describe '#JsonToHtml Array' do
+ it 'Should return blank string for blank doc' do
+ doc = getJson(BlankDocument)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [""]
+ end
+
+ it 'Should return mark text string for PlainTextJson doc' do
+ doc = getJson(PlainTextJson)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [PlainTextHtml]
+ end
+
+ it 'Should return paragraph string for ParagraphJson doc' do
+ doc = getJson(ParagraphJson)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [ParagraphHtml]
+ end
+
+ it 'Should return H1 string for H1Json doc' do
+ doc = getJson(H1Json)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [H1Html]
+ end
+
+ it 'Should return H2 string for H2Json doc' do
+ doc = getJson(H2Json)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [H2Html]
+ end
+
+ it 'Should return H3 string for H3Json doc' do
+ doc = getJson(H3Json)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [H3Html]
+ end
+
+ it 'Should return H4 string for H4Json doc' do
+ doc = getJson(H4Json)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [H4Html]
+ end
+
+ it 'Should return H5 string for H5Json doc' do
+ doc = getJson(H5Json)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [H5Html]
+ end
+
+ it 'Should return H6 string for H6Json doc' do
+ doc = getJson(H6Json)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [H6Html]
+ end
+
+ it 'Should return Order List string for OrderListJson doc' do
+ doc = getJson(OrderListJson)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [OrderListHtml]
+ end
+
+ it 'Should return Unorder List string for UnorderListJson doc' do
+ doc = getJson(UnorderListJson)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [UnorderListHtml]
+ end
+
+ it 'Should return image string for ImgJson doc' do
+ doc = getJson(ImgJson)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [ImgHtml]
+ end
+
+ it 'Should return Blockquote string for BlockquoteJson doc' do
+ doc = getJson(BlockquoteJson)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [BlockquoteHtml]
+ end
+
+ it 'Should return Code string for CodeJson doc' do
+ doc = getJson(CodeJson)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [CodeHtml]
+ end
+
+ it 'Should return Table string for TableJson doc' do
+ doc = getJson(TableJson)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [TableHtml]
+ end
+
+ it 'Should return Link string for LinkInPJson doc' do
+ doc = getJson(LinkInPJson)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [LinkInPHtml]
+ end
+
+ it 'Should return Embed string for EmbedJson doc' do
+ doc = getJson(EmbedJson)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq [EmbedHtml]
+ end
+
+ it 'Should return horizontal line string for horizontal line doc' do
+ doc = getJson(HRJson)
+
+ result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq ['']
+ end
+ end
+
+ describe '#JsonToHtml' do
+ it 'Should return blank string for blank doc' do
+ doc = getJson(BlankDocument)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq ""
+ end
+
+ it 'Should return mark text string for PlainTextJson doc' do
+ doc = getJson(PlainTextJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq PlainTextHtml
+ end
+
+ it 'Should return paragraph string for ParagraphJson doc' do
+ doc = getJson(ParagraphJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq ParagraphHtml
+ end
+
+ it 'Should return H1 string for H1Json doc' do
+ doc = getJson(H1Json)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq H1Html
+ end
+
+ it 'Should return H2 string for H2Json doc' do
+ doc = getJson(H2Json)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq H2Html
+ end
+
+ it 'Should return H3 string for H3Json doc' do
+ doc = getJson(H3Json)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq H3Html
+ end
+
+ it 'Should return H4 string for H4Json doc' do
+ doc = getJson(H4Json)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq H4Html
+ end
+
+ it 'Should return H5 string for H5Json doc' do
+ doc = getJson(H5Json)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq H5Html
+ end
+
+ it 'Should return H6 string for H6Json doc' do
+ doc = getJson(H6Json)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq H6Html
+ end
+
+ it 'Should return Order List string for OrderListJson doc' do
+ doc = getJson(OrderListJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq OrderListHtml
+ end
+
+ it 'Should return Unorder List string for UnorderListJson doc' do
+ doc = getJson(UnorderListJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq UnorderListHtml
+ end
+
+ it 'Should return image string for ImgJson doc' do
+ doc = getJson(ImgJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq ImgHtml
+ end
+
+ it 'Should return Blockquote string for BlockquoteJson doc' do
+ doc = getJson(BlockquoteJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq BlockquoteHtml
+ end
+
+ it 'Should return Code string for CodeJson doc' do
+ doc = getJson(CodeJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq CodeHtml
+ end
+
+ it 'Should return Table string for TableJson doc' do
+ doc = getJson(TableJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq TableHtml
+ end
+
+ it 'Should return Link string for LinkInPJson doc' do
+ doc = getJson(LinkInPJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq LinkInPHtml
+ end
+
+ it 'Should return Embed string for EmbedJson doc' do
+ doc = getJson(EmbedJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq EmbedHtml
+ end
+
+ it 'Should return horizontal line string for horizontal line doc' do
+ doc = getJson(HRJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq ''
+ end
+
+ it 'Should return horizontal line string for horizontal line doc' do
+ doc = getJson(H1NonChildJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq ''
+ end
+ end
+
+ describe '#JsonToHtml reference' do
+ it 'Should return blank string for non entry option' do
+ doc = getJson(AssetReferenceJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
+
+ expect(result).to eq ''
+ end
+
+ it 'Should return asset embedded items' do
+ doc = getJson(AssetReferenceJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new(JSON_EMBEDDED_ITEMS_ENTRY))
+
+ expect(result).to eq AssetReferenceHtml
+ end
+
+ it 'Should return entry block embedded items' do
+ doc = getJson(EntryReferenceBlockJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new(JSON_EMBEDDED_ITEMS_ENTRY))
+
+ expect(result).to eq EntryReferenceBlockHtml
+ end
+
+ it 'Should return entry link embedded items' do
+ doc = getJson(EntryReferenceLinkJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new(JSON_EMBEDDED_ITEMS_ENTRY))
+
+ expect(result).to eq EntryReferenceLinkHtml
+ end
+
+ it 'Should return entry inline embedded items' do
+ doc = getJson(EntryReferenceInlineJson)
+
+ result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new(JSON_EMBEDDED_ITEMS_ENTRY))
+
+ expect(result).to eq EntryReferenceInlineHtml
+ end
+
+ end
+
def makeRenderFunction(content, option = ContentstackUtils::Model::Options.new(ENTRY_EMBEDDED_ASSET))
ContentstackUtils.render_content(content, option)
end
diff --git a/spec/mock/json_to_html_mock.rb b/spec/mock/json_to_html_mock.rb
new file mode 100644
index 0000000..d3a63a8
--- /dev/null
+++ b/spec/mock/json_to_html_mock.rb
@@ -0,0 +1,145 @@
+
+PlainTextHtml = "Aliquam sit amet libero dapibus, eleifend ligula at, varius justoLorem ipsumdolor sit ametconsectetur adipiscing elit.Sed condimentum iaculis magna in vehicula. Vestibulum vitae convallis lacus. "
+ParagraphHtml = "
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed condimentum iaculis magna in vehicula. Vestibulum vitae convallis lacus. Praesent a diam iaculis turpis rhoncus faucibus. Aliquam sed pulvinar sem.
"
+H1Html = "
Lorem ipsum dolor sit amet.
"
+H2Html = "
Vestibulum a ligula eget massa sagittis aliquam sit amet quis tortor.
"
+H3Html = "
Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.
"
+H4Html = "
MaNullam feugiat turpis quis elit interdum, vitae laoreet quam viverra
"
+H5Html = "
Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.
"
+H6Html = "
Nunc porta diam vitae purus semper, ut consequat lorem vehicula.
"
+OrderListHtml = "
Morbi in quam molestie, fermentum diam vitae, bibendum ipsum.
Pellentesque mattis lacus in quam aliquam congue
Integer feugiat leo dignissim, lobortis enim vitae, mollis lectus.
Sed in ante lacinia, molestie metus eu, fringilla sapien.
"
+UnorderListHtml = "
Sed quis metus sed mi hendrerit mollis vel et odio.
Integer vitae sem dignissim, elementum libero vel, fringilla massa.
Integer imperdiet arcu sit amet tortor faucibus aliquet.
Aenean scelerisque velit vitae dui vehicula, at congue massa sagittis.