From 9571d35d981cfeb69eae4673dadb84e3d01cb641 Mon Sep 17 00:00:00 2001 From: Michael Ginalick Date: Wed, 22 Feb 2023 15:05:58 -0600 Subject: [PATCH 1/3] Support span tags in rendering description --- lib/contentstack_utils/model/options.rb | 4 +++- spec/lib/model/option_spec.rb | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/contentstack_utils/model/options.rb b/lib/contentstack_utils/model/options.rb index 5db11c9..94abecb 100644 --- a/lib/contentstack_utils/model/options.rb +++ b/lib/contentstack_utils/model/options.rb @@ -105,9 +105,11 @@ def render_node(node_type, node, inner_html) renderString = "#{inner_html}" when 'reference' renderString = "" + when 'span' + renderString = "#{inner_html}" end renderString 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 9e4f3ff..40bb228 100644 --- a/spec/lib/model/option_spec.rb +++ b/spec/lib/model/option_spec.rb @@ -305,5 +305,12 @@ def getMetadata(itemType=nil, styleType=nil, linkText=nil) expect(result).to eq "" end + it 'Should return span string for reference node type' do + doc = getJson(BlankDocument) + + result = subject.render_node('span', doc, linkText) + expect(result).to eq "#{linkText}" + end + end -end \ No newline at end of file +end From c02992474e1c7fa5f302bb8633f650eb0b781c79 Mon Sep 17 00:00:00 2001 From: Eric Agnew Date: Tue, 21 Mar 2023 21:03:59 -0500 Subject: [PATCH 2/3] Collect all text items, not just the last item --- lib/contentstack_utils/model/metadata.rb | 37 ++++++++++++------------ spec/mock/json_to_html_mock.rb | 3 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/contentstack_utils/model/metadata.rb b/lib/contentstack_utils/model/metadata.rb index 2412082..303b786 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"] - for item in child do - if item["type"] == nil && item["text"] - @text = item["text"] - end - end - end + + @text = child.reduce([]) do |texts, item| + texts << item["text"] if item["type"].nil? && item["text"] + + texts + end.join + 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/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}}]}' From 5739cbbd9306ac6778a15cae7decbce55672fee5 Mon Sep 17 00:00:00 2001 From: Eric Agnew Date: Wed, 22 Mar 2023 09:52:52 -0500 Subject: [PATCH 3/3] Keep as close to original implementation as possible --- lib/contentstack_utils/model/metadata.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/contentstack_utils/model/metadata.rb b/lib/contentstack_utils/model/metadata.rb index 303b786..ede348c 100644 --- a/lib/contentstack_utils/model/metadata.rb +++ b/lib/contentstack_utils/model/metadata.rb @@ -18,12 +18,12 @@ def initialize( element ) @contentTypeUid = element["attrs"]['content-type-uid'] if element["children"] && element["children"].length() > 0 child = element["children"] - - @text = child.reduce([]) do |texts, item| - texts << item["text"] if item["type"].nil? && item["text"] - - texts - end.join + @text = "" + for item in child do + if item["type"] == nil && item["text"] + @text += item["text"] + end + end end @element = element @attributes = element["attrs"]