diff --git a/lib/contentstack_utils/model/metadata.rb b/lib/contentstack_utils/model/metadata.rb index 2412082..ede348c 100644 --- a/lib/contentstack_utils/model/metadata.rb +++ b/lib/contentstack_utils/model/metadata.rb @@ -1,7 +1,7 @@ module ContentstackUtils module Model - class Metadata + class Metadata def initialize( element ) if element.instance_of? Nokogiri::XML::Element @itemType = element.attribute('type') ? element.attribute('type').value : nil @@ -16,44 +16,45 @@ def initialize( element ) @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 + if element["children"] && element["children"].length() > 0 child = element["children"] + @text = "" for item in child do - if item["type"] == nil && item["text"] - @text = item["text"] + if item["type"] == nil && item["text"] + @text += item["text"] end end - end + end @element = element @attributes = element["attrs"] end end - def item_type + def item_type @itemType ? @itemType : nil end - def style_type + def style_type @styleType ? @styleType : nil end - def item_uid + def item_uid @itemUid ? @itemUid : nil end - def content_type_uid + def content_type_uid @contentTypeUid ? @contentTypeUid : nil end - def text + def text @text end - def element + def element @element end - - def attributes + + def attributes @attributes end @@ -62,8 +63,8 @@ def get_attribute_value(string) @attributes.attribute(string) ? @attributes.attribute(string).value : nil else @attributes[string] - end + end end end end -end \ No newline at end of file +end diff --git a/spec/lib/model/option_spec.rb b/spec/lib/model/option_spec.rb index 23be650..d590621 100644 --- a/spec/lib/model/option_spec.rb +++ b/spec/lib/model/option_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -def getMetadata(itemType=nil, styleType=nil, linkText=nil) +def getMetadata(itemType=nil, styleType=nil, linkText=nil) html = "#{linkText || ''}"; element = getElement(html, '//test')[0] ContentstackUtils::Model::Metadata.new(element) @@ -104,203 +104,203 @@ def getMetadata(itemType=nil, styleType=nil, linkText=nil) 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 link string for link node type' do doc = getJson(ImgJsonURL)["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 "" 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 diff --git a/spec/mock/json_to_html_mock.rb b/spec/mock/json_to_html_mock.rb index 170067b..8a002b5 100644 --- a/spec/mock/json_to_html_mock.rb +++ b/spec/mock/json_to_html_mock.rb @@ -42,6 +42,7 @@ EntryReferenceBlockJson = '{ "uid":"06e34a7 5e4 e549d ", "_version":1, "attrs":{ }, "children":[{"uid":"70f9b 325075d43 128c0d0 aa3eb7f291f","type":"reference","attrs":{"display-type":"block","entry-uid":"entry_uid_1","content-type-uid":"content_block","locale":"en-us","type":"entry","class-name":"embedded-entry"},"children":[{"text":""}]}],"type":"doc"}' EntryReferenceLinkJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":{ }, "children":[{"uid":"7626ea98e0e95d602210","type":"reference","attrs":{"target":"_self","href":"/copy-of-entry-final-02","display-type":"link","entry-uid":"entry_uid_2","content-type-uid":"embeddedrte","locale":"en-us","type":"entry","class-name":"embedded-entry"},"children":[{"text":"/copy-of-entry-final-02"}]}],"type":"doc"}' EntryReferenceInlineJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":{ }, "children":[{"uid":"506 4878f3f46 s21f0cbc aff","type":"reference","attrs":{"display-type":"inline","entry-uid":"entry_uid_3","content-type-uid":"embeddedrte","locale":"en-us","type":"entry","class-name":"embedded-entry"},"children":[{"text":""}]}],"type":"doc"}' +EntryReferenceLinkTextJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":{ }, "children":[{"uid":"7626ea98e0e95d602210","type":"reference","attrs":{"target":"_self","href":"/copy-of-entry-final-02","display-type":"link","entry-uid":"entry_uid_3","content-type-uid":"embeddedrte","locale":"en-us","type":"entry","class-name":"embedded-entry"},"children":[{"text":"L\'Oreal Paris Telescopic Lift "},{"text":"Washable","italic":true},{"text":" Mascara"}]}],"type":"doc"}' HRJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":{ }, "children":[{"uid":"f5a7b57 40a8a5c3 576828276b","type":"hr","children":[{"text":""}],"attrs":{ }}],"type":"doc"}' H1NonChildJson = '{ "uid":"06e34a7a449d7fc2acd","_version":13,"attrs":{ },"children":[{ "type":"h1","attrs":{ },"uid":"c2dfed70 4d7030c65e2e1"}],"type":"doc"}' @@ -144,4 +145,4 @@ } } - EmbedEdges = '{"edges":[{"node":{"system":{"content_type_uid":"sys_assets","uid":"entry_uid_5"},"created_at":"2020-08-19T09:13:05.864Z","updated_at":"2020-09-10T09:35:28.393Z","created_by":"created_at_date","updated_by":"created_at_date","content_type":"image/png","file_size":"36743","filename":"svg-logo-text.png","url":"/v3/svg-logo-text.png","_version":7,"title":"svg-logo-text.png","description":""}},{"node":{"system":{"content_type_uid":"sys_assets","uid":"asset_uid_1"},"created_at":"2020-08-19T09:13:32.785Z","updated_at":"2020-08-19T09:13:32.785Z","created_by":"created_at_date","updated_by":"created_at_date","content_type":"application/pdf","file_size":"13264","filename":"title","url":"/v3/dummy.pdf","_version":1,"title":"dummy.pdf"}},{"node":{"title":"Update this title","url":"","locale":"en-us","system":{"uid":"entry_uid_1","content_type_uid":"content_block"},"_version":5,"_in_progress":false,"multi_line":"","rich_text_editor":""}},{"node":{"title":"updated title","rich_text_editor":[""],"locale":"en-us","system":{"uid":"entry_uid_3","content_type_uid":"embeddedrte"},"_in_progress":false}},{"node":{"title":"Entry with embedded entry","rich_text_editor":[""],"locale":"en-us","system":{"uid":"entry_uid_2","content_type_uid":"embeddedrte"},"_in_progress":false}},{"node":{"system":{"uid":"entry_uid_6","content_type_uid":"sys_assets"},"content_type":"image/png","file_size":"36743","filename":"svg-logo-text.png","url":"/v3/svg-logo-text.png","title":"svg-logo-text.png","description":""}},{"node":{"title":"Update this title","url":"","locale":"en-us","system":{"uid":"entry_uid_1","content_type_uid":"content_block"},"_version":5,"_in_progress":false,"multi_line":"","rich_text_editor":""}},{"node":{"title":"updated title","rich_text_editor":[""],"locale":"en-us","system":{"uid":"entry_uid_3","content_type_uid":"embeddedrte"},"_in_progress":false}},{"node":{"title":"Entry with embedded entry","rich_text_editor":[""],"locale":"en-us","system":{"uid":"entry_uid_2","content_type_uid":"embeddedrte"},"_in_progress":false}}]}' \ No newline at end of file + EmbedEdges = '{"edges":[{"node":{"system":{"content_type_uid":"sys_assets","uid":"entry_uid_5"},"created_at":"2020-08-19T09:13:05.864Z","updated_at":"2020-09-10T09:35:28.393Z","created_by":"created_at_date","updated_by":"created_at_date","content_type":"image/png","file_size":"36743","filename":"svg-logo-text.png","url":"/v3/svg-logo-text.png","_version":7,"title":"svg-logo-text.png","description":""}},{"node":{"system":{"content_type_uid":"sys_assets","uid":"asset_uid_1"},"created_at":"2020-08-19T09:13:32.785Z","updated_at":"2020-08-19T09:13:32.785Z","created_by":"created_at_date","updated_by":"created_at_date","content_type":"application/pdf","file_size":"13264","filename":"title","url":"/v3/dummy.pdf","_version":1,"title":"dummy.pdf"}},{"node":{"title":"Update this title","url":"","locale":"en-us","system":{"uid":"entry_uid_1","content_type_uid":"content_block"},"_version":5,"_in_progress":false,"multi_line":"","rich_text_editor":""}},{"node":{"title":"updated title","rich_text_editor":[""],"locale":"en-us","system":{"uid":"entry_uid_3","content_type_uid":"embeddedrte"},"_in_progress":false}},{"node":{"title":"Entry with embedded entry","rich_text_editor":[""],"locale":"en-us","system":{"uid":"entry_uid_2","content_type_uid":"embeddedrte"},"_in_progress":false}},{"node":{"system":{"uid":"entry_uid_6","content_type_uid":"sys_assets"},"content_type":"image/png","file_size":"36743","filename":"svg-logo-text.png","url":"/v3/svg-logo-text.png","title":"svg-logo-text.png","description":""}},{"node":{"title":"Update this title","url":"","locale":"en-us","system":{"uid":"entry_uid_1","content_type_uid":"content_block"},"_version":5,"_in_progress":false,"multi_line":"","rich_text_editor":""}},{"node":{"title":"updated title","rich_text_editor":[""],"locale":"en-us","system":{"uid":"entry_uid_3","content_type_uid":"embeddedrte"},"_in_progress":false}},{"node":{"title":"Entry with embedded entry","rich_text_editor":[""],"locale":"en-us","system":{"uid":"entry_uid_2","content_type_uid":"embeddedrte"},"_in_progress":false}}]}'