structured_text_renderer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +27 -0
  5. data/.rubocop_todo.yml +35 -0
  6. data/.travis.yml +13 -0
  7. data/.yardopts +4 -0
  8. data/CHANGELOG.md +5 -0
  9. data/Gemfile +3 -0
  10. data/Gemfile.lock +110 -0
  11. data/Guardfile +24 -0
  12. data/LICENSE.txt +21 -0
  13. data/README.md +87 -0
  14. data/Rakefile +33 -0
  15. data/coverage/.last_run.json +5 -0
  16. data/coverage/.resultset.json +1366 -0
  17. data/coverage/.resultset.json.lock +0 -0
  18. data/coverage/assets/0.10.2/application.css +799 -0
  19. data/coverage/assets/0.10.2/application.js +1707 -0
  20. data/coverage/assets/0.10.2/colorbox/border.png +0 -0
  21. data/coverage/assets/0.10.2/colorbox/controls.png +0 -0
  22. data/coverage/assets/0.10.2/colorbox/loading.gif +0 -0
  23. data/coverage/assets/0.10.2/colorbox/loading_background.png +0 -0
  24. data/coverage/assets/0.10.2/favicon_green.png +0 -0
  25. data/coverage/assets/0.10.2/favicon_red.png +0 -0
  26. data/coverage/assets/0.10.2/favicon_yellow.png +0 -0
  27. data/coverage/assets/0.10.2/loading.gif +0 -0
  28. data/coverage/assets/0.10.2/magnify.png +0 -0
  29. data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  30. data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  31. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  32. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  33. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  34. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  35. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  36. data/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  37. data/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png +0 -0
  38. data/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  39. data/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png +0 -0
  40. data/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png +0 -0
  41. data/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  42. data/coverage/index.html +9110 -0
  43. data/doc/StructuredTextRenderer/BaseBlockRenderer.html +248 -0
  44. data/doc/StructuredTextRenderer/BaseInlineRenderer.html +242 -0
  45. data/doc/StructuredTextRenderer/BaseNodeRenderer.html +300 -0
  46. data/doc/StructuredTextRenderer/BoldRenderer.html +169 -0
  47. data/doc/StructuredTextRenderer/CodeRenderer.html +169 -0
  48. data/doc/StructuredTextRenderer/DocumentRenderer.html +242 -0
  49. data/doc/StructuredTextRenderer/EntryBlockRenderer.html +239 -0
  50. data/doc/StructuredTextRenderer/HeadingFiveRenderer.html +169 -0
  51. data/doc/StructuredTextRenderer/HeadingFourRenderer.html +169 -0
  52. data/doc/StructuredTextRenderer/HeadingOneRenderer.html +169 -0
  53. data/doc/StructuredTextRenderer/HeadingSixRenderer.html +169 -0
  54. data/doc/StructuredTextRenderer/HeadingThreeRenderer.html +169 -0
  55. data/doc/StructuredTextRenderer/HeadingTwoRenderer.html +169 -0
  56. data/doc/StructuredTextRenderer/HrRenderer.html +238 -0
  57. data/doc/StructuredTextRenderer/HyperlinkRenderer.html +254 -0
  58. data/doc/StructuredTextRenderer/ItalicRenderer.html +169 -0
  59. data/doc/StructuredTextRenderer/ListItemRenderer.html +169 -0
  60. data/doc/StructuredTextRenderer/NullRenderer.html +238 -0
  61. data/doc/StructuredTextRenderer/OrderedListRenderer.html +169 -0
  62. data/doc/StructuredTextRenderer/ParagraphRenderer.html +169 -0
  63. data/doc/StructuredTextRenderer/QuoteRenderer.html +169 -0
  64. data/doc/StructuredTextRenderer/Renderer.html +349 -0
  65. data/doc/StructuredTextRenderer/TextRenderer.html +254 -0
  66. data/doc/StructuredTextRenderer/UnderlineRenderer.html +169 -0
  67. data/doc/StructuredTextRenderer/UnorderedListRenderer.html +169 -0
  68. data/doc/StructuredTextRenderer.html +155 -0
  69. data/doc/_index.html +403 -0
  70. data/doc/class_list.html +51 -0
  71. data/doc/css/common.css +1 -0
  72. data/doc/css/full_list.css +58 -0
  73. data/doc/css/style.css +496 -0
  74. data/doc/file.CHANGELOG.html +77 -0
  75. data/doc/file.LICENSE.html +70 -0
  76. data/doc/file.README.html +171 -0
  77. data/doc/file_list.html +66 -0
  78. data/doc/frames.html +17 -0
  79. data/doc/index.html +171 -0
  80. data/doc/js/app.js +292 -0
  81. data/doc/js/full_list.js +216 -0
  82. data/doc/js/jquery.js +4 -0
  83. data/doc/method_list.html +147 -0
  84. data/doc/top-level-namespace.html +110 -0
  85. data/lib/structured_text_renderer/base_node_renderer.rb +18 -0
  86. data/lib/structured_text_renderer/block_renderers/base_block_renderer.rb +20 -0
  87. data/lib/structured_text_renderer/block_renderers/entry_block_renderer.rb +13 -0
  88. data/lib/structured_text_renderer/block_renderers/heading_five_renderer.rb +12 -0
  89. data/lib/structured_text_renderer/block_renderers/heading_four_renderer.rb +12 -0
  90. data/lib/structured_text_renderer/block_renderers/heading_one_renderer.rb +12 -0
  91. data/lib/structured_text_renderer/block_renderers/heading_six_renderer.rb +12 -0
  92. data/lib/structured_text_renderer/block_renderers/heading_three_renderer.rb +12 -0
  93. data/lib/structured_text_renderer/block_renderers/heading_two_renderer.rb +12 -0
  94. data/lib/structured_text_renderer/block_renderers/hr_renderer.rb +11 -0
  95. data/lib/structured_text_renderer/block_renderers/hyperlink_renderer.rb +15 -0
  96. data/lib/structured_text_renderer/block_renderers/list_item_renderer.rb +12 -0
  97. data/lib/structured_text_renderer/block_renderers/ordered_list_renderer.rb +12 -0
  98. data/lib/structured_text_renderer/block_renderers/paragraph_renderer.rb +12 -0
  99. data/lib/structured_text_renderer/block_renderers/quote_renderer.rb +12 -0
  100. data/lib/structured_text_renderer/block_renderers/unordered_list_renderer.rb +12 -0
  101. data/lib/structured_text_renderer/block_renderers.rb +18 -0
  102. data/lib/structured_text_renderer/document_renderers/document_renderer.rb +13 -0
  103. data/lib/structured_text_renderer/document_renderers.rb +1 -0
  104. data/lib/structured_text_renderer/null_renderer.rb +19 -0
  105. data/lib/structured_text_renderer/renderer.rb +46 -0
  106. data/lib/structured_text_renderer/text_renderers/base_inline_renderer.rb +17 -0
  107. data/lib/structured_text_renderer/text_renderers/bold_renderer.rb +12 -0
  108. data/lib/structured_text_renderer/text_renderers/code_renderer.rb +12 -0
  109. data/lib/structured_text_renderer/text_renderers/italic_renderer.rb +12 -0
  110. data/lib/structured_text_renderer/text_renderers/text_renderer.rb +19 -0
  111. data/lib/structured_text_renderer/text_renderers/underline_renderer.rb +12 -0
  112. data/lib/structured_text_renderer/text_renderers.rb +5 -0
  113. data/lib/structured_text_renderer/version.rb +4 -0
  114. data/lib/structured_text_renderer.rb +2 -0
  115. data/spec/lib/structured_text_renderer/block_renderers/base_block_renderer_spec.rb +26 -0
  116. data/spec/lib/structured_text_renderer/block_renderers/entry_block_renderer_spec.rb +15 -0
  117. data/spec/lib/structured_text_renderer/block_renderers/heading_five_renderer_spec.rb +24 -0
  118. data/spec/lib/structured_text_renderer/block_renderers/heading_four_renderer_spec.rb +24 -0
  119. data/spec/lib/structured_text_renderer/block_renderers/heading_one_renderer_spec.rb +24 -0
  120. data/spec/lib/structured_text_renderer/block_renderers/heading_six_renderer_spec.rb +24 -0
  121. data/spec/lib/structured_text_renderer/block_renderers/heading_three_renderer_spec.rb +24 -0
  122. data/spec/lib/structured_text_renderer/block_renderers/heading_two_renderer_spec.rb +24 -0
  123. data/spec/lib/structured_text_renderer/block_renderers/hr_renderer_spec.rb +13 -0
  124. data/spec/lib/structured_text_renderer/block_renderers/hyperlink_renderer_spec.rb +24 -0
  125. data/spec/lib/structured_text_renderer/block_renderers/list_item_renderer_spec.rb +24 -0
  126. data/spec/lib/structured_text_renderer/block_renderers/ordered_list_renderer_spec.rb +56 -0
  127. data/spec/lib/structured_text_renderer/block_renderers/paragraph_renderer_spec.rb +24 -0
  128. data/spec/lib/structured_text_renderer/block_renderers/quote_renderer_spec.rb +25 -0
  129. data/spec/lib/structured_text_renderer/block_renderers/unordered_list_renderer_spec.rb +56 -0
  130. data/spec/lib/structured_text_renderer/document_renderers/document_renderer_spec.rb +42 -0
  131. data/spec/lib/structured_text_renderer/null_renderer_spec.rb +19 -0
  132. data/spec/lib/structured_text_renderer/renderer_spec.rb +308 -0
  133. data/spec/lib/structured_text_renderer/text_renderers/base_inline_renderer_spec.rb +11 -0
  134. data/spec/lib/structured_text_renderer/text_renderers/bold_renderer_spec.rb +11 -0
  135. data/spec/lib/structured_text_renderer/text_renderers/code_renderer_spec.rb +11 -0
  136. data/spec/lib/structured_text_renderer/text_renderers/italic_renderer_spec.rb +11 -0
  137. data/spec/lib/structured_text_renderer/text_renderers/text_renderer_spec.rb +53 -0
  138. data/spec/lib/structured_text_renderer/text_renderers/underline_renderer_spec.rb +11 -0
  139. data/spec/spec_helper.rb +82 -0
  140. data/structured_text_renderer.gemspec +30 -0
  141. metadata +361 -0
