contentstack_utils 1.0.1 → 1.1.1
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 +3 -2
- data/CHANGELOG.md +5 -0
- data/CODEOWNERS +1 -0
- data/Gemfile.lock +13 -13
- data/LICENSE +1 -1
- data/README.md +9 -0
- data/SECURITY.md +27 -0
- data/lib/contentstack_utils/model/metadata.rb +36 -11
- data/lib/contentstack_utils/model/options.rb +84 -5
- data/lib/contentstack_utils/utils.rb +109 -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 +223 -0
- data/spec/lib/utils_spec.rb +578 -0
- data/spec/mock/json_to_html_mock.rb +147 -0
- data/spec/spec_helper.rb +1 -2
- data/spec/support/constant.rb +116 -116
- data/spec/support/xml_parse.rb +18 -0
- metadata +16 -12
@@ -82,5 +82,228 @@ 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 link string for link node type' do
|
148
|
+
doc = getJson(ImgJsonURL)["children"][0]
|
149
|
+
|
150
|
+
result = subject.render_node('img', doc, linkText)
|
151
|
+
expect(result).to eq "<img src='#{doc["attrs"]["url"]}' />#{linkText}"
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'Should return embed string with blank src for embed node type' do
|
155
|
+
doc = getJson(BlankDocument)
|
156
|
+
|
157
|
+
result = subject.render_node('embed', doc, linkText)
|
158
|
+
expect(result).to eq "<iframe src=''></iframe>"
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'Should return embed string for embed node type' do
|
162
|
+
doc = getJson(EmbedJson)["children"][0]
|
163
|
+
|
164
|
+
result = subject.render_node('embed', doc, linkText)
|
165
|
+
expect(result).to eq "<iframe src='#{doc["attrs"]["src"]}'></iframe>"
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'Should return Heading 1 string for Heading 1 node type' do
|
169
|
+
doc = getJson(BlankDocument)
|
170
|
+
|
171
|
+
result = subject.render_node('h1', doc, linkText)
|
172
|
+
expect(result).to eq "<h1>#{linkText}</h1>"
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'Should return Heading 2 string for Heading 2 node type' do
|
176
|
+
doc = getJson(BlankDocument)
|
177
|
+
|
178
|
+
result = subject.render_node('h2', doc, linkText)
|
179
|
+
expect(result).to eq "<h2>#{linkText}</h2>"
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'Should return Heading 3 string for Heading 3 node type' do
|
183
|
+
doc = getJson(BlankDocument)
|
184
|
+
|
185
|
+
result = subject.render_node('h3', doc, linkText)
|
186
|
+
expect(result).to eq "<h3>#{linkText}</h3>"
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'Should return Heading 4 string for Heading 4 node type' do
|
190
|
+
doc = getJson(BlankDocument)
|
191
|
+
|
192
|
+
result = subject.render_node('h4', doc, linkText)
|
193
|
+
expect(result).to eq "<h4>#{linkText}</h4>"
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'Should return Heading 5 string for Heading 5 node type' do
|
197
|
+
doc = getJson(BlankDocument)
|
198
|
+
|
199
|
+
result = subject.render_node('h5', doc, linkText)
|
200
|
+
expect(result).to eq "<h5>#{linkText}</h5>"
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'Should return Heading 6 string for Heading 6 node type' do
|
204
|
+
doc = getJson(BlankDocument)
|
205
|
+
|
206
|
+
result = subject.render_node('h6', doc, linkText)
|
207
|
+
expect(result).to eq "<h6>#{linkText}</h6>"
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'Should return Hr string for Hr node type' do
|
211
|
+
doc = getJson(BlankDocument)
|
212
|
+
|
213
|
+
result = subject.render_node('hr', doc, linkText)
|
214
|
+
expect(result).to eq "<hr />"
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'Should return order list string for order list node type' do
|
218
|
+
doc = getJson(BlankDocument)
|
219
|
+
|
220
|
+
result = subject.render_node('ol', doc, linkText)
|
221
|
+
expect(result).to eq "<ol>#{linkText}</ol>"
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'Should return Unorder list string for Unorder list node type' do
|
225
|
+
doc = getJson(BlankDocument)
|
226
|
+
|
227
|
+
result = subject.render_node('ul', doc, linkText)
|
228
|
+
expect(result).to eq "<ul>#{linkText}</ul>"
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'Should return list item string for list item node type' do
|
232
|
+
doc = getJson(BlankDocument)
|
233
|
+
|
234
|
+
result = subject.render_node('li', doc, linkText)
|
235
|
+
expect(result).to eq "<li>#{linkText}</li>"
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'Should return table string for table node type' do
|
239
|
+
doc = getJson(BlankDocument)
|
240
|
+
|
241
|
+
result = subject.render_node('table', doc, linkText)
|
242
|
+
expect(result).to eq "<table>#{linkText}</table>"
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'Should return thead string for thead node type' do
|
246
|
+
doc = getJson(BlankDocument)
|
247
|
+
|
248
|
+
result = subject.render_node('thead', doc, linkText)
|
249
|
+
expect(result).to eq "<thead>#{linkText}</thead>"
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'Should return tfoot string for tfoot node type' do
|
253
|
+
doc = getJson(BlankDocument)
|
254
|
+
|
255
|
+
result = subject.render_node('tfoot', doc, linkText)
|
256
|
+
expect(result).to eq "<tfoot>#{linkText}</tfoot>"
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'Should return tbody string fortbody node type' do
|
260
|
+
doc = getJson(BlankDocument)
|
261
|
+
|
262
|
+
result = subject.render_node('tbody', doc, linkText)
|
263
|
+
expect(result).to eq "<tbody>#{linkText}</tbody>"
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'Should return table row string for table row node type' do
|
267
|
+
doc = getJson(BlankDocument)
|
268
|
+
|
269
|
+
result = subject.render_node('tr', doc, linkText)
|
270
|
+
expect(result).to eq "<tr>#{linkText}</tr>"
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'Should return table head string for table head node type' do
|
274
|
+
doc = getJson(BlankDocument)
|
275
|
+
|
276
|
+
result = subject.render_node('th', doc, linkText)
|
277
|
+
expect(result).to eq "<th>#{linkText}</th>"
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'Should return table data string for table data node type' do
|
281
|
+
doc = getJson(BlankDocument)
|
282
|
+
|
283
|
+
result = subject.render_node('td', doc, linkText)
|
284
|
+
expect(result).to eq "<td>#{linkText}</td>"
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'Should return blockquote string for blockquote node type' do
|
288
|
+
doc = getJson(BlankDocument)
|
289
|
+
|
290
|
+
result = subject.render_node('blockquote', doc, linkText)
|
291
|
+
expect(result).to eq "<blockquote>#{linkText}</blockquote>"
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'Should return code string for code node type' do
|
295
|
+
doc = getJson(BlankDocument)
|
296
|
+
|
297
|
+
result = subject.render_node('code', doc, linkText)
|
298
|
+
expect(result).to eq "<code>#{linkText}</code>"
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'Should return blank string for reference node type' do
|
302
|
+
doc = getJson(BlankDocument)
|
303
|
+
|
304
|
+
result = subject.render_node('reference', doc, linkText)
|
305
|
+
expect(result).to eq ""
|
306
|
+
end
|
307
|
+
|
85
308
|
end
|
86
309
|
end
|