From 35fbec2f1e036103a5ea42f2f5105d866f2545ea Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:14:54 +0530 Subject: [PATCH 1/8] Added support for the
tag and support for nested assets in the the image --- lib/contentstack_utils/model/options.rb | 4 ++++ lib/contentstack_utils/utils.rb | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/contentstack_utils/model/options.rb b/lib/contentstack_utils/model/options.rb index 94abecb..fcb76c6 100644 --- a/lib/contentstack_utils/model/options.rb +++ b/lib/contentstack_utils/model/options.rb @@ -48,6 +48,8 @@ def render_mark(mark_type, text) renderString = "#{text}" when 'superscript' renderString = "#{text}" + when 'br' + renderString = "
" end renderString end @@ -85,6 +87,8 @@ def render_node(node_type, node, inner_html) renderString = "
  • #{inner_html}
  • " when 'hr' renderString = "
    " + when 'br' + renderString = "
    " when 'table' renderString = "#{inner_html}
    " when 'thead' diff --git a/lib/contentstack_utils/utils.rb b/lib/contentstack_utils/utils.rb index 1bb338b..52053a4 100644 --- a/lib/contentstack_utils/utils.rb +++ b/lib/contentstack_utils/utils.rb @@ -23,6 +23,11 @@ def self.json_to_html(content, options) object = findObject(metadata, options.entry) if object!= nil && object.length() > 0 result = options.render_option(object[0], metadata) + else + content.each do |node| + inner_html = json_doc_to_html(node, options, reference) + result = options.render_node(node["type"], node, inner_html) + end end end result From 0309da373cd89657c87bbc738d5e2b6951f8c0b1 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:22:16 +0530 Subject: [PATCH 2/8] Added version and change log --- CHANGELOG.md | 2 ++ lib/contentstack_utils/version.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7ef236..2493c79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## [1.1.4](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.1.4) (2023-06-20) + - Support for nested assets in the the image and br tag ## [1.1.3](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.1.3) (2023-03-16) - Dependency gem max version issue resolved. (Activesupport gem) diff --git a/lib/contentstack_utils/version.rb b/lib/contentstack_utils/version.rb index 95ed36c..29b3e9a 100644 --- a/lib/contentstack_utils/version.rb +++ b/lib/contentstack_utils/version.rb @@ -1,3 +1,3 @@ module ContentstackUtils - VERSION = "1.1.3" + VERSION = "1.1.4" end \ No newline at end of file From 86b040ff45d243e083401b5139a78734b2eb72bf Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Tue, 20 Jun 2023 17:56:11 +0530 Subject: [PATCH 3/8] Added Testcases --- Gemfile.lock | 36 ++++++++++--------------- lib/contentstack_utils/model/options.rb | 7 ++++- spec/lib/utils_spec.rb | 15 +++++++++++ spec/mock/json_to_html_mock.rb | 1 + 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 70a93d4..cd1e810 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,20 +1,17 @@ PATH remote: . specs: - contentstack_utils (1.1.3) - activesupport (>= 3.2) + contentstack_utils (1.1.4) + activesupport (~> 3.2) nokogiri (~> 1.11) GEM remote: https://rubygems.org/ specs: - activesupport (6.1.7.3) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) - addressable (2.8.1) + activesupport (3.2.22.5) + i18n (~> 0.6, >= 0.6.4) + multi_json (~> 1.0) + addressable (2.8.4) public_suffix (>= 2.0.2, < 6.0) concurrent-ruby (1.2.2) crack (0.4.5) @@ -22,17 +19,17 @@ GEM diff-lcs (1.5.0) docile (1.4.0) hashdiff (1.0.1) - i18n (1.12.0) + i18n (0.9.5) concurrent-ruby (~> 1.0) - mini_portile2 (2.8.1) - minitest (5.18.0) - nokogiri (1.13.10) - mini_portile2 (~> 2.8.0) + mini_portile2 (2.8.2) + multi_json (1.15.0) + nokogiri (1.15.2) + mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.13.10-x64-mingw32) + nokogiri (1.15.2-x64-mingw32) racc (~> 1.4) public_suffix (5.0.1) - racc (1.6.2) + racc (1.7.1) rake (13.0.6) rexml (3.2.5) rspec (3.10.0) @@ -54,16 +51,11 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - tzinfo (2.0.6) - concurrent-ruby (~> 1.0) webmock (3.11.3) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.7.0) - yard (0.9.28) - webrick (~> 1.7.0) - zeitwerk (2.6.7) + yard (0.9.34) PLATFORMS ruby diff --git a/lib/contentstack_utils/model/options.rb b/lib/contentstack_utils/model/options.rb index fcb76c6..0ddee55 100644 --- a/lib/contentstack_utils/model/options.rb +++ b/lib/contentstack_utils/model/options.rb @@ -108,7 +108,12 @@ def render_node(node_type, node, inner_html) when 'code' renderString = "#{inner_html}" when 'reference' - renderString = "" + if (node["attrs"]['type'] === 'asset') + renderString = "#{node["attrs"]['asset-name']}" + else + renderString = "" + end + when 'span' renderString = "#{inner_html}" end diff --git a/spec/lib/utils_spec.rb b/spec/lib/utils_spec.rb index f941198..f9989a3 100644 --- a/spec/lib/utils_spec.rb +++ b/spec/lib/utils_spec.rb @@ -204,6 +204,13 @@ expect(result).to eq ['
    '] end + it 'Should return break line string for horizontal line doc' do + doc = getJson(BRJson) + + result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new()) + + expect(result).to eq ['
    '] + end end describe '#JsonToHtml' do @@ -377,6 +384,14 @@ expect(result).to eq AssetReferenceHtml end + it 'Should return asset embedded items for assest-link' do + doc = getJson(AssetReferenceJson) + + result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new(JSON_EMBEDDED_ITEMS_ENTRY)) + + expect(result).to eq "dummy.pdf" + end + it 'Should return entry block embedded items' do doc = getJson(EntryReferenceBlockJson) diff --git a/spec/mock/json_to_html_mock.rb b/spec/mock/json_to_html_mock.rb index 170067b..630da39 100644 --- a/spec/mock/json_to_html_mock.rb +++ b/spec/mock/json_to_html_mock.rb @@ -43,6 +43,7 @@ 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"}' HRJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":{ }, "children":[{"uid":"f5a7b57 40a8a5c3 576828276b","type":"hr","children":[{"text":""}],"attrs":{ }}],"type":"doc"}' +BRJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":{ }, "children":[{"uid":"f5a7b57 40a8a5c3 576828276b","type":"br","children":[{"text":""}],"attrs":{ }}],"type":"doc"}' H1NonChildJson = '{ "uid":"06e34a7a449d7fc2acd","_version":13,"attrs":{ },"children":[{ "type":"h1","attrs":{ },"uid":"c2dfed70 4d7030c65e2e1"}],"type":"doc"}' JSON_EMBEDDED_ITEMS_ENTRY= { From c2862469441342bd01ccc81934952a8d93c6af16 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Tue, 20 Jun 2023 18:21:15 +0530 Subject: [PATCH 4/8] Resolved dependency gem issues in latest ruby versions --- Gemfile.lock | 16 ++++++++++------ contentstack_utils.gemspec | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index cd1e810..6fc371c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,15 +2,17 @@ PATH remote: . specs: contentstack_utils (1.1.4) - activesupport (~> 3.2) + activesupport (>= 3.2) nokogiri (~> 1.11) GEM remote: https://rubygems.org/ specs: - activesupport (3.2.22.5) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) + activesupport (7.0.5) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) addressable (2.8.4) public_suffix (>= 2.0.2, < 6.0) concurrent-ruby (1.2.2) @@ -19,10 +21,10 @@ GEM diff-lcs (1.5.0) docile (1.4.0) hashdiff (1.0.1) - i18n (0.9.5) + i18n (1.14.1) concurrent-ruby (~> 1.0) mini_portile2 (2.8.2) - multi_json (1.15.0) + minitest (5.18.1) nokogiri (1.15.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) @@ -51,6 +53,8 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) webmock (3.11.3) addressable (>= 2.3.6) crack (>= 0.3.2) diff --git a/contentstack_utils.gemspec b/contentstack_utils.gemspec index 962b1c5..bfa04a1 100644 --- a/contentstack_utils.gemspec +++ b/contentstack_utils.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.test_files = s.files.grep(%r{^spec/}) s.require_paths = ["lib"] - s.add_dependency 'activesupport', '~> 3.2' + s.add_dependency 'activesupport', '>= 3.2' s.add_dependency 'nokogiri', '~> 1.11' s.add_development_dependency 'rake', '~> 13.0.3' From a827d6f23ec7e933b863b195ca9b88eaa574f780 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Tue, 20 Jun 2023 21:33:27 +0530 Subject: [PATCH 5/8] Added test case for break tag --- spec/lib/model/option_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/lib/model/option_spec.rb b/spec/lib/model/option_spec.rb index 23be650..ac32217 100644 --- a/spec/lib/model/option_spec.rb +++ b/spec/lib/model/option_spec.rb @@ -98,6 +98,8 @@ def getMetadata(itemType=nil, styleType=nil, linkText=nil) to eq "#{linkText}" expect(subject.render_mark('superscript', linkText)). to eq "#{linkText}" + expect(subject.render_mark('br', linkText)). + to eq "
    " expect(subject.render_mark('', linkText)). to eq linkText end From b088d13e13ff06e203f35e2dd7ddcec37363fd20 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Wed, 21 Jun 2023 16:11:24 +0530 Subject: [PATCH 6/8] Changed tag to full name --- lib/contentstack_utils/model/options.rb | 2 +- spec/lib/model/option_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/contentstack_utils/model/options.rb b/lib/contentstack_utils/model/options.rb index 0ddee55..e0facb2 100644 --- a/lib/contentstack_utils/model/options.rb +++ b/lib/contentstack_utils/model/options.rb @@ -48,7 +48,7 @@ def render_mark(mark_type, text) renderString = "#{text}" when 'superscript' renderString = "#{text}" - when 'br' + when 'break' renderString = "
    " end renderString diff --git a/spec/lib/model/option_spec.rb b/spec/lib/model/option_spec.rb index ac32217..7e162b9 100644 --- a/spec/lib/model/option_spec.rb +++ b/spec/lib/model/option_spec.rb @@ -98,7 +98,7 @@ def getMetadata(itemType=nil, styleType=nil, linkText=nil) to eq "#{linkText}" expect(subject.render_mark('superscript', linkText)). to eq "#{linkText}" - expect(subject.render_mark('br', linkText)). + expect(subject.render_mark('break', linkText)). to eq "
    " expect(subject.render_mark('', linkText)). to eq linkText From e36c493342c66e6df52a6e61c01e948fb23b2d98 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Thu, 22 Jun 2023 15:25:23 +0530 Subject: [PATCH 7/8] Changed method name from 'text_to_htms' to 'text_to_html' --- lib/contentstack_utils/utils.rb | 7 +++++-- spec/lib/utils_spec.rb | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/contentstack_utils/utils.rb b/lib/contentstack_utils/utils.rb index 52053a4..7eec6ba 100644 --- a/lib/contentstack_utils/utils.rb +++ b/lib/contentstack_utils/utils.rb @@ -58,7 +58,7 @@ def self.json_doc_to_html(node, options, callback) private_class_method def self.node_to_html(node, options, callback) html_result = "" if node["type"] == nil && node["text"] - html_result = text_to_htms(node, options) + html_result = text_to_html(node, options) elsif node["type"] if node["type"] == "reference" metadata = Model::Metadata.new(node) @@ -71,7 +71,7 @@ def self.json_doc_to_html(node, options, callback) html_result end - private_class_method def self.text_to_htms(node, options) + private_class_method def self.text_to_html(node, options) text = node["text"] if node["superscript"] text = options.render_mark("superscript", text) @@ -94,6 +94,9 @@ def self.json_doc_to_html(node, options, callback) if node["bold"] text = options.render_mark("bold", text) end + if node["break"] + text = options.render_mark("break", text) + end text end diff --git a/spec/lib/utils_spec.rb b/spec/lib/utils_spec.rb index f9989a3..06c207a 100644 --- a/spec/lib/utils_spec.rb +++ b/spec/lib/utils_spec.rb @@ -204,7 +204,7 @@ expect(result).to eq ['
    '] end - it 'Should return break line string for horizontal line doc' do + it 'Should return break line string for break line doc' do doc = getJson(BRJson) result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new()) From 5bd621470289d74c8c3c25c288cb9065bff1aed3 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Mon, 26 Jun 2023 15:48:20 +0530 Subject: [PATCH 8/8] Changed version from 1.1.4 to 1.2.0 --- CHANGELOG.md | 2 +- Gemfile.lock | 4 +--- lib/contentstack_utils/model/options.rb | 2 -- lib/contentstack_utils/version.rb | 2 +- spec/lib/utils_spec.rb | 7 ------- spec/mock/json_to_html_mock.rb | 1 - 6 files changed, 3 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2493c79..7c47e03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [1.1.4](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.1.4) (2023-06-20) +## [1.2.0](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.2.0) (2023-06-20) - Support for nested assets in the the image and br tag ## [1.1.3](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.1.3) (2023-03-16) - Dependency gem max version issue resolved. (Activesupport gem) diff --git a/Gemfile.lock b/Gemfile.lock index 6fc371c..c8af06c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - contentstack_utils (1.1.4) + contentstack_utils (1.2.0) activesupport (>= 3.2) nokogiri (~> 1.11) @@ -28,8 +28,6 @@ GEM nokogiri (1.15.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.15.2-x64-mingw32) - racc (~> 1.4) public_suffix (5.0.1) racc (1.7.1) rake (13.0.6) diff --git a/lib/contentstack_utils/model/options.rb b/lib/contentstack_utils/model/options.rb index e0facb2..9d869a2 100644 --- a/lib/contentstack_utils/model/options.rb +++ b/lib/contentstack_utils/model/options.rb @@ -87,8 +87,6 @@ def render_node(node_type, node, inner_html) renderString = "
  • #{inner_html}
  • " when 'hr' renderString = "
    " - when 'br' - renderString = "
    " when 'table' renderString = "#{inner_html}
    " when 'thead' diff --git a/lib/contentstack_utils/version.rb b/lib/contentstack_utils/version.rb index 29b3e9a..25428bf 100644 --- a/lib/contentstack_utils/version.rb +++ b/lib/contentstack_utils/version.rb @@ -1,3 +1,3 @@ module ContentstackUtils - VERSION = "1.1.4" + VERSION = "1.2.0" end \ No newline at end of file diff --git a/spec/lib/utils_spec.rb b/spec/lib/utils_spec.rb index 06c207a..2876e2e 100644 --- a/spec/lib/utils_spec.rb +++ b/spec/lib/utils_spec.rb @@ -204,13 +204,6 @@ expect(result).to eq ['
    '] end - it 'Should return break line string for break line doc' do - doc = getJson(BRJson) - - result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new()) - - expect(result).to eq ['
    '] - end end describe '#JsonToHtml' do diff --git a/spec/mock/json_to_html_mock.rb b/spec/mock/json_to_html_mock.rb index 630da39..170067b 100644 --- a/spec/mock/json_to_html_mock.rb +++ b/spec/mock/json_to_html_mock.rb @@ -43,7 +43,6 @@ 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"}' HRJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":{ }, "children":[{"uid":"f5a7b57 40a8a5c3 576828276b","type":"hr","children":[{"text":""}],"attrs":{ }}],"type":"doc"}' -BRJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":{ }, "children":[{"uid":"f5a7b57 40a8a5c3 576828276b","type":"br","children":[{"text":""}],"attrs":{ }}],"type":"doc"}' H1NonChildJson = '{ "uid":"06e34a7a449d7fc2acd","_version":13,"attrs":{ },"children":[{ "type":"h1","attrs":{ },"uid":"c2dfed70 4d7030c65e2e1"}],"type":"doc"}' JSON_EMBEDDED_ITEMS_ENTRY= {