contentstack_utils 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/lib/contentstack_utils/model/metadata.rb +36 -11
- data/lib/contentstack_utils/model/options.rb +83 -4
- data/lib/contentstack_utils/utils.rb +77 -0
- data/lib/contentstack_utils/version.rb +1 -1
- data/spec/lib/model/metadata_spec.rb +40 -0
- data/spec/lib/model/option_spec.rb +216 -0
- data/spec/lib/utils_spec.rb +344 -0
- data/spec/mock/json_to_html_mock.rb +145 -0
- data/spec/support/xml_parse.rb +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a691f064b75fd39a515820f923d010c522db2424625e7bc6067d506f503032d
|
4
|
+
data.tar.gz: 2697a1861b0ff36a01067c818b978f0ed49c70c1e5873fb8d848370314da11d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30aab1ef4bb9db3b8e2ebd83bc43ca204c93a11c96b37c85d57dc74b289e08ec518bfa5da8d192c146fdc52567f9b37acb1199d1f0eaedfd7af323154a8e1cfb
|
7
|
+
data.tar.gz: 6033a07b7469e441135337014784746a87ef215d4e70aa92e730c13a8636ebae8e48dc989efee9c1d201100317388db9c942bcecade1c3c7eb296d1767a1591f
|
data/.gitignore
CHANGED
@@ -3,29 +3,46 @@ module ContentstackUtils
|
|
3
3
|
module Model
|
4
4
|
class Metadata
|
5
5
|
def initialize( element )
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
if element.instance_of? Nokogiri::XML::Element
|
7
|
+
@itemType = element.attribute('type') ? element.attribute('type').value : nil
|
8
|
+
@styleType = element.attribute('sys-style-type') ? element.attribute('sys-style-type').value : nil
|
9
|
+
@itemUid ||= (element.attribute('data-sys-entry-uid') ? element.attribute('data-sys-entry-uid').value : nil) || (element.attribute('data-sys-asset-uid') ? element.attribute('data-sys-asset-uid').value : nil)
|
10
|
+
@contentTypeUid = element.attribute('data-sys-content-type-uid') ? element.attribute('data-sys-content-type-uid').value : nil
|
11
|
+
@text = element.text
|
12
|
+
@element = element
|
13
|
+
@attributes = element
|
14
|
+
else
|
15
|
+
@itemType = element["attrs"]['type']
|
16
|
+
@styleType = element["attrs"]['display-type']
|
17
|
+
@itemUid ||= element["attrs"]['entry-uid'] || element["attrs"]['asset-uid']
|
18
|
+
@contentTypeUid = element["attrs"]['content-type-uid']
|
19
|
+
if element["children"] && element["children"].length() > 0
|
20
|
+
child = element["children"]
|
21
|
+
for item in child do
|
22
|
+
if item["type"] == nil && item["text"]
|
23
|
+
@text = item["text"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
@element = element
|
28
|
+
@attributes = element["attrs"]
|
29
|
+
end
|
13
30
|
end
|
14
31
|
|
15
32
|
def item_type
|
16
|
-
@itemType ? @itemType
|
33
|
+
@itemType ? @itemType : nil
|
17
34
|
end
|
18
35
|
|
19
36
|
def style_type
|
20
|
-
@styleType ? @styleType
|
37
|
+
@styleType ? @styleType : nil
|
21
38
|
end
|
22
39
|
|
23
40
|
def item_uid
|
24
|
-
@itemUid ? @itemUid
|
41
|
+
@itemUid ? @itemUid : nil
|
25
42
|
end
|
26
43
|
|
27
44
|
def content_type_uid
|
28
|
-
@contentTypeUid ? @contentTypeUid
|
45
|
+
@contentTypeUid ? @contentTypeUid : nil
|
29
46
|
end
|
30
47
|
|
31
48
|
def text
|
@@ -39,6 +56,14 @@ module ContentstackUtils
|
|
39
56
|
def attributes
|
40
57
|
@attributes
|
41
58
|
end
|
59
|
+
|
60
|
+
def get_attribute_value(string)
|
61
|
+
if @attributes.instance_of? Nokogiri::XML::Element
|
62
|
+
@attributes.attribute(string) ? @attributes.attribute(string).value : nil
|
63
|
+
else
|
64
|
+
@attributes[string]
|
65
|
+
end
|
66
|
+
end
|
42
67
|
end
|
43
68
|
end
|
44
69
|
end
|
@@ -5,7 +5,7 @@ module ContentstackUtils
|
|
5
5
|
module Model
|
6
6
|
class Options < Interface::Rendarable
|
7
7
|
|
8
|
-
def initialize(entry)
|
8
|
+
def initialize(entry = nil)
|
9
9
|
@entry = entry
|
10
10
|
end
|
11
11
|
|
@@ -21,11 +21,90 @@ module ContentstackUtils
|
|
21
21
|
when 'inline'
|
22
22
|
renderString = "<span>#{embeddedObject["title"] || embeddedObject["uid"]}</span>";
|
23
23
|
when 'link'
|
24
|
-
|
24
|
+
metadata.get_attribute_value("href")
|
25
|
+
renderString = "<a href='#{metadata.get_attribute_value("href") || embeddedObject["url"] || embeddedObject["title"] || embeddedObject["uid"]}'>#{(metadata.text && metadata.text != '' ? metadata.text : (embeddedObject["title"] || embeddedObject["uid"]))}</a>";
|
25
26
|
when 'display'
|
26
|
-
renderString = "<img src='#{
|
27
|
+
renderString = "<img src='#{metadata.get_attribute_value("src")|| embeddedObject["url"]}' alt='#{(metadata.attributes["alt"] ? metadata.attributes["alt"].value : (embeddedObject["title"] || embeddedObject["filename"] || embeddedObject["uid"]))}' />";
|
27
28
|
when 'download'
|
28
|
-
renderString = "<a href='#{
|
29
|
+
renderString = "<a href='#{metadata.get_attribute_value("href") || embeddedObject["url"]}'>#{(metadata.text && metadata.text != '' ? metadata.text : (embeddedObject["filename"] || embeddedObject["title"] || embeddedObject["uid"]))}</a>";
|
30
|
+
end
|
31
|
+
renderString
|
32
|
+
end
|
33
|
+
|
34
|
+
def render_mark(mark_type, text)
|
35
|
+
renderString = text
|
36
|
+
case mark_type
|
37
|
+
when 'bold'
|
38
|
+
renderString = "<strong>#{text}</strong>"
|
39
|
+
when 'italic'
|
40
|
+
renderString = "<em>#{text}</em>"
|
41
|
+
when 'underline'
|
42
|
+
renderString = "<u>#{text}</u>"
|
43
|
+
when 'strikethrough'
|
44
|
+
renderString = "<strike>#{text}</strike>"
|
45
|
+
when 'inlineCode'
|
46
|
+
renderString = "<span>#{text}</span>"
|
47
|
+
when 'subscript'
|
48
|
+
renderString = "<sub>#{text}</sub>"
|
49
|
+
when 'superscript'
|
50
|
+
renderString = "<sup>#{text}</sup>"
|
51
|
+
end
|
52
|
+
renderString
|
53
|
+
end
|
54
|
+
|
55
|
+
def render_node(node_type, node, inner_html)
|
56
|
+
renderString = ""
|
57
|
+
case node_type
|
58
|
+
when 'doc'
|
59
|
+
renderString = ""
|
60
|
+
when 'p'
|
61
|
+
renderString = "<p>#{inner_html}</p>"
|
62
|
+
when 'a'
|
63
|
+
renderString = "<a href='#{node["attrs"]["href"] || ""}'>#{inner_html}</a>"
|
64
|
+
when 'img'
|
65
|
+
renderString = "<img src='#{node["attrs"]["src"] || ""}' />#{inner_html}"
|
66
|
+
when 'embed'
|
67
|
+
renderString = "<iframe src='#{node["attrs"]["src"] || ""}'></iframe>"
|
68
|
+
when 'h1'
|
69
|
+
renderString = "<h1>#{inner_html}</h1>"
|
70
|
+
when 'h2'
|
71
|
+
renderString = "<h2>#{inner_html}</h2>"
|
72
|
+
when 'h3'
|
73
|
+
renderString = "<h3>#{inner_html}</h3>"
|
74
|
+
when 'h4'
|
75
|
+
renderString = "<h4>#{inner_html}</h4>"
|
76
|
+
when 'h5'
|
77
|
+
renderString = "<h5>#{inner_html}</h5>"
|
78
|
+
when 'h6'
|
79
|
+
renderString = "<h6>#{inner_html}</h6>"
|
80
|
+
when 'ol'
|
81
|
+
renderString = "<ol>#{inner_html}</ol>"
|
82
|
+
when 'ul'
|
83
|
+
renderString = "<ul>#{inner_html}</ul>"
|
84
|
+
when 'li'
|
85
|
+
renderString = "<li>#{inner_html}</li>"
|
86
|
+
when 'hr'
|
87
|
+
renderString = "<hr />"
|
88
|
+
when 'table'
|
89
|
+
renderString = "<table>#{inner_html}</table>"
|
90
|
+
when 'thead'
|
91
|
+
renderString = "<thead>#{inner_html}</thead>"
|
92
|
+
when 'tbody'
|
93
|
+
renderString = "<tbody>#{inner_html}</tbody>"
|
94
|
+
when 'tfoot'
|
95
|
+
renderString = "<tfoot>#{inner_html}</tfoot>"
|
96
|
+
when 'tr'
|
97
|
+
renderString = "<tr>#{inner_html}</tr>"
|
98
|
+
when 'th'
|
99
|
+
renderString = "<th>#{inner_html}</th>"
|
100
|
+
when 'td'
|
101
|
+
renderString = "<td>#{inner_html}</td>"
|
102
|
+
when 'blockquote'
|
103
|
+
renderString = "<blockquote>#{inner_html}</blockquote>"
|
104
|
+
when 'code'
|
105
|
+
renderString = "<code>#{inner_html}</code>"
|
106
|
+
when 'reference'
|
107
|
+
renderString = ""
|
29
108
|
end
|
30
109
|
renderString
|
31
110
|
end
|
@@ -16,6 +16,83 @@ module ContentstackUtils
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.json_to_html(content, options)
|
20
|
+
if (content.instance_of? Array)
|
21
|
+
result = []
|
22
|
+
content.each do |n|
|
23
|
+
result.push(json_doc_to_html(n, options))
|
24
|
+
end
|
25
|
+
result
|
26
|
+
elsif content.instance_of? Hash
|
27
|
+
json_doc_to_html(content, options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private_class_method def self.json_doc_to_html(node, options)
|
32
|
+
result = ""
|
33
|
+
if node["children"] && node["children"].length() > 0
|
34
|
+
result = node_children_to_html(node["children"], options)
|
35
|
+
end
|
36
|
+
result
|
37
|
+
end
|
38
|
+
|
39
|
+
private_class_method def self.node_children_to_html(nodes, options)
|
40
|
+
nodes.map {|node| node_to_html(node, options)}.join("")
|
41
|
+
end
|
42
|
+
|
43
|
+
private_class_method def self.node_to_html(node, options)
|
44
|
+
html_result = ""
|
45
|
+
if node["type"] == nil && node["text"]
|
46
|
+
html_result = text_to_htms(node, options)
|
47
|
+
elsif node["type"]
|
48
|
+
if node["type"] == "reference"
|
49
|
+
html_result = reference_to_html(node, options)
|
50
|
+
else
|
51
|
+
inner_html = json_doc_to_html(node, options)
|
52
|
+
html_result = options.render_node(node["type"], node, inner_html)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
html_result
|
56
|
+
end
|
57
|
+
|
58
|
+
private_class_method def self.text_to_htms(node, options)
|
59
|
+
text = node["text"]
|
60
|
+
if node["superscript"]
|
61
|
+
text = options.render_mark("superscript", text)
|
62
|
+
end
|
63
|
+
if node["subscript"]
|
64
|
+
text = options.render_mark("subscript", text)
|
65
|
+
end
|
66
|
+
if node["inlineCode"]
|
67
|
+
text = options.render_mark("inlineCode", text)
|
68
|
+
end
|
69
|
+
if node["strikethrough"]
|
70
|
+
text = options.render_mark("strikethrough", text)
|
71
|
+
end
|
72
|
+
if node["underline"]
|
73
|
+
text = options.render_mark("underline", text)
|
74
|
+
end
|
75
|
+
if node["italic"]
|
76
|
+
text = options.render_mark("italic", text)
|
77
|
+
end
|
78
|
+
if node["bold"]
|
79
|
+
text = options.render_mark("bold", text)
|
80
|
+
end
|
81
|
+
text
|
82
|
+
end
|
83
|
+
|
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
|
+
|
19
96
|
private_class_method def self.render_string(string, options)
|
20
97
|
xml_doc = Nokogiri::HTML(appendFrame(string))
|
21
98
|
result = xml_doc.xpath('//documentfragmentcontainer').inner_html
|
@@ -51,5 +51,45 @@ RSpec.describe ContentstackUtils::Model::Metadata do
|
|
51
51
|
expect(metadata.text).to eq 'TEST'
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
it 'Asset Json To metadata' do
|
56
|
+
doc = getJson(AssetReferenceJson)
|
57
|
+
metadata = ContentstackUtils::Model::Metadata.new(doc["children"][0])
|
58
|
+
expect(metadata.item_type).to eq "asset"
|
59
|
+
expect(metadata.style_type).to eq "display"
|
60
|
+
expect(metadata.item_uid).to eq "blt44asset"
|
61
|
+
expect(metadata.content_type_uid).to eq 'sys_assets'
|
62
|
+
expect(metadata.text).to eq ''
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'Entry Block Json To metadata' do
|
66
|
+
doc = getJson(EntryReferenceBlockJson)
|
67
|
+
metadata = ContentstackUtils::Model::Metadata.new(doc["children"][0])
|
68
|
+
expect(metadata.item_type).to eq "entry"
|
69
|
+
expect(metadata.style_type).to eq "block"
|
70
|
+
expect(metadata.item_uid).to eq "blttitleuid"
|
71
|
+
expect(metadata.content_type_uid).to eq 'content_block'
|
72
|
+
expect(metadata.text).to eq ''
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'Entry Link Json To metadata' do
|
76
|
+
doc = getJson(EntryReferenceLinkJson)
|
77
|
+
metadata = ContentstackUtils::Model::Metadata.new(doc["children"][0])
|
78
|
+
expect(metadata.item_type).to eq "entry"
|
79
|
+
expect(metadata.style_type).to eq "link"
|
80
|
+
expect(metadata.item_uid).to eq "bltemmbedEntryuid"
|
81
|
+
expect(metadata.content_type_uid).to eq 'embeddedrte'
|
82
|
+
expect(metadata.text).to eq "/copy-of-entry-final-02"
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'Entry Inline Json To metadata' do
|
86
|
+
doc = getJson(EntryReferenceInlineJson)
|
87
|
+
metadata = ContentstackUtils::Model::Metadata.new(doc["children"][0])
|
88
|
+
expect(metadata.item_type).to eq "entry"
|
89
|
+
expect(metadata.style_type).to eq "inline"
|
90
|
+
expect(metadata.item_uid).to eq "blttitleUpdateuid"
|
91
|
+
expect(metadata.content_type_uid).to eq 'embeddedrte'
|
92
|
+
expect(metadata.text).to eq ''
|
93
|
+
end
|
54
94
|
end
|
55
95
|
end
|
@@ -82,5 +82,221 @@ RSpec.describe ContentstackUtils::Model::Options do
|
|
82
82
|
expect(subject.render_option(ASSET_CONTENT_URL, getMetadata('entry', 'download', linkText))).
|
83
83
|
to eq "<a href='url'>#{linkText}</a>"
|
84
84
|
end
|
85
|
+
|
86
|
+
it 'Should return Mark text html' do
|
87
|
+
expect(subject.render_mark('bold', linkText)).
|
88
|
+
to eq "<strong>#{linkText}</strong>"
|
89
|
+
expect(subject.render_mark('italic', linkText)).
|
90
|
+
to eq "<em>#{linkText}</em>"
|
91
|
+
expect(subject.render_mark('underline', linkText)).
|
92
|
+
to eq "<u>#{linkText}</u>"
|
93
|
+
expect(subject.render_mark('strikethrough', linkText)).
|
94
|
+
to eq "<strike>#{linkText}</strike>"
|
95
|
+
expect(subject.render_mark('inlineCode', linkText)).
|
96
|
+
to eq "<span>#{linkText}</span>"
|
97
|
+
expect(subject.render_mark('subscript', linkText)).
|
98
|
+
to eq "<sub>#{linkText}</sub>"
|
99
|
+
expect(subject.render_mark('superscript', linkText)).
|
100
|
+
to eq "<sup>#{linkText}</sup>"
|
101
|
+
expect(subject.render_mark('', linkText)).
|
102
|
+
to eq linkText
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'Should return blank string for doc node type' do
|
106
|
+
doc = getJson(BlankDocument)
|
107
|
+
|
108
|
+
result = subject.render_node('doc', doc, linkText)
|
109
|
+
expect(result).to eq ""
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'Should return paragraph string for paragrpah node type' do
|
113
|
+
doc = getJson(BlankDocument)
|
114
|
+
|
115
|
+
result = subject.render_node('p', doc, linkText)
|
116
|
+
expect(result).to eq "<p>#{linkText}</p>"
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'Should return link string with blank href for link node type' do
|
120
|
+
doc = getJson(BlankDocument)
|
121
|
+
|
122
|
+
result = subject.render_node('a', doc, linkText)
|
123
|
+
expect(result).to eq "<a href=''>#{linkText}</a>"
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'Should return link string for link node type' do
|
127
|
+
doc = getJson(LinkInPJson)["children"][0]
|
128
|
+
|
129
|
+
result = subject.render_node('a', doc, linkText)
|
130
|
+
expect(result).to eq "<a href='#{doc["attrs"]["href"]}'>#{linkText}</a>"
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'Should return image string with blank src for image node type' do
|
134
|
+
doc = getJson(BlankDocument)
|
135
|
+
|
136
|
+
result = subject.render_node('img', doc, linkText)
|
137
|
+
expect(result).to eq "<img src='' />#{linkText}"
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'Should return link string for link node type' do
|
141
|
+
doc = getJson(ImgJson)["children"][0]
|
142
|
+
|
143
|
+
result = subject.render_node('img', doc, linkText)
|
144
|
+
expect(result).to eq "<img src='#{doc["attrs"]["src"]}' />#{linkText}"
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'Should return embed string with blank src for embed node type' do
|
148
|
+
doc = getJson(BlankDocument)
|
149
|
+
|
150
|
+
result = subject.render_node('embed', doc, linkText)
|
151
|
+
expect(result).to eq "<iframe src=''></iframe>"
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'Should return embed string for embed node type' do
|
155
|
+
doc = getJson(EmbedJson)["children"][0]
|
156
|
+
|
157
|
+
result = subject.render_node('embed', doc, linkText)
|
158
|
+
expect(result).to eq "<iframe src='#{doc["attrs"]["src"]}'></iframe>"
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'Should return Heading 1 string for Heading 1 node type' do
|
162
|
+
doc = getJson(BlankDocument)
|
163
|
+
|
164
|
+
result = subject.render_node('h1', doc, linkText)
|
165
|
+
expect(result).to eq "<h1>#{linkText}</h1>"
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'Should return Heading 2 string for Heading 2 node type' do
|
169
|
+
doc = getJson(BlankDocument)
|
170
|
+
|
171
|
+
result = subject.render_node('h2', doc, linkText)
|
172
|
+
expect(result).to eq "<h2>#{linkText}</h2>"
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'Should return Heading 3 string for Heading 3 node type' do
|
176
|
+
doc = getJson(BlankDocument)
|
177
|
+
|
178
|
+
result = subject.render_node('h3', doc, linkText)
|
179
|
+
expect(result).to eq "<h3>#{linkText}</h3>"
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'Should return Heading 4 string for Heading 4 node type' do
|
183
|
+
doc = getJson(BlankDocument)
|
184
|
+
|
185
|
+
result = subject.render_node('h4', doc, linkText)
|
186
|
+
expect(result).to eq "<h4>#{linkText}</h4>"
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'Should return Heading 5 string for Heading 5 node type' do
|
190
|
+
doc = getJson(BlankDocument)
|
191
|
+
|
192
|
+
result = subject.render_node('h5', doc, linkText)
|
193
|
+
expect(result).to eq "<h5>#{linkText}</h5>"
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'Should return Heading 6 string for Heading 6 node type' do
|
197
|
+
doc = getJson(BlankDocument)
|
198
|
+
|
199
|
+
result = subject.render_node('h6', doc, linkText)
|
200
|
+
expect(result).to eq "<h6>#{linkText}</h6>"
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'Should return Hr string for Hr node type' do
|
204
|
+
doc = getJson(BlankDocument)
|
205
|
+
|
206
|
+
result = subject.render_node('hr', doc, linkText)
|
207
|
+
expect(result).to eq "<hr />"
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'Should return order list string for order list node type' do
|
211
|
+
doc = getJson(BlankDocument)
|
212
|
+
|
213
|
+
result = subject.render_node('ol', doc, linkText)
|
214
|
+
expect(result).to eq "<ol>#{linkText}</ol>"
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'Should return Unorder list string for Unorder list node type' do
|
218
|
+
doc = getJson(BlankDocument)
|
219
|
+
|
220
|
+
result = subject.render_node('ul', doc, linkText)
|
221
|
+
expect(result).to eq "<ul>#{linkText}</ul>"
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'Should return list item string for list item node type' do
|
225
|
+
doc = getJson(BlankDocument)
|
226
|
+
|
227
|
+
result = subject.render_node('li', doc, linkText)
|
228
|
+
expect(result).to eq "<li>#{linkText}</li>"
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'Should return table string for table node type' do
|
232
|
+
doc = getJson(BlankDocument)
|
233
|
+
|
234
|
+
result = subject.render_node('table', doc, linkText)
|
235
|
+
expect(result).to eq "<table>#{linkText}</table>"
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'Should return thead string for thead node type' do
|
239
|
+
doc = getJson(BlankDocument)
|
240
|
+
|
241
|
+
result = subject.render_node('thead', doc, linkText)
|
242
|
+
expect(result).to eq "<thead>#{linkText}</thead>"
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'Should return tfoot string for tfoot node type' do
|
246
|
+
doc = getJson(BlankDocument)
|
247
|
+
|
248
|
+
result = subject.render_node('tfoot', doc, linkText)
|
249
|
+
expect(result).to eq "<tfoot>#{linkText}</tfoot>"
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'Should return tbody string fortbody node type' do
|
253
|
+
doc = getJson(BlankDocument)
|
254
|
+
|
255
|
+
result = subject.render_node('tbody', doc, linkText)
|
256
|
+
expect(result).to eq "<tbody>#{linkText}</tbody>"
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'Should return table row string for table row node type' do
|
260
|
+
doc = getJson(BlankDocument)
|
261
|
+
|
262
|
+
result = subject.render_node('tr', doc, linkText)
|
263
|
+
expect(result).to eq "<tr>#{linkText}</tr>"
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'Should return table head string for table head node type' do
|
267
|
+
doc = getJson(BlankDocument)
|
268
|
+
|
269
|
+
result = subject.render_node('th', doc, linkText)
|
270
|
+
expect(result).to eq "<th>#{linkText}</th>"
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'Should return table data string for table data node type' do
|
274
|
+
doc = getJson(BlankDocument)
|
275
|
+
|
276
|
+
result = subject.render_node('td', doc, linkText)
|
277
|
+
expect(result).to eq "<td>#{linkText}</td>"
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'Should return blockquote string for blockquote node type' do
|
281
|
+
doc = getJson(BlankDocument)
|
282
|
+
|
283
|
+
result = subject.render_node('blockquote', doc, linkText)
|
284
|
+
expect(result).to eq "<blockquote>#{linkText}</blockquote>"
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'Should return code string for code node type' do
|
288
|
+
doc = getJson(BlankDocument)
|
289
|
+
|
290
|
+
result = subject.render_node('code', doc, linkText)
|
291
|
+
expect(result).to eq "<code>#{linkText}</code>"
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'Should return blank string for reference node type' do
|
295
|
+
doc = getJson(BlankDocument)
|
296
|
+
|
297
|
+
result = subject.render_node('reference', doc, linkText)
|
298
|
+
expect(result).to eq ""
|
299
|
+
end
|
300
|
+
|
85
301
|
end
|
86
302
|
end
|
data/spec/lib/utils_spec.rb
CHANGED
@@ -59,6 +59,350 @@ RSpec.describe ContentstackUtils do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
|
63
|
+
describe '#JsonToHtml Array' do
|
64
|
+
it 'Should return blank string for blank doc' do
|
65
|
+
doc = getJson(BlankDocument)
|
66
|
+
|
67
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
68
|
+
|
69
|
+
expect(result).to eq [""]
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'Should return mark text string for PlainTextJson doc' do
|
73
|
+
doc = getJson(PlainTextJson)
|
74
|
+
|
75
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
76
|
+
|
77
|
+
expect(result).to eq [PlainTextHtml]
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'Should return paragraph string for ParagraphJson doc' do
|
81
|
+
doc = getJson(ParagraphJson)
|
82
|
+
|
83
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
84
|
+
|
85
|
+
expect(result).to eq [ParagraphHtml]
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'Should return H1 string for H1Json doc' do
|
89
|
+
doc = getJson(H1Json)
|
90
|
+
|
91
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
92
|
+
|
93
|
+
expect(result).to eq [H1Html]
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'Should return H2 string for H2Json doc' do
|
97
|
+
doc = getJson(H2Json)
|
98
|
+
|
99
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
100
|
+
|
101
|
+
expect(result).to eq [H2Html]
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'Should return H3 string for H3Json doc' do
|
105
|
+
doc = getJson(H3Json)
|
106
|
+
|
107
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
108
|
+
|
109
|
+
expect(result).to eq [H3Html]
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'Should return H4 string for H4Json doc' do
|
113
|
+
doc = getJson(H4Json)
|
114
|
+
|
115
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
116
|
+
|
117
|
+
expect(result).to eq [H4Html]
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'Should return H5 string for H5Json doc' do
|
121
|
+
doc = getJson(H5Json)
|
122
|
+
|
123
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
124
|
+
|
125
|
+
expect(result).to eq [H5Html]
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'Should return H6 string for H6Json doc' do
|
129
|
+
doc = getJson(H6Json)
|
130
|
+
|
131
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
132
|
+
|
133
|
+
expect(result).to eq [H6Html]
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'Should return Order List string for OrderListJson doc' do
|
137
|
+
doc = getJson(OrderListJson)
|
138
|
+
|
139
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
140
|
+
|
141
|
+
expect(result).to eq [OrderListHtml]
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'Should return Unorder List string for UnorderListJson doc' do
|
145
|
+
doc = getJson(UnorderListJson)
|
146
|
+
|
147
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
148
|
+
|
149
|
+
expect(result).to eq [UnorderListHtml]
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'Should return image string for ImgJson doc' do
|
153
|
+
doc = getJson(ImgJson)
|
154
|
+
|
155
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
156
|
+
|
157
|
+
expect(result).to eq [ImgHtml]
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'Should return Blockquote string for BlockquoteJson doc' do
|
161
|
+
doc = getJson(BlockquoteJson)
|
162
|
+
|
163
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
164
|
+
|
165
|
+
expect(result).to eq [BlockquoteHtml]
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'Should return Code string for CodeJson doc' do
|
169
|
+
doc = getJson(CodeJson)
|
170
|
+
|
171
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
172
|
+
|
173
|
+
expect(result).to eq [CodeHtml]
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'Should return Table string for TableJson doc' do
|
177
|
+
doc = getJson(TableJson)
|
178
|
+
|
179
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
180
|
+
|
181
|
+
expect(result).to eq [TableHtml]
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'Should return Link string for LinkInPJson doc' do
|
185
|
+
doc = getJson(LinkInPJson)
|
186
|
+
|
187
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
188
|
+
|
189
|
+
expect(result).to eq [LinkInPHtml]
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'Should return Embed string for EmbedJson doc' do
|
193
|
+
doc = getJson(EmbedJson)
|
194
|
+
|
195
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
196
|
+
|
197
|
+
expect(result).to eq [EmbedHtml]
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'Should return horizontal line string for horizontal line doc' do
|
201
|
+
doc = getJson(HRJson)
|
202
|
+
|
203
|
+
result = ContentstackUtils.json_to_html([doc], ContentstackUtils::Model::Options.new())
|
204
|
+
|
205
|
+
expect(result).to eq ['<hr />']
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe '#JsonToHtml' do
|
210
|
+
it 'Should return blank string for blank doc' do
|
211
|
+
doc = getJson(BlankDocument)
|
212
|
+
|
213
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
214
|
+
|
215
|
+
expect(result).to eq ""
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'Should return mark text string for PlainTextJson doc' do
|
219
|
+
doc = getJson(PlainTextJson)
|
220
|
+
|
221
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
222
|
+
|
223
|
+
expect(result).to eq PlainTextHtml
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'Should return paragraph string for ParagraphJson doc' do
|
227
|
+
doc = getJson(ParagraphJson)
|
228
|
+
|
229
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
230
|
+
|
231
|
+
expect(result).to eq ParagraphHtml
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'Should return H1 string for H1Json doc' do
|
235
|
+
doc = getJson(H1Json)
|
236
|
+
|
237
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
238
|
+
|
239
|
+
expect(result).to eq H1Html
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'Should return H2 string for H2Json doc' do
|
243
|
+
doc = getJson(H2Json)
|
244
|
+
|
245
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
246
|
+
|
247
|
+
expect(result).to eq H2Html
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'Should return H3 string for H3Json doc' do
|
251
|
+
doc = getJson(H3Json)
|
252
|
+
|
253
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
254
|
+
|
255
|
+
expect(result).to eq H3Html
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'Should return H4 string for H4Json doc' do
|
259
|
+
doc = getJson(H4Json)
|
260
|
+
|
261
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
262
|
+
|
263
|
+
expect(result).to eq H4Html
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'Should return H5 string for H5Json doc' do
|
267
|
+
doc = getJson(H5Json)
|
268
|
+
|
269
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
270
|
+
|
271
|
+
expect(result).to eq H5Html
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'Should return H6 string for H6Json doc' do
|
275
|
+
doc = getJson(H6Json)
|
276
|
+
|
277
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
278
|
+
|
279
|
+
expect(result).to eq H6Html
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'Should return Order List string for OrderListJson doc' do
|
283
|
+
doc = getJson(OrderListJson)
|
284
|
+
|
285
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
286
|
+
|
287
|
+
expect(result).to eq OrderListHtml
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'Should return Unorder List string for UnorderListJson doc' do
|
291
|
+
doc = getJson(UnorderListJson)
|
292
|
+
|
293
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
294
|
+
|
295
|
+
expect(result).to eq UnorderListHtml
|
296
|
+
end
|
297
|
+
|
298
|
+
it 'Should return image string for ImgJson doc' do
|
299
|
+
doc = getJson(ImgJson)
|
300
|
+
|
301
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
302
|
+
|
303
|
+
expect(result).to eq ImgHtml
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'Should return Blockquote string for BlockquoteJson doc' do
|
307
|
+
doc = getJson(BlockquoteJson)
|
308
|
+
|
309
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
310
|
+
|
311
|
+
expect(result).to eq BlockquoteHtml
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'Should return Code string for CodeJson doc' do
|
315
|
+
doc = getJson(CodeJson)
|
316
|
+
|
317
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
318
|
+
|
319
|
+
expect(result).to eq CodeHtml
|
320
|
+
end
|
321
|
+
|
322
|
+
it 'Should return Table string for TableJson doc' do
|
323
|
+
doc = getJson(TableJson)
|
324
|
+
|
325
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
326
|
+
|
327
|
+
expect(result).to eq TableHtml
|
328
|
+
end
|
329
|
+
|
330
|
+
it 'Should return Link string for LinkInPJson doc' do
|
331
|
+
doc = getJson(LinkInPJson)
|
332
|
+
|
333
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
334
|
+
|
335
|
+
expect(result).to eq LinkInPHtml
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'Should return Embed string for EmbedJson doc' do
|
339
|
+
doc = getJson(EmbedJson)
|
340
|
+
|
341
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
342
|
+
|
343
|
+
expect(result).to eq EmbedHtml
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'Should return horizontal line string for horizontal line doc' do
|
347
|
+
doc = getJson(HRJson)
|
348
|
+
|
349
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
350
|
+
|
351
|
+
expect(result).to eq '<hr />'
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'Should return horizontal line string for horizontal line doc' do
|
355
|
+
doc = getJson(H1NonChildJson)
|
356
|
+
|
357
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
358
|
+
|
359
|
+
expect(result).to eq '<h1></h1>'
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
describe '#JsonToHtml reference' do
|
364
|
+
it 'Should return blank string for non entry option' do
|
365
|
+
doc = getJson(AssetReferenceJson)
|
366
|
+
|
367
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new())
|
368
|
+
|
369
|
+
expect(result).to eq ''
|
370
|
+
end
|
371
|
+
|
372
|
+
it 'Should return asset embedded items' do
|
373
|
+
doc = getJson(AssetReferenceJson)
|
374
|
+
|
375
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new(JSON_EMBEDDED_ITEMS_ENTRY))
|
376
|
+
|
377
|
+
expect(result).to eq AssetReferenceHtml
|
378
|
+
end
|
379
|
+
|
380
|
+
it 'Should return entry block embedded items' do
|
381
|
+
doc = getJson(EntryReferenceBlockJson)
|
382
|
+
|
383
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new(JSON_EMBEDDED_ITEMS_ENTRY))
|
384
|
+
|
385
|
+
expect(result).to eq EntryReferenceBlockHtml
|
386
|
+
end
|
387
|
+
|
388
|
+
it 'Should return entry link embedded items' do
|
389
|
+
doc = getJson(EntryReferenceLinkJson)
|
390
|
+
|
391
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new(JSON_EMBEDDED_ITEMS_ENTRY))
|
392
|
+
|
393
|
+
expect(result).to eq EntryReferenceLinkHtml
|
394
|
+
end
|
395
|
+
|
396
|
+
it 'Should return entry inline embedded items' do
|
397
|
+
doc = getJson(EntryReferenceInlineJson)
|
398
|
+
|
399
|
+
result = ContentstackUtils.json_to_html(doc, ContentstackUtils::Model::Options.new(JSON_EMBEDDED_ITEMS_ENTRY))
|
400
|
+
|
401
|
+
expect(result).to eq EntryReferenceInlineHtml
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|
405
|
+
|
62
406
|
def makeRenderFunction(content, option = ContentstackUtils::Model::Options.new(ENTRY_EMBEDDED_ASSET))
|
63
407
|
ContentstackUtils.render_content(content, option)
|
64
408
|
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
|
2
|
+
PlainTextHtml = "<strong>Aliquam sit amet libero dapibus, eleifend ligula at, varius justo</strong><strong><em>Lorem ipsum</em></strong><strong><em><u>dolor sit amet</u></em></strong><strong><em><u><strike>consectetur adipiscing elit.</strike></u></em></strong><strong><em><u><span>Sed condimentum iaculis magna in vehicula. </span></u></em></strong><strong><em><u><sup>Vestibulum vitae convallis </sup></u></em></strong><strong><em><u><sub> lacus. </sub></u></em></strong>"
|
3
|
+
ParagraphHtml = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed condimentum iaculis magna in vehicula. Vestibulum vitae convallis lacus. Praesent a diam iaculis turpis rhoncus faucibus. Aliquam sed pulvinar sem.</p>"
|
4
|
+
H1Html = "<h1><strong><em><u><sub>Lorem ipsum dolor sit amet.</sub></u></em></strong></h1>"
|
5
|
+
H2Html = "<h2><strong><em><u><sub>Vestibulum a ligula eget massa sagittis aliquam sit amet quis tortor. </sub></u></em></strong></h2>"
|
6
|
+
H3Html = "<h3><strong><em><u><sub>Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.</sub></u></em></strong></h3>"
|
7
|
+
H4Html = "<h4><strong><em><u><sub>MaNullam feugiat turpis quis elit interdum, vitae laoreet quam viverra</sub></u></em></strong></h4>"
|
8
|
+
H5Html = "<h5>Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.</h5>"
|
9
|
+
H6Html = "<h6>Nunc porta diam vitae purus semper, ut consequat lorem vehicula.</h6>"
|
10
|
+
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>"
|
11
|
+
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
|
+
ImgHtml = "<img src='https://images.contentstack.com/v3/assets/blt7726e6b/bltb42cd1/5fa3be959bedb6b/Donald.jog.png' />"
|
13
|
+
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>"
|
14
|
+
BlockquoteHtml = "<blockquote>Praesent eu ex sed nibh venenatis pretium.</blockquote>"
|
15
|
+
CodeHtml = "<code>Code template.</code>"
|
16
|
+
LinkInPHtml = "<p><strong><em><u><sub></sub></u></em></strong><a href='LINK.com'>LINK</a></p>"
|
17
|
+
EmbedHtml = "<iframe src='https://www.youtube.com/watch?v=AOP0yARiW8U'></iframe>"
|
18
|
+
AssetReferenceHtml = "<img src='/v3/assets/blt333/blt44asset/dummy.pdf' alt='dummy.pdf' />"
|
19
|
+
EntryReferenceBlockHtml = "<div><p>Update this title</p><p>Content type: <span>content_block</span></p></div>"
|
20
|
+
EntryReferenceLinkHtml = "<a href='/copy-of-entry-final-02'>/copy-of-entry-final-02</a>"
|
21
|
+
EntryReferenceInlineHtml = "<span>updated title</span>"
|
22
|
+
|
23
|
+
BlankDocument = '{ "uid":"06e34a7a4e5d7fc2acd", "_version":13, "attrs":{ }, "children":[],"type":"doc"}'
|
24
|
+
PlainTextJson = '{ "uid":"06e34a7a4e5d7fc2acd", "_version":13, "attrs":{ }, "children":[{"text":"Aliquam sit amet libero dapibus, eleifend ligula at, varius justo","bold":true},{ "text":"Lorem ipsum","bold":true,"italic":true},{ "text":"dolor sit amet","bold":true,"italic":true,"underline":true},{ "text":"consectetur adipiscing elit.","bold":true,"italic":true,"underline":true,"strikethrough":true},{ "text":"Sed condimentum iaculis magna in vehicula. ","bold":true,"italic":true,"underline":true,"inlineCode":true},{ "text":"Vestibulum vitae convallis ","bold":true,"italic":true,"underline":true,"superscript":true},{ "text":" lacus. ","bold":true,"italic":true,"underline":true,"subscript":true}],"type":"doc"}'
|
25
|
+
H1Json = '{ "uid":"06e34a7a449d7fc2acd","_version":13,"attrs":{ },"children":[{ "type":"h1","attrs":{ },"uid":"c2dfed70 4d7030c65e2e1","children":[{ "text":"Lorem ipsum dolor sit amet.","bold":true,"italic":true,"underline":true,"subscript":true}]}],"type":"doc"}'
|
26
|
+
H2Json = '{ "uid":"06e34a7a4e2acd","_version":13,"attrs":{ },"children":[{ "type":"h2","attrs":{ },"uid":"c2dfed9a7030c65e2e1","children":[{ "text":"Vestibulum a ligula eget massa sagittis aliquam sit amet quis tortor. ","bold":true,"italic":true,"underline":true,"subscript":true}]}],"type":"doc"}'
|
27
|
+
H3Json = '{ "uid":"06e34ad7fc2acd","_version":13,"attrs":{ },"children":[{ "type":"h3","attrs":{ },"uid":"c2df42cfb70 4d7030c65e2e1","children":[{ "text":"Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.","bold":true,"italic":true,"underline":true,"subscript":true}]}],"type":"doc"}'
|
28
|
+
H4Json = '{ "uid":"06e34a7a4e54cd", "_version":13, "attrs":{ "style":{ "text-align":"center" }, "redactor-attributes":{ } }, "children":[{"type":"h4","attrs":{},"uid":"c2dfed4d7030c65e2e1","children":[{"text":"MaNullam feugiat turpis quis elit interdum, vitae laoreet quam viverra","bold":true,"italic":true,"underline":true,"subscript":true}]}],"type":"doc"}'
|
29
|
+
H5Json = '{ "uid": "06e381190849dacd", "_version": 13, "attrs": { }, "children": [ { "type": "h5", "attrs": {}, "uid": "c2d672242cfb7045e2e1", "children": [ { "text": "Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum." } ] } ], "type": "doc" }'
|
30
|
+
H6Json = '{ "uid": "06e34a71190849d7fcd", "_version": 13, "attrs": { }, "children": [ { "type": "h6", "attrs": {}, "uid": "c2dfa672242cfb7e2e1", "children": [ { "text": "Nunc porta diam vitae purus semper, ut consequat lorem vehicula." } ] } ], "type": "doc" }'
|
31
|
+
OrderListJson = '{ "uid":"06e35 48119084 9d7fc2acd", "_version":13, "attrs":{ }, "children":[{"uid":"2b5b4acbb3cfce02d3e","type":"ol","children":[{"type":"li","attrs":{"style":{"text-align":"justify"},"redactor-attributes":{ }},"uid":"160bbd7430b98bd3d996","children":[{"text":"Morbi in quam molestie, fermentum diam vitae, bibendum ipsum."}]},{ "type":"li","attrs":{ "style":{ "text-align":"justify"},"redactor-attributes":{ } },"uid":"a15f4d749bc2903d","children":[{ "text":"Pellentesque mattis lacus in quam aliquam congue"}]},{ "type":"li","attrs":{ "style":{ "text-align":"justify"},"redactor-attributes":{ } },"uid":"e54224bbcb6f9e8f1e43","children":[{ "text":"Integer feugiat leo dignissim, lobortis enim vitae, mollis lectus."}]},{ "type":"li","attrs":{ "style":{ "text-align":"justify"},"redactor-attributes":{ } },"uid":"c0148bab9af758784","children":[{ "text":"Sed in ante lacinia, molestie metus eu, fringilla sapien."}]}],"id":"7f413d448a","attrs":{ }}],"type":"doc"}'
|
32
|
+
UnorderListJson = '{ "uid":"0e5481190849a", "_version":13, "attrs":{ }, "children":[{"uid":"a3a2b443ebffc867b","type":"ul","children":[{"uid":"f67354d4eed64451922","type":"li","children":[{"text":"Sed quis metus sed mi hendrerit mollis vel et odio."}],"attrs":{ }},{ "uid":"5 50cba5 bea92f23e36fd1","type":"li","children":[{ "text":"Integer vitae sem dignissim, elementum libero vel, fringilla massa."}],"attrs":{ } },{ "uid":"0e5c9b4cd983e8fd543","type":"li","children":[{ "text":"Integer imperdiet arcu sit amet tortor faucibus aliquet."}],"attrs":{ } },{ "uid":"6d9a43a3816bd83a9a","type":"li","children":[{ "text":"Aenean scelerisque velit vitae dui vehicula, at congue massa sagittis."}],"attrs":{ } }],"id":"b083fa46ef899420ab19","attrs":{ }}],"type":"doc"}'
|
33
|
+
ImgJson = '{ "uid":"06e34a7a4849d7fc2acd", "_version":13, "attrs":{ }, "children":[{"uid":"f3be74be3b64646e626","type":"img","attrs":{"src":"https://images.contentstack.com/v3/assets/blt7726e6b/bltb42cd1/5fa3be959bedb6b/Donald.jog.png","width":33.69418132611637,"height":"auto","redactor-attributes":{"asset_uid":"47f1aa5ae422cd1"}},"children":[{"text":""}]}],"type":"doc"}'
|
34
|
+
ParagraphJson = '{ "uid":"0d7fd", "_version":13, "attrs":{ }, "children":[{"type":"p","attrs":{},"uid":"0a1b5676aa510e5a","children":[{"text":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed condimentum iaculis magna in vehicula. Vestibulum vitae convallis lacus. Praesent a diam iaculis turpis rhoncus faucibus. Aliquam sed pulvinar sem."}]}],"type":"doc"}'
|
35
|
+
BlockquoteJson = '{ "uid":"06084d7fd", "_version":13, "attrs":{ }, "children":[{"uid":"503f9cc97534db55","type":"blockquote","id":"431f78e567161460","children":[{"text":"Praesent eu ex sed nibh venenatis pretium."}],"attrs":{ }}],"type":"doc"}'
|
36
|
+
CodeJson = '{ "uid":"06ea490849d7fc2acd", "_version":13, "attrs":{ }, "children":[{"uid":"83fba92c91b30002b","type":"code","attrs":{},"children":[{"text":"Code template."}]}],"type":"doc"}'
|
37
|
+
TableJson = '{ "uid": "06e481190849d7fcd", "_version": 13, "attrs": { }, "children": [ { "uid": "6dd64343bf634bfadd4", "type": "table", "attrs": { "rows": 4, "cols": 2, "colWidths": [ 250, 250 ] }, "children": [ { "uid": "b9082", "type": "thead", "attrs": {}, "children": [ { "type": "tr", "attrs": {}, "children": [ { "type": "th", "attrs": {}, "children": [ { "type": "p", "attrs": {}, "children": [ { "text": "Header 1" } ], "uid": "daa3ef" } ], "uid": "4b3124414a3" }, { "type": "th", "attrs": { }, "children": [ { "type": "p", "attrs": { }, "children": [ { "text": "Header 2" } ], "uid": "eae83c5797d" } ], "uid": "bca9b6f037a04fb485" } ], "uid": "b91ae7a48ef2e9da1" } ] }, { "type": "tbody", "attrs": { }, "children": [ { "type": "tr", "attrs": { }, "children": [ { "type": "td", "attrs": { }, "children": [ { "type": "p", "attrs": { }, "children": [ { "text": "Body row 1 data 1" } ], "uid": "ec674ccc5ce70b7cab" } ], "uid": "2a70bdeeb99a" }, { "type": "td", "attrs": { }, "children": [ { "type": "p", "attrs": { }, "children": [ { "text": "Body row 1 data 2" } ], "uid": "769a 3f9db34 ce8ec 10486d50" } ], "uid": "d6407 34a5c6 1ab1e5f7d1" } ], "uid": "77f6 b951c68 7f9eb397c5" }, { "type": "tr", "attrs": { }, "children": [ { "type": "td", "attrs": { }, "children": [ { "type": "p", "attrs": { }, "children": [ { "text": "Body row 2 data 1" } ], "uid": "a6bf 11bb48 630e87d721c0" } ], "uid": "3da39838b0feaf" }, { "type": "td", "attrs": { }, "children": [ { "type": "p", "attrs": { }, "children": [ { "text": "Body row 2 data 2" } ], "uid": "3b7d12 1f694202 49029e86313" } ], "uid": "95b38b04abcbc25e94f" } ], "uid": "b 227fea 8d247013 4f1e1e8" } ], "uid": "fd5ab86aa642798451b" } ] } ], "type": "doc" }'
|
38
|
+
LinkInPJson = '{ "uid":"06e34a7190849d7f2acd", "_version":13, "attrs":{ }, "children":[{"type":"p","attrs":{"style":{"text-align":"left"},"redactor-attributes":{ }},"uid":"d88dcdf4590dff2d","children":[{"text":"","bold":true,"italic":true,"underline":true,"subscript":true},{ "uid":"0d06598201aa8b47","type":"a","attrs":{ "href":"LINK.com","target":"_self"},"children":[{ "text":"LINK"}]},{ "text":""}]}],"type":"doc"}'
|
39
|
+
EmbedJson = '{ "uid":"06e34a7190849d7f2acd", "_version":13, "attrs":{ }, "children":[{"uid":"251017315905c35d42c9","type":"embed","attrs":{"src":"https://www.youtube.com/watch?v=AOP0yARiW8U"},"children":[{"text":""}]}],"type":"doc"}'
|
40
|
+
AssetReferenceJson = '{"uid":"06e34a7 5e4 e549d ", "_version":1, "attrs":{}, "children":[{ "uid": "4f7e33 3390a955 de10c1 c836", "type":"reference","attrs":{"display-type":"display","asset-uid":"blt44asset","content-type-uid":"sys_assets","asset-link":"https://images.contentstack.com/v3/assets/blt77263d3e6b/blt73403ee7281/51807f919e0e4/11.jpg","asset-name":"11.jpg","asset-type":"image/jpeg","type":"asset","class-name":"embedded-asset","width":25.16914749661705,"className":"dsd","id":"sdf"},"children":[{"text":""}]}],"type":"doc"}'
|
41
|
+
EntryReferenceBlockJson = '{ "uid":"06e34a7 5e4 e549d ", "_version":1, "attrs":{ }, "children":[{"uid":"70f9b 325075d43 128c0d0 aa3eb7f291f","type":"reference","attrs":{"display-type":"block","entry-uid":"blttitleuid","content-type-uid":"content_block","locale":"en-us","type":"entry","class-name":"embedded-entry"},"children":[{"text":""}]}],"type":"doc"}'
|
42
|
+
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":"bltemmbedEntryuid","content-type-uid":"embeddedrte","locale":"en-us","type":"entry","class-name":"embedded-entry"},"children":[{"text":"/copy-of-entry-final-02"}]}],"type":"doc"}'
|
43
|
+
EntryReferenceInlineJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":{ }, "children":[{"uid":"506 4878f3f46 s21f0cbc aff","type":"reference","attrs":{"display-type":"inline","entry-uid":"blttitleUpdateuid","content-type-uid":"embeddedrte","locale":"en-us","type":"entry","class-name":"embedded-entry"},"children":[{"text":""}]}],"type":"doc"}'
|
44
|
+
HRJson = '{ "uid":"06e34a7 5e4 e549d", "_version":1, "attrs":{ }, "children":[{"uid":"f5a7b57 40a8a5c3 576828276b","type":"hr","children":[{"text":""}],"attrs":{ }}],"type":"doc"}'
|
45
|
+
H1NonChildJson = '{ "uid":"06e34a7a449d7fc2acd","_version":13,"attrs":{ },"children":[{ "type":"h1","attrs":{ },"uid":"c2dfed70 4d7030c65e2e1"}],"type":"doc"}'
|
46
|
+
|
47
|
+
|
48
|
+
JSON_EMBEDDED_ITEMS_ENTRY= {
|
49
|
+
"title"=> 'one',
|
50
|
+
"url"=> '/one',
|
51
|
+
"locale"=> 'en-us',
|
52
|
+
"uid"=> 'blt88jn',
|
53
|
+
"created_by"=> 'bltcreate',
|
54
|
+
"updated_by"=> 'bltcreate',
|
55
|
+
"created_at"=> '2020-08-13T06:18:18.989Z',
|
56
|
+
"updated_at"=> '2020-08-31T06:06:31.258Z',
|
57
|
+
"markdown"=> '',
|
58
|
+
"_embedded_items"=> {
|
59
|
+
"rich_text_editor"=> [
|
60
|
+
{
|
61
|
+
"_content_type_uid"=> 'sys_assets',
|
62
|
+
"uid"=> 'blt44asset',
|
63
|
+
"created_at"=> '2020-08-19T09:13:32.785Z',
|
64
|
+
"updated_at"=> '2020-08-19T09:13:32.785Z',
|
65
|
+
"created_by"=> 'bltcreate',
|
66
|
+
"updated_by"=> 'bltcreate',
|
67
|
+
"content_type"=> 'application/pdf',
|
68
|
+
"file_size"=> '13264',
|
69
|
+
"filename"=> 'dummy.pdf',
|
70
|
+
"url"=> '/v3/assets/blt333/blt44asset/dummy.pdf',
|
71
|
+
"_version"=> 1,
|
72
|
+
"title"=> 'dummy.pdf'
|
73
|
+
},
|
74
|
+
{
|
75
|
+
"title"=> 'Update this title',
|
76
|
+
"url"=> '',
|
77
|
+
"locale"=> 'en-us',
|
78
|
+
"uid"=> 'blttitleuid',
|
79
|
+
"_content_type_uid"=> 'content_block',
|
80
|
+
"_version"=> 5,
|
81
|
+
"_in_progress"=> false,
|
82
|
+
"multi_line"=> '',
|
83
|
+
"_embedded_items"=> {
|
84
|
+
"rich_text_editor"=> [
|
85
|
+
{
|
86
|
+
"uid"=> 'blttitleuid',
|
87
|
+
"_content_type_uid"=> 'content_block'
|
88
|
+
}
|
89
|
+
]
|
90
|
+
},
|
91
|
+
"rich_text_editor"=> '<figure class="embedded-entry inline-entry" data-sys-entry-uid="blttitleuid" data-sys-entry-"locale"="en-us" data-sys-content-type-uid="content_block" sys-style-type="inline" type="entry"></figure>',
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"title"=> 'updated title',
|
95
|
+
"rich_text_editor"=> [
|
96
|
+
'<figure class="embedded-asset" data-sys-asset-filelink="https://contentstack.image/DIABETICDIET-800x600.jpg" data-sys-asset-uid="bltassetUID" data-sys-asset-filename="DIABETICDIET-800x600.jpg" data-sys-asset-contenttype="image/jpeg" type="asset" sys-style-type="display"></figure>'
|
97
|
+
],
|
98
|
+
"locale"=> 'en-us',
|
99
|
+
"uid"=> 'blttitleUpdateuid',
|
100
|
+
"_content_type_uid"=> 'embeddedrte',
|
101
|
+
"_in_progress"=> false,
|
102
|
+
"_embedded_items"=> {
|
103
|
+
"rich_text_editor"=>[
|
104
|
+
{
|
105
|
+
"_content_type_uid"=> 'sys_assets',
|
106
|
+
"uid"=> 'bltassetUID',
|
107
|
+
"content_type"=> 'image/png',
|
108
|
+
"file_size"=> '36743',
|
109
|
+
"filename"=> 'svg-logo-text.png',
|
110
|
+
"url"=> '/v3/assets/blturl/bltassetEmbuid/svg-logo-text.png',
|
111
|
+
"title"=> 'svg-logo-text.png',
|
112
|
+
"description"=> ''
|
113
|
+
}
|
114
|
+
]
|
115
|
+
}
|
116
|
+
},
|
117
|
+
{
|
118
|
+
"title"=> 'Entry with embedded entry',
|
119
|
+
"rich_text_editor"=> [
|
120
|
+
'<figure class="embedded-entry block-entry" data-sys-entry-uid="blt1234CtUID" data-sys-content-type-uid="1234" sys-style-type="block" type="entry"></figure>\n<figure class="embedded-entry inline-entry" data-sys-entry-uid="blt1234CtUID" data-sys-content-type-uid="1234" sys-style-type="inline" type="entry"></figure>\n<p><br><br></p>\n<figure class="embedded-asset" data-sys-asset-filelink="https://contentstack.image/v3/assets/blt/html5.png" data-sys-asset-uid="blt1234AssetUID" data-sys-asset-filename="html5.png" data-sys-asset-contenttype="image/png" type="asset" sys-style-type="display"></figure>'
|
121
|
+
],
|
122
|
+
"locale"=> 'en-us',
|
123
|
+
"uid"=> 'bltemmbedEntryuid',
|
124
|
+
"_content_type_uid"=> 'embeddedrte',
|
125
|
+
"_in_progress"=> false,
|
126
|
+
"_embedded_items"=> {
|
127
|
+
"rich_text_editor"=>[
|
128
|
+
{
|
129
|
+
"uid"=> 'blt1234CtUID',
|
130
|
+
"_content_type_uid"=> '1234'
|
131
|
+
},
|
132
|
+
{
|
133
|
+
"uid"=> 'blt1234CtUID',
|
134
|
+
"_content_type_uid"=> '1234'
|
135
|
+
},
|
136
|
+
{
|
137
|
+
"uid"=> 'blt1234AssetUID',
|
138
|
+
"_content_type_uid"=> 'sys_assets'
|
139
|
+
}
|
140
|
+
]
|
141
|
+
},
|
142
|
+
}
|
143
|
+
]
|
144
|
+
}
|
145
|
+
}
|
data/spec/support/xml_parse.rb
CHANGED
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.0.2
|
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-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- spec/lib/utils_spec.rb
|
150
150
|
- spec/mock/constant_render_options.rb
|
151
151
|
- spec/mock/custom_render_option.rb
|
152
|
+
- spec/mock/json_to_html_mock.rb
|
152
153
|
- spec/spec_helper.rb
|
153
154
|
- spec/support/constant.rb
|
154
155
|
- spec/support/xml_parse.rb
|
@@ -181,6 +182,7 @@ test_files:
|
|
181
182
|
- spec/lib/utils_spec.rb
|
182
183
|
- spec/mock/constant_render_options.rb
|
183
184
|
- spec/mock/custom_render_option.rb
|
185
|
+
- spec/mock/json_to_html_mock.rb
|
184
186
|
- spec/spec_helper.rb
|
185
187
|
- spec/support/constant.rb
|
186
188
|
- spec/support/xml_parse.rb
|