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.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/README.md +1 -1
  4. data/lib/rich_text_renderer/block_renderers/asset_block_renderer.rb +27 -0
  5. data/lib/rich_text_renderer/block_renderers/asset_hyperlink_renderer.rb +64 -0
  6. data/lib/rich_text_renderer/block_renderers/blockquote_renderer.rb +1 -1
  7. data/lib/rich_text_renderer/block_renderers/entry_block_renderer.rb +1 -1
  8. data/lib/rich_text_renderer/block_renderers.rb +2 -0
  9. data/lib/rich_text_renderer/renderer.rb +2 -0
  10. data/lib/rich_text_renderer/text_renderers/text_renderer.rb +2 -0
  11. data/lib/rich_text_renderer/version.rb +1 -1
  12. metadata +9 -165
  13. data/.gitignore +0 -7
  14. data/.rspec +0 -1
  15. data/.rubocop.yml +0 -27
  16. data/.rubocop_todo.yml +0 -35
  17. data/.travis.yml +0 -13
  18. data/.yardopts +0 -4
  19. data/Gemfile +0 -3
  20. data/Gemfile.lock +0 -110
  21. data/Guardfile +0 -24
  22. data/Rakefile +0 -33
  23. data/coverage/.last_run.json +0 -5
  24. data/coverage/.resultset.json +0 -1372
  25. data/coverage/.resultset.json.lock +0 -0
  26. data/coverage/assets/0.10.2/application.css +0 -799
  27. data/coverage/assets/0.10.2/application.js +0 -1707
  28. data/coverage/assets/0.10.2/colorbox/border.png +0 -0
  29. data/coverage/assets/0.10.2/colorbox/controls.png +0 -0
  30. data/coverage/assets/0.10.2/colorbox/loading.gif +0 -0
  31. data/coverage/assets/0.10.2/colorbox/loading_background.png +0 -0
  32. data/coverage/assets/0.10.2/favicon_green.png +0 -0
  33. data/coverage/assets/0.10.2/favicon_red.png +0 -0
  34. data/coverage/assets/0.10.2/favicon_yellow.png +0 -0
  35. data/coverage/assets/0.10.2/loading.gif +0 -0
  36. data/coverage/assets/0.10.2/magnify.png +0 -0
  37. data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  38. data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  39. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  40. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  41. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  42. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  43. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  44. data/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  45. data/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png +0 -0
  46. data/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  47. data/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png +0 -0
  48. data/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png +0 -0
  49. data/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  50. data/coverage/index.html +0 -9146
  51. data/doc/RichTextRenderer/BaseBlockRenderer.html +0 -242
  52. data/doc/RichTextRenderer/BaseInlineRenderer.html +0 -242
  53. data/doc/RichTextRenderer/BaseNodeRenderer.html +0 -300
  54. data/doc/RichTextRenderer/BlockQuoteRenderer.html +0 -169
  55. data/doc/RichTextRenderer/BoldRenderer.html +0 -169
  56. data/doc/RichTextRenderer/CodeRenderer.html +0 -169
  57. data/doc/RichTextRenderer/DocumentRenderer.html +0 -242
  58. data/doc/RichTextRenderer/EntryBlockRenderer.html +0 -239
  59. data/doc/RichTextRenderer/HeadingFiveRenderer.html +0 -169
  60. data/doc/RichTextRenderer/HeadingFourRenderer.html +0 -169
  61. data/doc/RichTextRenderer/HeadingOneRenderer.html +0 -169
  62. data/doc/RichTextRenderer/HeadingSixRenderer.html +0 -169
  63. data/doc/RichTextRenderer/HeadingThreeRenderer.html +0 -169
  64. data/doc/RichTextRenderer/HeadingTwoRenderer.html +0 -169
  65. data/doc/RichTextRenderer/HrRenderer.html +0 -238
  66. data/doc/RichTextRenderer/HyperlinkRenderer.html +0 -246
  67. data/doc/RichTextRenderer/ItalicRenderer.html +0 -169
  68. data/doc/RichTextRenderer/ListItemRenderer.html +0 -169
  69. data/doc/RichTextRenderer/NullRenderer.html +0 -238
  70. data/doc/RichTextRenderer/OrderedListRenderer.html +0 -169
  71. data/doc/RichTextRenderer/ParagraphRenderer.html +0 -169
  72. data/doc/RichTextRenderer/Renderer.html +0 -349
  73. data/doc/RichTextRenderer/TextRenderer.html +0 -254
  74. data/doc/RichTextRenderer/UnderlineRenderer.html +0 -169
  75. data/doc/RichTextRenderer/UnorderedListRenderer.html +0 -169
  76. data/doc/RichTextRenderer.html +0 -155
  77. data/doc/StructuredTextRenderer/BaseBlockRenderer.html +0 -242
  78. data/doc/StructuredTextRenderer/BaseInlineRenderer.html +0 -242
  79. data/doc/StructuredTextRenderer/BaseNodeRenderer.html +0 -300
  80. data/doc/StructuredTextRenderer/BoldRenderer.html +0 -169
  81. data/doc/StructuredTextRenderer/CodeRenderer.html +0 -169
  82. data/doc/StructuredTextRenderer/DocumentRenderer.html +0 -242
  83. data/doc/StructuredTextRenderer/EntryBlockRenderer.html +0 -239
  84. data/doc/StructuredTextRenderer/HeadingFiveRenderer.html +0 -169
  85. data/doc/StructuredTextRenderer/HeadingFourRenderer.html +0 -169
  86. data/doc/StructuredTextRenderer/HeadingOneRenderer.html +0 -169
  87. data/doc/StructuredTextRenderer/HeadingSixRenderer.html +0 -169
  88. data/doc/StructuredTextRenderer/HeadingThreeRenderer.html +0 -169
  89. data/doc/StructuredTextRenderer/HeadingTwoRenderer.html +0 -169
  90. data/doc/StructuredTextRenderer/HrRenderer.html +0 -238
  91. data/doc/StructuredTextRenderer/HyperlinkRenderer.html +0 -246
  92. data/doc/StructuredTextRenderer/ItalicRenderer.html +0 -169
  93. data/doc/StructuredTextRenderer/ListItemRenderer.html +0 -169
  94. data/doc/StructuredTextRenderer/NullRenderer.html +0 -238
  95. data/doc/StructuredTextRenderer/OrderedListRenderer.html +0 -169
  96. data/doc/StructuredTextRenderer/ParagraphRenderer.html +0 -169
  97. data/doc/StructuredTextRenderer/QuoteRenderer.html +0 -169
  98. data/doc/StructuredTextRenderer/Renderer.html +0 -349
  99. data/doc/StructuredTextRenderer/TextRenderer.html +0 -254
  100. data/doc/StructuredTextRenderer/UnderlineRenderer.html +0 -169
  101. data/doc/StructuredTextRenderer/UnorderedListRenderer.html +0 -169
  102. data/doc/StructuredTextRenderer.html +0 -155
  103. data/doc/_index.html +0 -387
  104. data/doc/class_list.html +0 -51
  105. data/doc/css/common.css +0 -1
  106. data/doc/css/full_list.css +0 -58
  107. data/doc/css/style.css +0 -496
  108. data/doc/file.CHANGELOG.html +0 -91
  109. data/doc/file.LICENSE.html +0 -70
  110. data/doc/file.README.html +0 -170
  111. data/doc/file_list.html +0 -66
  112. data/doc/frames.html +0 -17
  113. data/doc/index.html +0 -170
  114. data/doc/js/app.js +0 -292
  115. data/doc/js/full_list.js +0 -216
  116. data/doc/js/jquery.js +0 -4
  117. data/doc/method_list.html +0 -147
  118. data/doc/top-level-namespace.html +0 -110
  119. data/rich_text_renderer.gemspec +0 -30
  120. data/spec/lib/rich_text_renderer/block_renderers/base_block_renderer_spec.rb +0 -26
  121. data/spec/lib/rich_text_renderer/block_renderers/blockquote_renderer_spec.rb +0 -25
  122. data/spec/lib/rich_text_renderer/block_renderers/entry_block_renderer_spec.rb +0 -15
  123. data/spec/lib/rich_text_renderer/block_renderers/heading_five_renderer_spec.rb +0 -24
  124. data/spec/lib/rich_text_renderer/block_renderers/heading_four_renderer_spec.rb +0 -24
  125. data/spec/lib/rich_text_renderer/block_renderers/heading_one_renderer_spec.rb +0 -24
  126. data/spec/lib/rich_text_renderer/block_renderers/heading_six_renderer_spec.rb +0 -24
  127. data/spec/lib/rich_text_renderer/block_renderers/heading_three_renderer_spec.rb +0 -24
  128. data/spec/lib/rich_text_renderer/block_renderers/heading_two_renderer_spec.rb +0 -24
  129. data/spec/lib/rich_text_renderer/block_renderers/hr_renderer_spec.rb +0 -13
  130. data/spec/lib/rich_text_renderer/block_renderers/hyperlink_renderer_spec.rb +0 -24
  131. data/spec/lib/rich_text_renderer/block_renderers/list_item_renderer_spec.rb +0 -24
  132. data/spec/lib/rich_text_renderer/block_renderers/ordered_list_renderer_spec.rb +0 -56
  133. data/spec/lib/rich_text_renderer/block_renderers/paragraph_renderer_spec.rb +0 -30
  134. data/spec/lib/rich_text_renderer/block_renderers/unordered_list_renderer_spec.rb +0 -56
  135. data/spec/lib/rich_text_renderer/document_renderers/document_renderer_spec.rb +0 -42
  136. data/spec/lib/rich_text_renderer/null_renderer_spec.rb +0 -19
  137. data/spec/lib/rich_text_renderer/renderer_spec.rb +0 -308
  138. data/spec/lib/rich_text_renderer/text_renderers/base_inline_renderer_spec.rb +0 -11
  139. data/spec/lib/rich_text_renderer/text_renderers/bold_renderer_spec.rb +0 -11
  140. data/spec/lib/rich_text_renderer/text_renderers/code_renderer_spec.rb +0 -11
  141. data/spec/lib/rich_text_renderer/text_renderers/italic_renderer_spec.rb +0 -11
  142. data/spec/lib/rich_text_renderer/text_renderers/text_renderer_spec.rb +0 -53
  143. data/spec/lib/rich_text_renderer/text_renderers/underline_renderer_spec.rb +0 -11
  144. 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,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- mock_node = {"value" => "foo"}