@@ -0,0 +1,12 @@
1
+ require_relative './base_block_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # H2 node renderer.
5
+ class HeadingTwoRenderer < BaseBlockRenderer
6
+ protected
7
+
8
+ def render_tag
9
+ 'h2'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require_relative '../base_node_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # hr node renderer
5
+ class HrRenderer < BaseNodeRenderer
6
+ # Renders an hr node
7
+ def render(_node)
8
+ '<hr />'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ require_relative './base_block_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # a node renderer.
5
+ class HyperlinkRenderer < BaseBlockRenderer
6
+ # Renders hyperlink
7
+ def render(node)
8
+ content = node['content'].each_with_object([]) do |content_node, result|
9
+ renderer = find_renderer(content_node)
10
+ result << renderer.render(content_node)
11
+ end.join
12
+ "<a href=\"#{node['data']['uri']}\">#{content}</a>"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './base_block_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # li node renderer.
5
+ class ListItemRenderer < BaseBlockRenderer
6
+ protected
7
+
8
+ def render_tag
9
+ 'li'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './base_block_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # ol node renderer.
5
+ class OrderedListRenderer < BaseBlockRenderer
6
+ protected
7
+
8
+ def render_tag
9
+ 'ol'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './base_block_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # P node renderer.
5
+ class ParagraphRenderer < BaseBlockRenderer
6
+ protected
7
+
8
+ def render_tag
9
+ 'p'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './base_block_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # blockquote node renderer.
5
+ class QuoteRenderer < BaseBlockRenderer
6
+ protected
7
+
8
+ def render_tag
9
+ 'blockqoute'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './base_block_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # ul node renderer.
5
+ class UnorderedListRenderer < BaseBlockRenderer
6
+ protected
7
+
8
+ def render_tag
9
+ 'ul'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ require_relative './block_renderers/hr_renderer'
2
+
3
+ require_relative './block_renderers/quote_renderer'
4
+ require_relative './block_renderers/paragraph_renderer'
5
+ require_relative './block_renderers/hyperlink_renderer'
6
+
7
+ require_relative './block_renderers/entry_block_renderer'
8
+
9
+ require_relative './block_renderers/heading_one_renderer'
10
+ require_relative './block_renderers/heading_two_renderer'
11
+ require_relative './block_renderers/heading_six_renderer'
12
+ require_relative './block_renderers/heading_five_renderer'
13
+ require_relative './block_renderers/heading_four_renderer'
14
+ require_relative './block_renderers/heading_three_renderer'
15
+
16
+ require_relative './block_renderers/list_item_renderer'
17
+ require_relative './block_renderers/ordered_list_renderer'
18
+ require_relative './block_renderers/unordered_list_renderer'
@@ -0,0 +1,13 @@
1
+ require_relative '../base_node_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # Document renderer.
5
+ class DocumentRenderer < BaseNodeRenderer
6
+ # Renders all nodes in the document.
7
+ def render(document)
8
+ document['content'].each_with_object([]) do |node, result|
9
+ result << find_renderer(node).render(node)
10
+ end.join("\n")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ require_relative './document_renderers/document_renderer'
@@ -0,0 +1,19 @@
1
+ require_relative './base_node_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # Catch-all renderer for missing node types
5
+ class NullRenderer < BaseNodeRenderer
6
+ # Will raise an exception indicating the missing node type.
7
+ def render(node)
8
+ fail "No renderer defined for '#{node_type(node)}' nodes"
9
+ end
10
+
11
+ private
12
+
13
+ def node_type(node)
14
+ return node['nodeType'] if node.key?('nodeType')
15
+ return node['type'] if node.key?('type')
16
+ node
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,46 @@
1
+ require_relative './text_renderers'
2
+ require_relative './block_renderers'
3
+ require_relative './document_renderers'
4
+ require_relative './base_node_renderer'
5
+ require_relative './null_renderer'
6
+
7
+ # StructuredTextRenderer Namespace
8
+ module StructuredTextRenderer
9
+ # Renderer for StructuredText field from Contentful
10
+ class Renderer < BaseNodeRenderer
11
+ # Default Renderers
12
+ DEFAULT_MAPPINGS = {
13
+ nil => NullRenderer,
14
+ 'document' => DocumentRenderer,
15
+ 'heading-1' => HeadingOneRenderer,
16
+ 'heading-2' => HeadingTwoRenderer,
17
+ 'heading-3' => HeadingThreeRenderer,
18
+ 'heading-4' => HeadingFourRenderer,
19
+ 'heading-5' => HeadingFiveRenderer,
20
+ 'heading-6' => HeadingSixRenderer,
21
+ 'quote' => QuoteRenderer,
22
+ 'hyperlink' => HyperlinkRenderer,
23
+ 'paragraph' => ParagraphRenderer,
24
+ 'list-item' => ListItemRenderer,
25
+ 'ordered-list' => OrderedListRenderer,
26
+ 'unordered-list' => UnorderedListRenderer,
27
+ 'embedded-entry-block' => EntryBlockRenderer,
28
+ 'hr' => HrRenderer,
29
+ 'text' => TextRenderer,
30
+ 'bold' => BoldRenderer,
31
+ 'code' => CodeRenderer,
32
+ 'italic' => ItalicRenderer,
33
+ 'underline' => UnderlineRenderer
34
+ }
35
+
36
+ def initialize(mappings = {})
37
+ @mappings = DEFAULT_MAPPINGS.merge(mappings)
38
+ end
39
+
40
+ # Returns a rendered StructuredText document
41
+ def render(document)
42
+ renderer = find_renderer(document)
43
+ renderer.render(document) unless renderer.nil?
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,17 @@
1
+ require_relative '../base_node_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # Base renderer for inline nodes.
5
+ class BaseInlineRenderer < BaseNodeRenderer
6
+ # Renders inline nodes.
7
+ def render(node)
8
+ "<#{render_tag}>#{node['value']}</#{render_tag}>"
9
+ end
10
+
11
+ protected
12
+
13
+ def render_tag
14
+ 'span'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './base_inline_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # B node renderer.
5
+ class BoldRenderer < BaseInlineRenderer
6
+ protected
7
+
8
+ def render_tag
9
+ 'b'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './base_inline_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # code node renderer.
5
+ class CodeRenderer < BaseInlineRenderer
6
+ protected
7
+
8
+ def render_tag
9
+ 'code'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './base_inline_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # I node renderer.
5
+ class ItalicRenderer < BaseInlineRenderer
6
+ protected
7
+
8
+ def render_tag
9
+ 'i'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../base_node_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # Renderer for Text nodes.
5
+ class TextRenderer < BaseNodeRenderer
6
+ # Renders text nodes with all markings.
7
+ def render(node)
8
+ node = Marshal.load(Marshal.dump(node)) # Clone the node
9
+
10
+ node.fetch('marks', []).each do |mark|
11
+ renderer = mappings[mark['type']]
12
+ return mappings[nil].new(mappings).render(mark) if renderer.nil? && mappings.key?(nil)
13
+ node['value'] = renderer.new(mappings).render(node) unless renderer.nil?
14
+ end
15
+
16
+ node['value']
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './base_inline_renderer'
2
+
3
+ module StructuredTextRenderer
4
+ # U node renderer.
5
+ class UnderlineRenderer < BaseInlineRenderer
6
+ protected
7
+
8
+ def render_tag
9
+ 'u'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ require_relative './text_renderers/text_renderer'
2
+ require_relative './text_renderers/bold_renderer'
3
+ require_relative './text_renderers/code_renderer'
4
+ require_relative './text_renderers/italic_renderer'
5
+ require_relative './text_renderers/underline_renderer'
@@ -0,0 +1,4 @@
1
+ module StructuredTextRenderer
2
+ # Gem Version
3
+ VERSION = '0.0.1'.freeze
4
+ end
@@ -0,0 +1,2 @@
1
+ require_relative './structured_text_renderer/renderer'
2
+ require_relative './structured_text_renderer/version'
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ mock_node = {"content" => [{"value" => "foo", "nodeType" => "text"}]}
4
+
5
+ mock_node_with_marks = {"content" => [{"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]}]}
6
+
7
+ describe StructuredTextRenderer::BaseBlockRenderer do
8
+ subject do
9
+ described_class.new(
10
+ 'text' => StructuredTextRenderer::TextRenderer,
11
+ 'bold' => StructuredTextRenderer::BoldRenderer,
12
+ 'italic' => StructuredTextRenderer::ItalicRenderer,
13
+ 'underline' => StructuredTextRenderer::UnderlineRenderer
14
+ )
15
+ end
16
+
17
+ describe '#render' do
18
+ it 'by defaults renders a div' do
19
+ expect(subject.render(mock_node)).to eq "<div>foo</div>"
20
+ end
21
+
22
+ it 'will propagate marks to text renderers' do
23
+ expect(subject.render(mock_node_with_marks)).to eq "<div><b>foo</b></div>"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ mock_data_node = {
4
+ "data" => {"target" => {"sys" => {"id" => "foo", "type" => "Link", "linkType" => "Entry"}}}
5
+ }
6
+
7
+ describe StructuredTextRenderer::EntryBlockRenderer do
8
+ subject { described_class.new }
9
+
10
+ describe '#render' do
11
+ it 'will stringify node data' do
12
+ expect(subject.render(mock_data_node)).to eq '<div>{"target"=>{"sys"=>{"id"=>"foo", "type"=>"Link", "linkType"=>"Entry"}}}</div>'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ mock_node = {"content" => [{"value" => "foo", "nodeType" => "text"}]}
4
+
5
+ mock_node_with_marks = {"content" => [{"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]}]}
6
+
7
+ describe StructuredTextRenderer::HeadingFiveRenderer do
8
+ subject do
9
+ described_class.new(
10
+ 'text' => StructuredTextRenderer::TextRenderer,
11
+ 'bold' => StructuredTextRenderer::BoldRenderer
12
+ )
13
+ end
14
+
15
+ describe '#render' do
16
+ it 'renders a h5' do
17
+ expect(subject.render(mock_node)).to eq "<h5>foo</h5>"
18
+ end
19
+
20
+ it 'will propagate marks to text renderers' do
21
+ expect(subject.render(mock_node_with_marks)).to eq "<h5><b>foo</b></h5>"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ mock_node = {"content" => [{"value" => "foo", "nodeType" => "text"}]}
4
+
5
+ mock_node_with_marks = {"content" => [{"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]}]}
6
+
7
+ describe StructuredTextRenderer::HeadingFourRenderer do
8
+ subject do
9
+ described_class.new(
10
+ 'text' => StructuredTextRenderer::TextRenderer,
11
+ 'bold' => StructuredTextRenderer::BoldRenderer
12
+ )
13
+ end
14
+
15
+ describe '#render' do
16
+ it 'renders a h4' do
17
+ expect(subject.render(mock_node)).to eq "<h4>foo</h4>"
18
+ end
19
+
20
+ it 'will propagate marks to text renderers' do
21
+ expect(subject.render(mock_node_with_marks)).to eq "<h4><b>foo</b></h4>"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ mock_node = {"content" => [{"value" => "foo", "nodeType" => "text"}]}
4
+
5
+ mock_node_with_marks = {"content" => [{"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]}]}
6
+
7
+ describe StructuredTextRenderer::HeadingOneRenderer do
8
+ subject do
9
+ described_class.new(
10
+ 'text' => StructuredTextRenderer::TextRenderer,
11
+ 'bold' => StructuredTextRenderer::BoldRenderer
12
+ )
13
+ end
14
+
15
+ describe '#render' do
16
+ it 'renders a h1' do
17
+ expect(subject.render(mock_node)).to eq "<h1>foo</h1>"
18
+ end
19
+
20
+ it 'will propagate marks to text renderers' do
21
+ expect(subject.render(mock_node_with_marks)).to eq "<h1><b>foo</b></h1>"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ mock_node = {"content" => [{"value" => "foo", "nodeType" => "text"}]}
4
+
5
+ mock_node_with_marks = {"content" => [{"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]}]}
6
+
7
+ describe StructuredTextRenderer::HeadingSixRenderer do
8
+ subject do
9
+ described_class.new(
10
+ 'text' => StructuredTextRenderer::TextRenderer,
11
+ 'bold' => StructuredTextRenderer::BoldRenderer
12
+ )
13
+ end
14
+
15
+ describe '#render' do
16
+ it 'renders a h6' do
17
+ expect(subject.render(mock_node)).to eq "<h6>foo</h6>"
18
+ end
19
+
20
+ it 'will propagate marks to text renderers' do
21
+ expect(subject.render(mock_node_with_marks)).to eq "<h6><b>foo</b></h6>"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ mock_node = {"content" => [{"value" => "foo", "nodeType" => "text"}]}
4
+
5
+ mock_node_with_marks = {"content" => [{"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]}]}
6
+
7
+ describe StructuredTextRenderer::HeadingThreeRenderer do
8
+ subject do
9
+ described_class.new(
10
+ 'text' => StructuredTextRenderer::TextRenderer,
11
+ 'bold' => StructuredTextRenderer::BoldRenderer
12
+ )
13
+ end
14
+
15
+ describe '#render' do
16
+ it 'renders a h3' do
17
+ expect(subject.render(mock_node)).to eq "<h3>foo</h3>"
18
+ end
19
+
20
+ it 'will propagate marks to text renderers' do
21
+ expect(subject.render(mock_node_with_marks)).to eq "<h3><b>foo</b></h3>"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ mock_node = {"content" => [{"value" => "foo", "nodeType" => "text"}]}
4
+
5
+ mock_node_with_marks = {"content" => [{"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]}]}
6
+
7
+ describe StructuredTextRenderer::HeadingTwoRenderer do
8
+ subject do
9
+ described_class.new(
10
+ 'text' => StructuredTextRenderer::TextRenderer,
11
+ 'bold' => StructuredTextRenderer::BoldRenderer
12
+ )
13
+ end
14
+
15
+ describe '#render' do
16
+ it 'renders a h2' do
17
+ expect(subject.render(mock_node)).to eq "<h2>foo</h2>"
18
+ end
19
+
20
+ it 'will propagate marks to text renderers' do
21
+ expect(subject.render(mock_node_with_marks)).to eq "<h2><b>foo</b></h2>"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ mock_node = {"nodeType" => "hr"}
4
+
5
+ describe StructuredTextRenderer::HrRenderer do
6
+ subject { described_class.new }
7
+
8
+ describe '#render' do
9
+ it 'will render an hr' do
10
+ expect(subject.render(mock_node)).to eq '<hr />'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ mock_node = {"data" => {"uri" => "https://foobar.com"}, "content" => [{"value" => "foo", "nodeType" => "text"}]}
4
+
5
+ mock_node_with_marks = {"data" => {"uri" => "https://foobar.com"}, "content" => [{"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]}]}
6
+
7
+ describe StructuredTextRenderer::HyperlinkRenderer do
8
+ subject do
9
+ described_class.new(
10
+ 'text' => StructuredTextRenderer::TextRenderer,
11
+ 'bold' => StructuredTextRenderer::BoldRenderer
12
+ )
13
+ end
14
+
15
+ describe '#render' do
16
+ it 'renders an a' do
17
+ expect(subject.render(mock_node)).to eq '<a href="https://foobar.com">foo</a>'
18
+ end
19
+
20
+ it 'will propagate marks to text renderers' do
21
+ expect(subject.render(mock_node_with_marks)).to eq '<a href="https://foobar.com"><b>foo</b></a>'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ mock_node = {"content" => [{"value" => "foo", "nodeType" => "text"}]}
4
+
5
+ mock_node_with_marks = {"content" => [{"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]}]}
6
+
7
+ describe StructuredTextRenderer::ListItemRenderer do
8
+ subject do
9
+ described_class.new(
10
+ 'text' => StructuredTextRenderer::TextRenderer,
11
+ 'bold' => StructuredTextRenderer::BoldRenderer
12
+ )
13
+ end
14
+
15
+ describe '#render' do
16
+ it 'renders a li' do
17
+ expect(subject.render(mock_node)).to eq "<li>foo</li>"
18
+ end
19
+
20
+ it 'will propagate marks to text renderers' do
21
+ expect(subject.render(mock_node_with_marks)).to eq "<li><b>foo</b></li>"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ mock_node = {"content" => [
4
+ {
5
+ "content" => [{
6
+ "content" => [{
7
+ "value" => "foo",
8
+ "nodeType" => "text",
9
+ "nodeClass" => "text"
10
+ }],
11
+ "nodeType" => "paragraph",
12
+ "nodeClass" => "block"
13
+ }],
14
+ "nodeType" => "list-item",
15
+ "nodeClass" => "block"
16
+ }]
17
+ }
18
+
19
+ mock_node_with_marks = {"content" => [
20
+ {
21
+ "content" => [{
22
+ "content" => [{
23
+ "marks" => [{"type" => "bold"}],
24
+ "value" => "foo",
25
+ "nodeType" => "text",
26
+ "nodeClass" => "text"
27
+ }],
28
+ "nodeType" => "paragraph",
29
+ "nodeClass" => "block"
30
+ }],
31
+ "nodeType" => "list-item",
32
+ "nodeClass" => "block"
33
+ }]
34
+ }
35
+
36
+
37
+ describe StructuredTextRenderer::OrderedListRenderer do
38
+ subject do
39
+ described_class.new(
40
+ 'paragraph' => StructuredTextRenderer::ParagraphRenderer,
41
+ 'text' => StructuredTextRenderer::TextRenderer,
42
+ 'bold' => StructuredTextRenderer::BoldRenderer,
43
+ 'list-item' => StructuredTextRenderer::ListItemRenderer
44
+ )
45
+ end
46
+
47
+ describe '#render' do
48
+ it 'renders a ol' do
49
+ expect(subject.render(mock_node)).to eq "<ol><li><p>foo</p></li></ol>"
50
+ end
51
+
52
+ it 'will propagate marks to text renderers' do
53
+ expect(subject.render(mock_node_with_marks)).to eq "<ol><li><p><b>foo</b></p></li></ol>"
54
+ end
55
+ end
56
+ end