Skip to content

Commit 2e77507

Browse files
Added Fragment attribute in JSON RTE (#16) (#17)
* Added Fragment attribute in JSON RTE * Removed unused github action files
1 parent aea592d commit 2e77507

File tree

8 files changed

+125
-26
lines changed

8 files changed

+125
-26
lines changed

.github/workflows/sast-scan.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/secrets-scan.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Changelog
2-
2+
## [1.2.1](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.2.1) (2024-02-27)
3+
- Support for JSON RTE with fragment in nested list
34
## [1.2.0](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.2.0) (2023-06-20)
45
- Support for nested assets in the the image and br tag
56
## [1.1.3](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.1.3) (2023-03-16)

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2012-2023 Contentstack. All Rights Reserved
3+
Copyright (c) 2012-2024 Contentstack. All Rights Reserved
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

lib/contentstack_utils/model/options.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def render_node(node_type, node, inner_html)
105105
renderString = "<blockquote>#{inner_html}</blockquote>"
106106
when 'code'
107107
renderString = "<code>#{inner_html}</code>"
108+
when 'fragment'
109+
renderString = "<fragment>#{inner_html}</fragment>"
108110
when 'reference'
109111
if (node["attrs"]['type'] === 'asset')
110112
renderString = "<img src=#{node["attrs"]['asset-link']} alt=#{node["attrs"]['asset-name']} />"

lib/contentstack_utils/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ContentstackUtils
2-
VERSION = "1.2.0"
2+
VERSION = "1.2.1"
33
end

spec/lib/utils_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,26 @@
522522
expect(arrayResult).to eq [UnorderListHtml]
523523
end
524524

525+
it 'Should return Order List string for OrderListJson with Fragment doc' do
526+
entry = getGQLJSONRTE(OrderListFragmentJson)
527+
528+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
529+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
530+
531+
expect(result).to eq OrderListFragmentHtml
532+
expect(arrayResult).to eq [OrderListFragmentHtml]
533+
end
534+
535+
it 'Should return Unorder List string for UnorderListJson with Fragment doc' do
536+
entry = getGQLJSONRTE(UnorderListFragmentJson)
537+
538+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
539+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
540+
541+
expect(result).to eq UnorderListFragmentHtml
542+
expect(arrayResult).to eq [UnorderListFragmentHtml]
543+
end
544+
525545
it 'Should return image string for ImgJson doc' do
526546
entry = getGQLJSONRTE(ImgJson)
527547

spec/mock/json_to_html_mock.rb

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
H6Html = "<h6>Nunc porta diam vitae purus semper, ut consequat lorem vehicula.</h6>"
1010
OrderListHtml = "<ol><li>Morbi in quam molestie, fermentum diam vitae, bibendum ipsum.</li><li>Pellentesque mattis lacus in quam aliquam congue</li><li>Integer feugiat leo dignissim, lobortis enim vitae, mollis lectus.</li><li>Sed in ante lacinia, molestie metus eu, fringilla sapien.</li></ol>"
1111
UnorderListHtml = "<ul><li>Sed quis metus sed mi hendrerit mollis vel et odio.</li><li>Integer vitae sem dignissim, elementum libero vel, fringilla massa.</li><li>Integer imperdiet arcu sit amet tortor faucibus aliquet.</li><li>Aenean scelerisque velit vitae dui vehicula, at congue massa sagittis.</li></ul>"
12+
OrderListFragmentHtml = "<ol><li><fragment>List Item 1</fragment><ol><li>List Item 1.1</li><li>List Item 1.2</li><li>List Item 1.3</li></ol></li></ol>"
13+
UnorderListFragmentHtml = "<ul><li><fragment>List Item 1</fragment><ul><li>List Item 1.1</li><li>List Item 1.2</li><li>List Item 1.3</li></ul></li></ul>"
1214
ImgHtml = "<img src='https://images.contentstack.com/v3/Donald.jog.png' />"
1315
TableHtml = "<table><thead><tr><th><p>Header 1</p></th><th><p>Header 2</p></th></tr></thead><tbody><tr><td><p>Body row 1 data 1</p></td><td><p>Body row 1 data 2</p></td></tr><tr><td><p>Body row 2 data 1</p></td><td><p>Body row 2 data 2</p></td></tr></tbody></table>"
1416
BlockquoteHtml = "<blockquote>Praesent eu ex sed nibh venenatis pretium.</blockquote>"
@@ -144,4 +146,100 @@
144146
}
145147
}
146148

147-
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}}]}'
149+
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}}]}'
150+
151+
OrderListFragmentJson = {
152+
"type": "ol",
153+
"children": [
154+
{
155+
"type": "li",
156+
"children": [
157+
{
158+
"type": "fragment",
159+
"children": [
160+
{
161+
"text": "List Item 1"
162+
}
163+
]
164+
},
165+
{
166+
"type": "ol",
167+
"children": [
168+
{
169+
"type": "li",
170+
"children": [
171+
{
172+
"text": "List Item 1.1"
173+
}
174+
]
175+
},
176+
{
177+
"type": "li",
178+
"children": [
179+
{
180+
"text": "List Item 1.2"
181+
}
182+
]
183+
},
184+
{
185+
"type": "li",
186+
"children": [
187+
{
188+
"text": "List Item 1.3"
189+
}
190+
]
191+
}
192+
]
193+
}
194+
]
195+
}
196+
]
197+
}
198+
199+
UnorderListFragmentJson = {
200+
"type": "ul",
201+
"children": [
202+
{
203+
"type": "li",
204+
"children": [
205+
{
206+
"type": "fragment",
207+
"children": [
208+
{
209+
"text": "List Item 1"
210+
}
211+
]
212+
},
213+
{
214+
"type": "ul",
215+
"children": [
216+
{
217+
"type": "li",
218+
"children": [
219+
{
220+
"text": "List Item 1.1"
221+
}
222+
]
223+
},
224+
{
225+
"type": "li",
226+
"children": [
227+
{
228+
"text": "List Item 1.2"
229+
}
230+
]
231+
},
232+
{
233+
"type": "li",
234+
"children": [
235+
{
236+
"text": "List Item 1.3"
237+
}
238+
]
239+
}
240+
]
241+
}
242+
]
243+
}
244+
]
245+
}

0 commit comments

Comments
 (0)