rich_text_renderer 0.1.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +1 -1
- data/lib/rich_text_renderer/block_renderers/asset_block_renderer.rb +27 -0
- data/lib/rich_text_renderer/block_renderers/asset_hyperlink_renderer.rb +64 -0
- data/lib/rich_text_renderer/block_renderers/blockquote_renderer.rb +1 -1
- data/lib/rich_text_renderer/block_renderers/entry_block_renderer.rb +1 -1
- data/lib/rich_text_renderer/block_renderers.rb +2 -0
- data/lib/rich_text_renderer/renderer.rb +2 -0
- data/lib/rich_text_renderer/text_renderers/text_renderer.rb +2 -0
- data/lib/rich_text_renderer/version.rb +1 -1
- metadata +9 -165
- data/.gitignore +0 -7
- data/.rspec +0 -1
- data/.rubocop.yml +0 -27
- data/.rubocop_todo.yml +0 -35
- data/.travis.yml +0 -13
- data/.yardopts +0 -4
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -110
- data/Guardfile +0 -24
- data/Rakefile +0 -33
- data/coverage/.last_run.json +0 -5
- data/coverage/.resultset.json +0 -1372
- data/coverage/.resultset.json.lock +0 -0
- data/coverage/assets/0.10.2/application.css +0 -799
- data/coverage/assets/0.10.2/application.js +0 -1707
- data/coverage/assets/0.10.2/colorbox/border.png +0 -0
- data/coverage/assets/0.10.2/colorbox/controls.png +0 -0
- data/coverage/assets/0.10.2/colorbox/loading.gif +0 -0
- data/coverage/assets/0.10.2/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.10.2/favicon_green.png +0 -0
- data/coverage/assets/0.10.2/favicon_red.png +0 -0
- data/coverage/assets/0.10.2/favicon_yellow.png +0 -0
- data/coverage/assets/0.10.2/loading.gif +0 -0
- data/coverage/assets/0.10.2/magnify.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +0 -9146
- data/doc/RichTextRenderer/BaseBlockRenderer.html +0 -242
- data/doc/RichTextRenderer/BaseInlineRenderer.html +0 -242
- data/doc/RichTextRenderer/BaseNodeRenderer.html +0 -300
- data/doc/RichTextRenderer/BlockQuoteRenderer.html +0 -169
- data/doc/RichTextRenderer/BoldRenderer.html +0 -169
- data/doc/RichTextRenderer/CodeRenderer.html +0 -169
- data/doc/RichTextRenderer/DocumentRenderer.html +0 -242
- data/doc/RichTextRenderer/EntryBlockRenderer.html +0 -239
- data/doc/RichTextRenderer/HeadingFiveRenderer.html +0 -169
- data/doc/RichTextRenderer/HeadingFourRenderer.html +0 -169
- data/doc/RichTextRenderer/HeadingOneRenderer.html +0 -169
- data/doc/RichTextRenderer/HeadingSixRenderer.html +0 -169
- data/doc/RichTextRenderer/HeadingThreeRenderer.html +0 -169
- data/doc/RichTextRenderer/HeadingTwoRenderer.html +0 -169
- data/doc/RichTextRenderer/HrRenderer.html +0 -238
- data/doc/RichTextRenderer/HyperlinkRenderer.html +0 -246
- data/doc/RichTextRenderer/ItalicRenderer.html +0 -169
- data/doc/RichTextRenderer/ListItemRenderer.html +0 -169
- data/doc/RichTextRenderer/NullRenderer.html +0 -238
- data/doc/RichTextRenderer/OrderedListRenderer.html +0 -169
- data/doc/RichTextRenderer/ParagraphRenderer.html +0 -169
- data/doc/RichTextRenderer/Renderer.html +0 -349
- data/doc/RichTextRenderer/TextRenderer.html +0 -254
- data/doc/RichTextRenderer/UnderlineRenderer.html +0 -169
- data/doc/RichTextRenderer/UnorderedListRenderer.html +0 -169
- data/doc/RichTextRenderer.html +0 -155
- data/doc/StructuredTextRenderer/BaseBlockRenderer.html +0 -242
- data/doc/StructuredTextRenderer/BaseInlineRenderer.html +0 -242
- data/doc/StructuredTextRenderer/BaseNodeRenderer.html +0 -300
- data/doc/StructuredTextRenderer/BoldRenderer.html +0 -169
- data/doc/StructuredTextRenderer/CodeRenderer.html +0 -169
- data/doc/StructuredTextRenderer/DocumentRenderer.html +0 -242
- data/doc/StructuredTextRenderer/EntryBlockRenderer.html +0 -239
- data/doc/StructuredTextRenderer/HeadingFiveRenderer.html +0 -169
- data/doc/StructuredTextRenderer/HeadingFourRenderer.html +0 -169
- data/doc/StructuredTextRenderer/HeadingOneRenderer.html +0 -169
- data/doc/StructuredTextRenderer/HeadingSixRenderer.html +0 -169
- data/doc/StructuredTextRenderer/HeadingThreeRenderer.html +0 -169
- data/doc/StructuredTextRenderer/HeadingTwoRenderer.html +0 -169
- data/doc/StructuredTextRenderer/HrRenderer.html +0 -238
- data/doc/StructuredTextRenderer/HyperlinkRenderer.html +0 -246
- data/doc/StructuredTextRenderer/ItalicRenderer.html +0 -169
- data/doc/StructuredTextRenderer/ListItemRenderer.html +0 -169
- data/doc/StructuredTextRenderer/NullRenderer.html +0 -238
- data/doc/StructuredTextRenderer/OrderedListRenderer.html +0 -169
- data/doc/StructuredTextRenderer/ParagraphRenderer.html +0 -169
- data/doc/StructuredTextRenderer/QuoteRenderer.html +0 -169
- data/doc/StructuredTextRenderer/Renderer.html +0 -349
- data/doc/StructuredTextRenderer/TextRenderer.html +0 -254
- data/doc/StructuredTextRenderer/UnderlineRenderer.html +0 -169
- data/doc/StructuredTextRenderer/UnorderedListRenderer.html +0 -169
- data/doc/StructuredTextRenderer.html +0 -155
- data/doc/_index.html +0 -387
- data/doc/class_list.html +0 -51
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -58
- data/doc/css/style.css +0 -496
- data/doc/file.CHANGELOG.html +0 -91
- data/doc/file.LICENSE.html +0 -70
- data/doc/file.README.html +0 -170
- data/doc/file_list.html +0 -66
- data/doc/frames.html +0 -17
- data/doc/index.html +0 -170
- data/doc/js/app.js +0 -292
- data/doc/js/full_list.js +0 -216
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -147
- data/doc/top-level-namespace.html +0 -110
- data/rich_text_renderer.gemspec +0 -30
- data/spec/lib/rich_text_renderer/block_renderers/base_block_renderer_spec.rb +0 -26
- data/spec/lib/rich_text_renderer/block_renderers/blockquote_renderer_spec.rb +0 -25
- data/spec/lib/rich_text_renderer/block_renderers/entry_block_renderer_spec.rb +0 -15
- data/spec/lib/rich_text_renderer/block_renderers/heading_five_renderer_spec.rb +0 -24
- data/spec/lib/rich_text_renderer/block_renderers/heading_four_renderer_spec.rb +0 -24
- data/spec/lib/rich_text_renderer/block_renderers/heading_one_renderer_spec.rb +0 -24
- data/spec/lib/rich_text_renderer/block_renderers/heading_six_renderer_spec.rb +0 -24
- data/spec/lib/rich_text_renderer/block_renderers/heading_three_renderer_spec.rb +0 -24
- data/spec/lib/rich_text_renderer/block_renderers/heading_two_renderer_spec.rb +0 -24
- data/spec/lib/rich_text_renderer/block_renderers/hr_renderer_spec.rb +0 -13
- data/spec/lib/rich_text_renderer/block_renderers/hyperlink_renderer_spec.rb +0 -24
- data/spec/lib/rich_text_renderer/block_renderers/list_item_renderer_spec.rb +0 -24
- data/spec/lib/rich_text_renderer/block_renderers/ordered_list_renderer_spec.rb +0 -56
- data/spec/lib/rich_text_renderer/block_renderers/paragraph_renderer_spec.rb +0 -30
- data/spec/lib/rich_text_renderer/block_renderers/unordered_list_renderer_spec.rb +0 -56
- data/spec/lib/rich_text_renderer/document_renderers/document_renderer_spec.rb +0 -42
- data/spec/lib/rich_text_renderer/null_renderer_spec.rb +0 -19
- data/spec/lib/rich_text_renderer/renderer_spec.rb +0 -308
- data/spec/lib/rich_text_renderer/text_renderers/base_inline_renderer_spec.rb +0 -11
- data/spec/lib/rich_text_renderer/text_renderers/bold_renderer_spec.rb +0 -11
- data/spec/lib/rich_text_renderer/text_renderers/code_renderer_spec.rb +0 -11
- data/spec/lib/rich_text_renderer/text_renderers/italic_renderer_spec.rb +0 -11
- data/spec/lib/rich_text_renderer/text_renderers/text_renderer_spec.rb +0 -53
- data/spec/lib/rich_text_renderer/text_renderers/underline_renderer_spec.rb +0 -11
- data/spec/spec_helper.rb +0 -82
@@ -1,308 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
full_document = {
|
4
|
-
"content" => [
|
5
|
-
{
|
6
|
-
"data" => {},
|
7
|
-
"content" => [
|
8
|
-
{
|
9
|
-
"marks" => [],
|
10
|
-
"value" => "Some heading",
|
11
|
-
"nodeType" => "text",
|
12
|
-
"nodeClass" => "text",
|
13
|
-
}
|
14
|
-
],
|
15
|
-
"nodeType" => "heading-1",
|
16
|
-
"nodeClass" => "block",
|
17
|
-
},
|
18
|
-
{
|
19
|
-
"data" => {},
|
20
|
-
"content" => [
|
21
|
-
{"marks" => [], "value" => "", "nodeType" => "text", "nodeClass" => "text"}
|
22
|
-
],
|
23
|
-
"nodeType" => "paragraph",
|
24
|
-
"nodeClass" => "block",
|
25
|
-
},
|
26
|
-
{
|
27
|
-
"data" => {
|
28
|
-
"target" => {
|
29
|
-
"sys" => {
|
30
|
-
"id" => "49rofLvvxCOiIMIi6mk8ai",
|
31
|
-
"type" => "Link",
|
32
|
-
"linkType" => "Entry",
|
33
|
-
}
|
34
|
-
}
|
35
|
-
},
|
36
|
-
"content" => [
|
37
|
-
{"marks" => [], "value" => "", "nodeType" => "text", "nodeClass" => "text"}
|
38
|
-
],
|
39
|
-
"nodeType" => "embedded-entry-block",
|
40
|
-
"nodeClass" => "block",
|
41
|
-
},
|
42
|
-
{
|
43
|
-
"data" => {},
|
44
|
-
"content" => [
|
45
|
-
{
|
46
|
-
"marks" => [],
|
47
|
-
"value" => "Some subheading",
|
48
|
-
"nodeType" => "text",
|
49
|
-
"nodeClass" => "text",
|
50
|
-
}
|
51
|
-
],
|
52
|
-
"nodeType" => "heading-2",
|
53
|
-
"nodeClass" => "block",
|
54
|
-
},
|
55
|
-
{
|
56
|
-
"data" => {},
|
57
|
-
"content" => [
|
58
|
-
{
|
59
|
-
"marks" => [{"data" => {}, "type" => "bold", "object" => "mark"}],
|
60
|
-
"value" => "Some bold",
|
61
|
-
"nodeType" => "text",
|
62
|
-
"nodeClass" => "text",
|
63
|
-
}
|
64
|
-
],
|
65
|
-
"nodeType" => "paragraph",
|
66
|
-
"nodeClass" => "block",
|
67
|
-
},
|
68
|
-
{
|
69
|
-
"data" => {},
|
70
|
-
"content" => [
|
71
|
-
{
|
72
|
-
"marks" => [{"data" => {}, "type" => "italic", "object" => "mark"}],
|
73
|
-
"value" => "Some italics",
|
74
|
-
"nodeType" => "text",
|
75
|
-
"nodeClass" => "text",
|
76
|
-
}
|
77
|
-
],
|
78
|
-
"nodeType" => "paragraph",
|
79
|
-
"nodeClass" => "block",
|
80
|
-
},
|
81
|
-
{
|
82
|
-
"data" => {},
|
83
|
-
"content" => [
|
84
|
-
{
|
85
|
-
"marks" => [{"data" => {}, "type" => "underline", "object" => "mark"}],
|
86
|
-
"value" => "Some underline",
|
87
|
-
"nodeType" => "text",
|
88
|
-
"nodeClass" => "text",
|
89
|
-
}
|
90
|
-
],
|
91
|
-
"nodeType" => "paragraph",
|
92
|
-
"nodeClass" => "block",
|
93
|
-
},
|
94
|
-
{
|
95
|
-
"data" => {},
|
96
|
-
"content" => [
|
97
|
-
{"marks" => [], "value" => "", "nodeType" => "text", "nodeClass" => "text"}
|
98
|
-
],
|
99
|
-
"nodeType" => "paragraph",
|
100
|
-
"nodeClass" => "block",
|
101
|
-
},
|
102
|
-
{
|
103
|
-
"data" => {},
|
104
|
-
"content" => [
|
105
|
-
{"marks" => [], "value" => "", "nodeType" => "text", "nodeClass" => "text"}
|
106
|
-
],
|
107
|
-
"nodeType" => "paragraph",
|
108
|
-
"nodeClass" => "block",
|
109
|
-
},
|
110
|
-
{
|
111
|
-
"data" => {
|
112
|
-
"target" => {
|
113
|
-
"sys" => {
|
114
|
-
"id" => "5ZF9Q4K6iWSYIU2OUs0UaQ",
|
115
|
-
"type" => "Link",
|
116
|
-
"linkType" => "Entry",
|
117
|
-
}
|
118
|
-
}
|
119
|
-
},
|
120
|
-
"content" => [
|
121
|
-
{"marks" => [], "value" => "", "nodeType" => "text", "nodeClass" => "text"}
|
122
|
-
],
|
123
|
-
"nodeType" => "embedded-entry-block",
|
124
|
-
"nodeClass" => "block",
|
125
|
-
},
|
126
|
-
{
|
127
|
-
"data" => {},
|
128
|
-
"content" => [
|
129
|
-
{"marks" => [], "value" => "", "nodeType" => "text", "nodeClass" => "text"}
|
130
|
-
],
|
131
|
-
"nodeType" => "paragraph",
|
132
|
-
"nodeClass" => "block",
|
133
|
-
},
|
134
|
-
{
|
135
|
-
"data" => {},
|
136
|
-
"content" => [
|
137
|
-
{
|
138
|
-
"marks" => [],
|
139
|
-
"value" => "Some raw content",
|
140
|
-
"nodeType" => "text",
|
141
|
-
"nodeClass" => "text",
|
142
|
-
}
|
143
|
-
],
|
144
|
-
"nodeType" => "paragraph",
|
145
|
-
"nodeClass" => "block",
|
146
|
-
},
|
147
|
-
{
|
148
|
-
"data" => {},
|
149
|
-
"content" => [
|
150
|
-
{"marks" => [], "value" => "", "nodeType" => "text", "nodeClass" => "text"}
|
151
|
-
],
|
152
|
-
"nodeType" => "paragraph",
|
153
|
-
"nodeClass" => "block",
|
154
|
-
},
|
155
|
-
{
|
156
|
-
"data" => {},
|
157
|
-
"content" => [
|
158
|
-
{
|
159
|
-
"marks" => [],
|
160
|
-
"value" => "An unpublished embed:",
|
161
|
-
"nodeType" => "text",
|
162
|
-
"nodeClass" => "text",
|
163
|
-
}
|
164
|
-
],
|
165
|
-
"nodeType" => "paragraph",
|
166
|
-
"nodeClass" => "block",
|
167
|
-
},
|
168
|
-
{
|
169
|
-
"data" => {},
|
170
|
-
"content" => [
|
171
|
-
{"marks" => [], "value" => "", "nodeType" => "text", "nodeClass" => "text"}
|
172
|
-
],
|
173
|
-
"nodeType" => "paragraph",
|
174
|
-
"nodeClass" => "block",
|
175
|
-
},
|
176
|
-
{
|
177
|
-
"data" => {
|
178
|
-
"target" => {
|
179
|
-
"sys" => {
|
180
|
-
"id" => "q2hGXkd5tICym64AcgeKK",
|
181
|
-
"type" => "Link",
|
182
|
-
"linkType" => "Entry",
|
183
|
-
}
|
184
|
-
}
|
185
|
-
},
|
186
|
-
"content" => [
|
187
|
-
{"marks" => [], "value" => "", "nodeType" => "text", "nodeClass" => "text"}
|
188
|
-
],
|
189
|
-
"nodeType" => "embedded-entry-block",
|
190
|
-
"nodeClass" => "block",
|
191
|
-
},
|
192
|
-
{
|
193
|
-
"data" => {},
|
194
|
-
"content" => [
|
195
|
-
{
|
196
|
-
"marks" => [],
|
197
|
-
"value" => "Some more content",
|
198
|
-
"nodeType" => "text",
|
199
|
-
"nodeClass" => "text",
|
200
|
-
}
|
201
|
-
],
|
202
|
-
"nodeType" => "paragraph",
|
203
|
-
"nodeClass" => "block",
|
204
|
-
},
|
205
|
-
],
|
206
|
-
"nodeType" => "document",
|
207
|
-
"nodeClass" => "document",
|
208
|
-
}
|
209
|
-
|
210
|
-
describe RichTextRenderer::Renderer do
|
211
|
-
subject { described_class.new }
|
212
|
-
|
213
|
-
describe '#render' do
|
214
|
-
it 'by default renders html' do
|
215
|
-
expect(subject.render(full_document)).to eq [
|
216
|
-
"<h1>Some heading</h1>",
|
217
|
-
"<p></p>",
|
218
|
-
'<div>{"target"=>{"sys"=>{"id"=>"49rofLvvxCOiIMIi6mk8ai", "type"=>"Link", "linkType"=>"Entry"}}}</div>',
|
219
|
-
"<h2>Some subheading</h2>",
|
220
|
-
"<p><b>Some bold</b></p>",
|
221
|
-
"<p><i>Some italics</i></p>",
|
222
|
-
"<p><u>Some underline</u></p>",
|
223
|
-
"<p></p>",
|
224
|
-
"<p></p>",
|
225
|
-
'<div>{"target"=>{"sys"=>{"id"=>"5ZF9Q4K6iWSYIU2OUs0UaQ", "type"=>"Link", "linkType"=>"Entry"}}}</div>',
|
226
|
-
"<p></p>",
|
227
|
-
"<p>Some raw content</p>",
|
228
|
-
"<p></p>",
|
229
|
-
"<p>An unpublished embed:</p>",
|
230
|
-
"<p></p>",
|
231
|
-
'<div>{"target"=>{"sys"=>{"id"=>"q2hGXkd5tICym64AcgeKK", "type"=>"Link", "linkType"=>"Entry"}}}</div>',
|
232
|
-
"<p>Some more content</p>",
|
233
|
-
].join("\n")
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe 'with all renderers overridden' do
|
238
|
-
subject do
|
239
|
-
described_class.new(
|
240
|
-
'heading-1' => HeadingOneMarkdownRenderer,
|
241
|
-
'heading-2' => HeadingTwoMarkdownRenderer,
|
242
|
-
'paragraph' => ParagraphMarkdownRenderer,
|
243
|
-
'embedded-entry-block' => EntryBlockMarkdownRenderer,
|
244
|
-
'bold' => BoldMarkdownRenderer,
|
245
|
-
'italic' => ItalicMarkdownRenderer,
|
246
|
-
'underline' => UnderlineMarkdownRenderer
|
247
|
-
)
|
248
|
-
end
|
249
|
-
|
250
|
-
it 'renders with the overridden renderers' do
|
251
|
-
expect(subject.render(full_document)).to eq [
|
252
|
-
"# Some heading",
|
253
|
-
"",
|
254
|
-
"",
|
255
|
-
"",
|
256
|
-
"",
|
257
|
-
"```",
|
258
|
-
'{"target"=>{"sys"=>{"id"=>"49rofLvvxCOiIMIi6mk8ai", "type"=>"Link", "linkType"=>"Entry"}}}',
|
259
|
-
"```",
|
260
|
-
"",
|
261
|
-
"## Some subheading",
|
262
|
-
"",
|
263
|
-
"**Some bold**",
|
264
|
-
"",
|
265
|
-
"",
|
266
|
-
"*Some italics*",
|
267
|
-
"",
|
268
|
-
"",
|
269
|
-
"__Some underline__",
|
270
|
-
"",
|
271
|
-
"",
|
272
|
-
"",
|
273
|
-
"",
|
274
|
-
"",
|
275
|
-
"",
|
276
|
-
"",
|
277
|
-
"",
|
278
|
-
"```",
|
279
|
-
'{"target"=>{"sys"=>{"id"=>"5ZF9Q4K6iWSYIU2OUs0UaQ", "type"=>"Link", "linkType"=>"Entry"}}}',
|
280
|
-
"```",
|
281
|
-
"",
|
282
|
-
"",
|
283
|
-
"",
|
284
|
-
"",
|
285
|
-
"",
|
286
|
-
"Some raw content",
|
287
|
-
"",
|
288
|
-
"",
|
289
|
-
"",
|
290
|
-
"",
|
291
|
-
"",
|
292
|
-
"An unpublished embed:",
|
293
|
-
"",
|
294
|
-
"",
|
295
|
-
"",
|
296
|
-
"",
|
297
|
-
"",
|
298
|
-
"```",
|
299
|
-
'{"target"=>{"sys"=>{"id"=>"q2hGXkd5tICym64AcgeKK", "type"=>"Link", "linkType"=>"Entry"}}}',
|
300
|
-
"```",
|
301
|
-
"",
|
302
|
-
"",
|
303
|
-
"Some more content",
|
304
|
-
""
|
305
|
-
].join("\n")
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
mock_node_underline_only = {"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "underline"}]}
|
4
|
-
|
5
|
-
mock_node_italic_only = {"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "italic"}]}
|
6
|
-
|
7
|
-
mock_node_bold_only = {"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]}
|
8
|
-
|
9
|
-
mock_node_multiple_marks = {
|
10
|
-
"value" => "foo",
|
11
|
-
"nodeType" => "text",
|
12
|
-
"marks" => [{"type" => "underline"}, {"type" => "italic"}, {"type" => "bold"}],
|
13
|
-
}
|
14
|
-
|
15
|
-
mock_node_unsupported_mark = {"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "foobar"}]}
|
16
|
-
|
17
|
-
describe RichTextRenderer::TextRenderer do
|
18
|
-
subject do
|
19
|
-
described_class.new(
|
20
|
-
'text' => RichTextRenderer::TextRenderer,
|
21
|
-
'bold' => RichTextRenderer::BoldRenderer,
|
22
|
-
'italic' => RichTextRenderer::ItalicRenderer,
|
23
|
-
'underline' => RichTextRenderer::UnderlineRenderer,
|
24
|
-
nil => RichTextRenderer::NullRenderer
|
25
|
-
)
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#render' do
|
29
|
-
it 'can render with a single mark' do
|
30
|
-
expect(subject.render(mock_node_bold_only)).to eq "<b>foo</b>"
|
31
|
-
expect(subject.render(mock_node_italic_only)).to eq "<i>foo</i>"
|
32
|
-
expect(subject.render(mock_node_underline_only)).to eq "<u>foo</u>"
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'can render multiple marks' do
|
36
|
-
expect(subject.render(mock_node_multiple_marks)).to eq "<b><i><u>foo</u></i></b>"
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'raises an error for unsupported marks' do
|
40
|
-
expect { subject.render(mock_node_unsupported_mark) }.to raise_error "No renderer defined for 'foobar' nodes"
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'supports custom renderers' do
|
44
|
-
subject = described_class.new(
|
45
|
-
'text' => RichTextRenderer::TextRenderer,
|
46
|
-
'bold' => BoldMarkdownRenderer,
|
47
|
-
nil => RichTextRenderer::NullRenderer
|
48
|
-
)
|
49
|
-
|
50
|
-
expect(subject.render(mock_node_bold_only)).to eq "**foo**"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
SimpleCov.start unless RUBY_PLATFORM == 'java'
|
3
|
-
|
4
|
-
require 'rspec'
|
5
|
-
require 'rich_text_renderer'
|
6
|
-
|
7
|
-
RSpec.configure do |config|
|
8
|
-
config.filter_run :focus => true
|
9
|
-
config.run_all_when_everything_filtered = true
|
10
|
-
end
|
11
|
-
|
12
|
-
class NodeRenderer
|
13
|
-
attr_reader :mappings
|
14
|
-
|
15
|
-
def initialize(mappings = {})
|
16
|
-
@mappings = mappings
|
17
|
-
end
|
18
|
-
|
19
|
-
protected
|
20
|
-
|
21
|
-
def find_renderer(node)
|
22
|
-
renderer = mappings[node['nodeType']]
|
23
|
-
return if renderer.nil?
|
24
|
-
renderer.new(mappings)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class HeadingOneMarkdownRenderer < NodeRenderer
|
29
|
-
def render(node)
|
30
|
-
node['content'].each_with_object([]) do |c, res|
|
31
|
-
renderer = find_renderer(c)
|
32
|
-
next if renderer.nil?
|
33
|
-
res << "# #{renderer.render(c)}"
|
34
|
-
end.join("\n")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class HeadingTwoMarkdownRenderer < NodeRenderer
|
39
|
-
def render(node)
|
40
|
-
node['content'].each_with_object([]) do |c, res|
|
41
|
-
renderer = find_renderer(c)
|
42
|
-
next if renderer.nil?
|
43
|
-
res << "## #{renderer.render(c)}"
|
44
|
-
end.join("\n")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class ParagraphMarkdownRenderer < NodeRenderer
|
49
|
-
def render(node)
|
50
|
-
paragraphs = node['content'].each_with_object([]) do |c, res|
|
51
|
-
renderer = find_renderer(c)
|
52
|
-
next if renderer.nil?
|
53
|
-
res << "#{renderer.render(c)}"
|
54
|
-
end.join("\n")
|
55
|
-
|
56
|
-
"\n#{paragraphs}\n"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
class EntryBlockMarkdownRenderer < NodeRenderer
|
61
|
-
def render(node)
|
62
|
-
"\n```\n#{node['data']}\n```\n"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class BoldMarkdownRenderer < NodeRenderer
|
67
|
-
def render(node)
|
68
|
-
"**#{node['value']}**"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
class ItalicMarkdownRenderer < NodeRenderer
|
73
|
-
def render(node)
|
74
|
-
"*#{node['value']}*"
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
class UnderlineMarkdownRenderer < NodeRenderer
|
79
|
-
def render(node)
|
80
|
-
"__#{node['value']}__"
|
81
|
-
end
|
82
|
-
end
|