4
-
5
- describe RichTextRenderer::BaseInlineRenderer do
6
- subject { described_class.new }
7
-
8
- it 'renders as a span' do
9
- expect(subject.render(mock_node)).to eq "<span>foo</span>"
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- mock_node = {"value" => "foo"}
4
-
5
- describe RichTextRenderer::BoldRenderer do
6
- subject { described_class.new }
7
-
8
- it 'renders as a b' do
9
- expect(subject.render(mock_node)).to eq "<b>foo</b>"
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- mock_node = {"value" => "foo"}
4
-
5
- describe RichTextRenderer::CodeRenderer do
6
- subject { described_class.new }
7
-
8
- it 'renders as a code' do
9
- expect(subject.render(mock_node)).to eq "<code>foo</code>"
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- mock_node = {"value" => "foo"}
4
-
5
- describe RichTextRenderer::ItalicRenderer do
6
- subject { described_class.new }
7
-
8
- it 'renders as a i' do
9
- expect(subject.render(mock_node)).to eq "<i>foo</i>"
10
- end
11
- 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
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- mock_node = {"value" => "foo"}
4
-
5
- describe RichTextRenderer::UnderlineRenderer do
6
- subject { described_class.new }
7
-
8
- it 'renders as a u' do
9
- expect(subject.render(mock_node)).to eq "<u>foo</u>"
10
- end
11
- 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