contentstack_utils 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +9 -0
- data/lib/contentstack_utils/model/options.rb +1 -1
- data/lib/contentstack_utils/utils.rb +53 -21
- data/lib/contentstack_utils/version.rb +1 -1
- data/spec/lib/utils_spec.rb +234 -0
- data/spec/mock/json_to_html_mock.rb +3 -2
- data/spec/support/xml_parse.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21932309e73056c667d82fb62ffcc391b31875bbab0862b3c62e6c5cd273f0e4
|
4
|
+
data.tar.gz: 2c62ff41a24c02a1737f192d51389449f9c7f4a3f157f6b3373367a74809b5c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 597777d333caef160d256e78b740ae5a2068ecbe8bac8b77183df32efc40d781101dcef0787b045ea816e1560ca46704b50e801746a2bce797134538f18fd723
|
7
|
+
data.tar.gz: cd94ed56bae23557502116fd4c1d1d3aca927cdc3d7af38708950cbc52fa8deb6051c529d41c579421e060c8694f57ef56a846a7fdd27a931267747ef0cf81e8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [1.1.0](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.1.0) (2021-08-10)
|
4
|
+
- GQL Json rte to Html content support added
|
5
|
+
|
6
|
+
## [1.0.2](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.0.2) (2021-07-16)
|
7
|
+
- JSON RTE support added
|
3
8
|
## [1.0.1](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.0.1) (2021-06-02)
|
4
9
|
- Gemspec Dependency update
|
5
10
|
|
data/README.md
CHANGED
@@ -86,3 +86,12 @@ require 'contentstack'
|
|
86
86
|
Contentstack.render_content(@entry.rte_field_uid, ContentstackUtils::Model::Option.new(@entry))
|
87
87
|
end
|
88
88
|
```
|
89
|
+
### GQL Json RTE to HTML
|
90
|
+
To parse JSON RTE content from GQL response to HTML content use `ContentstackUtils::GQL.json_to_html` function as below:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
require 'contentstack_utils'
|
94
|
+
|
95
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
96
|
+
|
97
|
+
```
|
@@ -17,7 +17,7 @@ module ContentstackUtils
|
|
17
17
|
renderString = ''
|
18
18
|
case metadata.style_type
|
19
19
|
when 'block'
|
20
|
-
renderString = "<div><p>#{embeddedObject['title'] || embeddedObject['uid']}</p><p>Content type: <span>#{embeddedObject['_content_type_uid']}</span></p></div>"
|
20
|
+
renderString = "<div><p>#{embeddedObject['title'] || embeddedObject['uid']}</p><p>Content type: <span>#{embeddedObject['_content_type_uid'] || embeddedObject['system']['content_type_uid']}</span></p></div>"
|
21
21
|
when 'inline'
|
22
22
|
renderString = "<span>#{embeddedObject["title"] || embeddedObject["uid"]}</span>";
|
23
23
|
when 'link'
|
@@ -17,38 +17,49 @@ module ContentstackUtils
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.json_to_html(content, options)
|
20
|
+
reference = -> (metadata){
|
21
|
+
result = ""
|
22
|
+
if options.entry != nil
|
23
|
+
object = findObject(metadata, options.entry)
|
24
|
+
if object!= nil && object.length() > 0
|
25
|
+
result = options.render_option(object[0], metadata)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
result
|
29
|
+
}
|
20
30
|
if (content.instance_of? Array)
|
21
31
|
result = []
|
22
32
|
content.each do |n|
|
23
|
-
result.push(json_doc_to_html(n, options))
|
33
|
+
result.push(json_doc_to_html(n, options, reference) )
|
24
34
|
end
|
25
35
|
result
|
26
36
|
elsif content.instance_of? Hash
|
27
|
-
json_doc_to_html(content, options)
|
37
|
+
json_doc_to_html(content, options, reference)
|
28
38
|
end
|
29
39
|
end
|
30
40
|
|
31
|
-
|
41
|
+
def self.json_doc_to_html(node, options, callback)
|
32
42
|
result = ""
|
33
43
|
if node["children"] && node["children"].length() > 0
|
34
|
-
result = node_children_to_html(node["children"], options)
|
44
|
+
result = node_children_to_html(node["children"], options, callback)
|
35
45
|
end
|
36
46
|
result
|
37
47
|
end
|
38
48
|
|
39
|
-
private_class_method def self.node_children_to_html(nodes, options)
|
40
|
-
nodes.map {|node| node_to_html(node, options)}.join("")
|
49
|
+
private_class_method def self.node_children_to_html(nodes, options, callback)
|
50
|
+
nodes.map {|node| node_to_html(node, options, callback)}.join("")
|
41
51
|
end
|
42
52
|
|
43
|
-
private_class_method def self.node_to_html(node, options)
|
53
|
+
private_class_method def self.node_to_html(node, options, callback)
|
44
54
|
html_result = ""
|
45
55
|
if node["type"] == nil && node["text"]
|
46
56
|
html_result = text_to_htms(node, options)
|
47
57
|
elsif node["type"]
|
48
58
|
if node["type"] == "reference"
|
49
|
-
|
59
|
+
metadata = Model::Metadata.new(node)
|
60
|
+
html_result = callback.call(metadata)
|
50
61
|
else
|
51
|
-
inner_html = json_doc_to_html(node, options)
|
62
|
+
inner_html = json_doc_to_html(node, options, callback)
|
52
63
|
html_result = options.render_node(node["type"], node, inner_html)
|
53
64
|
end
|
54
65
|
end
|
@@ -81,18 +92,6 @@ module ContentstackUtils
|
|
81
92
|
text
|
82
93
|
end
|
83
94
|
|
84
|
-
private_class_method def self.reference_to_html(node, options)
|
85
|
-
result = ""
|
86
|
-
if options.entry != nil
|
87
|
-
metadata = Model::Metadata.new(node)
|
88
|
-
object = findObject(metadata, options.entry)
|
89
|
-
if object!= nil && object.length() > 0
|
90
|
-
result = options.render_option(object[0], metadata)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
result
|
94
|
-
end
|
95
|
-
|
96
95
|
private_class_method def self.render_string(string, options)
|
97
96
|
xml_doc = Nokogiri::HTML(appendFrame(string))
|
98
97
|
result = xml_doc.xpath('//documentfragmentcontainer').inner_html
|
@@ -128,4 +127,37 @@ module ContentstackUtils
|
|
128
127
|
end
|
129
128
|
return nil
|
130
129
|
end
|
130
|
+
|
131
|
+
module GQL
|
132
|
+
include ContentstackUtils
|
133
|
+
def self.json_to_html(content, options)
|
134
|
+
embeddedItems = []
|
135
|
+
if content.has_key? 'embedded_itemsConnection'
|
136
|
+
embeddedItems = content['embedded_itemsConnection']['edges'] || []
|
137
|
+
end
|
138
|
+
reference = -> (metadata){
|
139
|
+
result = ""
|
140
|
+
if embeddedItems != nil
|
141
|
+
object = embeddedItems.select { |embedObject| embedObject['node']["system"]["uid"] == metadata.item_uid }
|
142
|
+
if object != nil && object.length() > 0
|
143
|
+
result = options.render_option(object[0]["node"], metadata)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
result
|
147
|
+
}
|
148
|
+
|
149
|
+
if content.has_key? 'json'
|
150
|
+
json = content['json']
|
151
|
+
if (json.instance_of? Array)
|
152
|
+
result = []
|
153
|
+
json.each do |n|
|
154
|
+
result.push(ContentstackUtils.json_doc_to_html(n, options, reference))
|
155
|
+
end
|
156
|
+
result
|
157
|
+
elsif json.instance_of? Hash
|
158
|
+
ContentstackUtils.json_doc_to_html(json, options, reference)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
131
163
|
end
|
data/spec/lib/utils_spec.rb
CHANGED
@@ -401,6 +401,240 @@ RSpec.describe ContentstackUtils do
|
|
401
401
|
expect(result).to eq EntryReferenceInlineHtml
|
402
402
|
end
|
403
403
|
|
404
|
+
|
405
|
+
end
|
406
|
+
describe 'GQL #JsonToHtml' do
|
407
|
+
it 'Should return blank string for blank doc' do
|
408
|
+
entry = getGQLJSONRTE(BlankDocument)
|
409
|
+
|
410
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
411
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
412
|
+
|
413
|
+
expect(result).to eq ""
|
414
|
+
expect(arrayResult).to eq [""]
|
415
|
+
end
|
416
|
+
|
417
|
+
it 'Should return mark text string for PlainTextJson doc' do
|
418
|
+
entry = getGQLJSONRTE(PlainTextJson)
|
419
|
+
|
420
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
421
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
422
|
+
|
423
|
+
expect(result).to eq PlainTextHtml
|
424
|
+
expect(arrayResult).to eq [PlainTextHtml]
|
425
|
+
end
|
426
|
+
|
427
|
+
it 'Should return paragraph string for ParagraphJson doc' do
|
428
|
+
entry = getGQLJSONRTE(ParagraphJson)
|
429
|
+
|
430
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
431
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
432
|
+
|
433
|
+
expect(result).to eq ParagraphHtml
|
434
|
+
expect(arrayResult).to eq [ParagraphHtml]
|
435
|
+
end
|
436
|
+
|
437
|
+
it 'Should return H1 string for H1Json doc' do
|
438
|
+
entry = getGQLJSONRTE(H1Json)
|
439
|
+
|
440
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
441
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
442
|
+
|
443
|
+
expect(result).to eq H1Html
|
444
|
+
expect(arrayResult).to eq [H1Html]
|
445
|
+
end
|
446
|
+
|
447
|
+
it 'Should return H2 string for H1Json doc' do
|
448
|
+
entry = getGQLJSONRTE(H2Json)
|
449
|
+
|
450
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
451
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
452
|
+
|
453
|
+
expect(result).to eq H2Html
|
454
|
+
expect(arrayResult).to eq [H2Html]
|
455
|
+
end
|
456
|
+
|
457
|
+
it 'Should return H3 string for H1Json doc' do
|
458
|
+
entry = getGQLJSONRTE(H3Json)
|
459
|
+
|
460
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
461
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
462
|
+
|
463
|
+
expect(result).to eq H3Html
|
464
|
+
expect(arrayResult).to eq [H3Html]
|
465
|
+
end
|
466
|
+
|
467
|
+
it 'Should return H4 string for H1Json doc' do
|
468
|
+
entry = getGQLJSONRTE(H4Json)
|
469
|
+
|
470
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
471
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
472
|
+
|
473
|
+
expect(result).to eq H4Html
|
474
|
+
expect(arrayResult).to eq [H4Html]
|
475
|
+
end
|
476
|
+
|
477
|
+
it 'Should return H5 string for H1Json doc' do
|
478
|
+
entry = getGQLJSONRTE(H5Json)
|
479
|
+
|
480
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
481
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
482
|
+
|
483
|
+
expect(result).to eq H5Html
|
484
|
+
expect(arrayResult).to eq [H5Html]
|
485
|
+
end
|
486
|
+
|
487
|
+
it 'Should return H6 string for H1Json doc' do
|
488
|
+
entry = getGQLJSONRTE(H6Json)
|
489
|
+
|
490
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
491
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
492
|
+
|
493
|
+
expect(result).to eq H6Html
|
494
|
+
expect(arrayResult).to eq [H6Html]
|
495
|
+
end
|
496
|
+
|
497
|
+
it 'Should return Order List string for OrderListJson doc' do
|
498
|
+
entry = getGQLJSONRTE(OrderListJson)
|
499
|
+
|
500
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
501
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
502
|
+
|
503
|
+
expect(result).to eq OrderListHtml
|
504
|
+
expect(arrayResult).to eq [OrderListHtml]
|
505
|
+
end
|
506
|
+
|
507
|
+
it 'Should return Unorder List string for UnorderListJson doc' do
|
508
|
+
entry = getGQLJSONRTE(UnorderListJson)
|
509
|
+
|
510
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
511
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
512
|
+
|
513
|
+
expect(result).to eq UnorderListHtml
|
514
|
+
expect(arrayResult).to eq [UnorderListHtml]
|
515
|
+
end
|
516
|
+
|
517
|
+
it 'Should return image string for ImgJson doc' do
|
518
|
+
entry = getGQLJSONRTE(ImgJson)
|
519
|
+
|
520
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
521
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
522
|
+
|
523
|
+
expect(result).to eq ImgHtml
|
524
|
+
expect(arrayResult).to eq [ImgHtml]
|
525
|
+
end
|
526
|
+
|
527
|
+
it 'Should return Blockquote string for BlockquoteJson doc' do
|
528
|
+
entry = getGQLJSONRTE(BlockquoteJson)
|
529
|
+
|
530
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
531
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
532
|
+
|
533
|
+
expect(result).to eq BlockquoteHtml
|
534
|
+
expect(arrayResult).to eq [BlockquoteHtml]
|
535
|
+
end
|
536
|
+
|
537
|
+
it 'Should return Code string for CodeJson doc' do
|
538
|
+
entry = getGQLJSONRTE(CodeJson)
|
539
|
+
|
540
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
541
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
542
|
+
|
543
|
+
expect(result).to eq CodeHtml
|
544
|
+
expect(arrayResult).to eq [CodeHtml]
|
545
|
+
end
|
546
|
+
|
547
|
+
it 'Should return Table string for TableJson doc' do
|
548
|
+
entry = getGQLJSONRTE(TableJson)
|
549
|
+
|
550
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
551
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
552
|
+
|
553
|
+
expect(result).to eq TableHtml
|
554
|
+
expect(arrayResult).to eq [TableHtml]
|
555
|
+
end
|
556
|
+
|
557
|
+
it 'Should return Link string for LinkInPJson doc' do
|
558
|
+
entry = getGQLJSONRTE(LinkInPJson)
|
559
|
+
|
560
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
561
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
562
|
+
|
563
|
+
expect(result).to eq LinkInPHtml
|
564
|
+
expect(arrayResult).to eq [LinkInPHtml]
|
565
|
+
end
|
566
|
+
|
567
|
+
it 'Should return Embed string for EmbedJson doc' do
|
568
|
+
entry = getGQLJSONRTE(EmbedJson)
|
569
|
+
|
570
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
571
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
572
|
+
|
573
|
+
expect(result).to eq EmbedHtml
|
574
|
+
expect(arrayResult).to eq [EmbedHtml]
|
575
|
+
end
|
576
|
+
|
577
|
+
it 'Should return horizontal line string for horizontal line doc' do
|
578
|
+
entry = getGQLJSONRTE(HRJson)
|
579
|
+
|
580
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
581
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
582
|
+
|
583
|
+
expect(result).to eq '<hr />'
|
584
|
+
expect(arrayResult).to eq ['<hr />']
|
585
|
+
end
|
586
|
+
end
|
587
|
+
|
588
|
+
describe 'GQL #JsonToHtml reference' do
|
589
|
+
it 'Should return blank string for non entry option' do
|
590
|
+
entry = getGQLJSONRTE(AssetReferenceJson)
|
591
|
+
|
592
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
593
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
594
|
+
|
595
|
+
expect(result).to eq ''
|
596
|
+
expect(arrayResult).to eq ['']
|
597
|
+
end
|
598
|
+
|
599
|
+
it 'Should return asset embedded items' do
|
600
|
+
entry = getGQLJSONRTE(AssetReferenceJson, EmbedEdges)
|
601
|
+
|
602
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
603
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
604
|
+
|
605
|
+
expect(result).to eq AssetReferenceHtml
|
606
|
+
expect(arrayResult).to eq [AssetReferenceHtml]
|
607
|
+
end
|
608
|
+
|
609
|
+
it 'Should return entry block embedded items' do
|
610
|
+
entry = getGQLJSONRTE(EntryReferenceBlockJson, EmbedEdges)
|
611
|
+
|
612
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
613
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
614
|
+
|
615
|
+
expect(result).to eq EntryReferenceBlockHtml
|
616
|
+
expect(arrayResult).to eq [EntryReferenceBlockHtml]
|
617
|
+
end
|
618
|
+
|
619
|
+
it 'Should return entry link embedded items' do
|
620
|
+
entry = getGQLJSONRTE(EntryReferenceLinkJson, EmbedEdges)
|
621
|
+
|
622
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
623
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
624
|
+
|
625
|
+
expect(result).to eq EntryReferenceLinkHtml
|
626
|
+
expect(arrayResult).to eq [EntryReferenceLinkHtml]
|
627
|
+
end
|
628
|
+
|
629
|
+
it 'Should return entry inline embedded items' do
|
630
|
+
entry = getGQLJSONRTE(EntryReferenceInlineJson, EmbedEdges)
|
631
|
+
|
632
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
633
|
+
arrayResult = ContentstackUtils::GQL.json_to_html(entry['multiple_rte'], ContentstackUtils::Model::Options.new())
|
634
|
+
|
635
|
+
expect(result).to eq EntryReferenceInlineHtml
|
636
|
+
expect(arrayResult).to eq [EntryReferenceInlineHtml]
|
637
|
+
end
|
404
638
|
end
|
405
639
|
|
406
640
|
def makeRenderFunction(content, option = ContentstackUtils::Model::Options.new(ENTRY_EMBEDDED_ASSET))
|
@@ -44,7 +44,6 @@ EntryReferenceInlineJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":
|
|
44
44
|
HRJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":{ }, "children":[{"uid":"f5a7b57 40a8a5c3 576828276b","type":"hr","children":[{"text":""}],"attrs":{ }}],"type":"doc"}'
|
45
45
|
H1NonChildJson = '{ "uid":"06e34a7a449d7fc2acd","_version":13,"attrs":{ },"children":[{ "type":"h1","attrs":{ },"uid":"c2dfed70 4d7030c65e2e1"}],"type":"doc"}'
|
46
46
|
|
47
|
-
|
48
47
|
JSON_EMBEDDED_ITEMS_ENTRY= {
|
49
48
|
"title"=> 'one',
|
50
49
|
"url"=> '/one',
|
@@ -142,4 +141,6 @@ JSON_EMBEDDED_ITEMS_ENTRY= {
|
|
142
141
|
}
|
143
142
|
]
|
144
143
|
}
|
145
|
-
}
|
144
|
+
}
|
145
|
+
|
146
|
+
EmbedEdges = '{"edges":[{"node":{"system":{"content_type_uid":"sys_assets","uid":"blt9844"},"created_at":"2020-08-19T09:13:05.864Z","updated_at":"2020-09-10T09:35:28.393Z","created_by":"bltcreate","updated_by":"bltcreate","content_type":"image/png","file_size":"36743","filename":"svg-logo-text.png","url":"/v3/assets/svg-logo-text.png","_version":7,"title":"svg-logo-text.png","description":""}},{"node":{"system":{"content_type_uid":"sys_assets","uid":"blt44asset"},"created_at":"2020-08-19T09:13:32.785Z","updated_at":"2020-08-19T09:13:32.785Z","created_by":"bltcreate","updated_by":"bltcreate","content_type":"application/pdf","file_size":"13264","filename":"title","url":"/v3/assets/blt333/blt44asset/dummy.pdf","_version":1,"title":"dummy.pdf"}},{"node":{"title":"Update this title","url":"","locale":"en-us","system":{"uid":"blttitleuid","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":"blttitleUpdateuid","content_type_uid":"embeddedrte"},"_in_progress":false}},{"node":{"title":"Entry with embedded entry","rich_text_editor":[""],"locale":"en-us","system":{"uid":"bltemmbedEntryuid","content_type_uid":"embeddedrte"},"_in_progress":false}},{"node":{"system":{"uid":"bltassetEmbuid","content_type_uid":"sys_assets"},"content_type":"image/png","file_size":"36743","filename":"svg-logo-text.png","url":"/v3/assets/blturl/bltassetEmbuid/svg-logo-text.png","title":"svg-logo-text.png","description":""}},{"node":{"title":"Update this title","url":"","locale":"en-us","system":{"uid":"blttitleuid","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":"blttitleUpdateUID","content_type_uid":"embeddedrte"},"_in_progress":false}},{"node":{"title":"Entry with embedded entry","rich_text_editor":[""],"locale":"en-us","system":{"uid":"bltemmbedEntryUID","content_type_uid":"embeddedrte"},"_in_progress":false}}]}'
|
data/spec/support/xml_parse.rb
CHANGED
@@ -14,4 +14,18 @@ end
|
|
14
14
|
|
15
15
|
def getJson(text)
|
16
16
|
JSON.parse(text)
|
17
|
+
end
|
18
|
+
|
19
|
+
def getGQLJSONRTE(node, item = '""')
|
20
|
+
entry = "{
|
21
|
+
\"single_rte\": {
|
22
|
+
\"json\": #{node},
|
23
|
+
\"embedded_itemsConnection\": #{item}
|
24
|
+
},
|
25
|
+
\"multiple_rte\": {
|
26
|
+
\"json\": [#{node}],
|
27
|
+
\"embedded_itemsConnection\": #{item}
|
28
|
+
}
|
29
|
+
}"
|
30
|
+
getJson(entry)
|
17
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentstack_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentstack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|