From e726150ea2e0e2d2e99e984dc7f64c6a42ad9e34 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Mon, 26 Jun 2023 18:43:20 +0530 Subject: [PATCH] =?UTF-8?q?Added=20support=20for=20the=20
=20tag=20and?= =?UTF-8?q?=20support=20for=20nested=20assets=20in=20the=20t=E2=80=A6=20(#?= =?UTF-8?q?14)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added support for the
tag and support for nested assets in the the image * Added version and change log * Added Testcases * Resolved dependency gem issues in latest ruby versions * Added test case for break tag * Changed tag to full name * Changed method name from 'text_to_htms' to 'text_to_html' * Changed version from 1.1.4 to 1.2.0 --- CHANGELOG.md | 2 ++ Gemfile.lock | 26 ++++++++++--------------- contentstack_utils.gemspec | 2 +- lib/contentstack_utils/model/options.rb | 9 ++++++++- lib/contentstack_utils/utils.rb | 12 ++++++++++-- lib/contentstack_utils/version.rb | 2 +- spec/lib/model/option_spec.rb | 2 ++ spec/lib/utils_spec.rb | 8 ++++++++ 8 files changed, 42 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7ef236..7c47e03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## [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 70a93d4..c8af06c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,20 +1,19 @@ PATH remote: . specs: - contentstack_utils (1.1.3) + contentstack_utils (1.2.0) activesupport (>= 3.2) nokogiri (~> 1.11) GEM remote: https://rubygems.org/ specs: - activesupport (6.1.7.3) + activesupport (7.0.5) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) - addressable (2.8.1) + addressable (2.8.4) public_suffix (>= 2.0.2, < 6.0) concurrent-ruby (1.2.2) crack (0.4.5) @@ -22,17 +21,15 @@ GEM diff-lcs (1.5.0) docile (1.4.0) hashdiff (1.0.1) - i18n (1.12.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) - mini_portile2 (2.8.1) - minitest (5.18.0) - nokogiri (1.13.10) - mini_portile2 (~> 2.8.0) - racc (~> 1.4) - nokogiri (1.13.10-x64-mingw32) + mini_portile2 (2.8.2) + minitest (5.18.1) + nokogiri (1.15.2) + mini_portile2 (~> 2.8.2) 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) @@ -60,10 +57,7 @@ GEM 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/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' diff --git a/lib/contentstack_utils/model/options.rb b/lib/contentstack_utils/model/options.rb index 94abecb..9d869a2 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 'break' + renderString = "
" end renderString end @@ -104,7 +106,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/lib/contentstack_utils/utils.rb b/lib/contentstack_utils/utils.rb index 1bb338b..7eec6ba 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 @@ -53,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) @@ -66,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) @@ -89,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/lib/contentstack_utils/version.rb b/lib/contentstack_utils/version.rb index 95ed36c..25428bf 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.2.0" end \ No newline at end of file diff --git a/spec/lib/model/option_spec.rb b/spec/lib/model/option_spec.rb index 23be650..7e162b9 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('break', linkText)). + to eq "
" expect(subject.render_mark('', linkText)). to eq linkText end diff --git a/spec/lib/utils_spec.rb b/spec/lib/utils_spec.rb index f941198..2876e2e 100644 --- a/spec/lib/utils_spec.rb +++ b/spec/lib/utils_spec.rb @@ -377,6 +377,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)