structured_text_renderer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/.rubocop.yml +27 -0
- data/.rubocop_todo.yml +35 -0
- data/.travis.yml +13 -0
- data/.yardopts +4 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +110 -0
- data/Guardfile +24 -0
- data/LICENSE.txt +21 -0
- data/README.md +87 -0
- data/Rakefile +33 -0
- data/coverage/.last_run.json +5 -0
- data/coverage/.resultset.json +1366 -0
- data/coverage/.resultset.json.lock +0 -0
- data/coverage/assets/0.10.2/application.css +799 -0
- data/coverage/assets/0.10.2/application.js +1707 -0
- 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 +9110 -0
- data/doc/StructuredTextRenderer/BaseBlockRenderer.html +248 -0
- data/doc/StructuredTextRenderer/BaseInlineRenderer.html +242 -0
- data/doc/StructuredTextRenderer/BaseNodeRenderer.html +300 -0
- data/doc/StructuredTextRenderer/BoldRenderer.html +169 -0
- data/doc/StructuredTextRenderer/CodeRenderer.html +169 -0
- data/doc/StructuredTextRenderer/DocumentRenderer.html +242 -0
- data/doc/StructuredTextRenderer/EntryBlockRenderer.html +239 -0
- data/doc/StructuredTextRenderer/HeadingFiveRenderer.html +169 -0
- data/doc/StructuredTextRenderer/HeadingFourRenderer.html +169 -0
- data/doc/StructuredTextRenderer/HeadingOneRenderer.html +169 -0
- data/doc/StructuredTextRenderer/HeadingSixRenderer.html +169 -0
- data/doc/StructuredTextRenderer/HeadingThreeRenderer.html +169 -0
- data/doc/StructuredTextRenderer/HeadingTwoRenderer.html +169 -0
- data/doc/StructuredTextRenderer/HrRenderer.html +238 -0
- data/doc/StructuredTextRenderer/HyperlinkRenderer.html +254 -0
- data/doc/StructuredTextRenderer/ItalicRenderer.html +169 -0
- data/doc/StructuredTextRenderer/ListItemRenderer.html +169 -0
- data/doc/StructuredTextRenderer/NullRenderer.html +238 -0
- data/doc/StructuredTextRenderer/OrderedListRenderer.html +169 -0
- data/doc/StructuredTextRenderer/ParagraphRenderer.html +169 -0
- data/doc/StructuredTextRenderer/QuoteRenderer.html +169 -0
- data/doc/StructuredTextRenderer/Renderer.html +349 -0
- data/doc/StructuredTextRenderer/TextRenderer.html +254 -0
- data/doc/StructuredTextRenderer/UnderlineRenderer.html +169 -0
- data/doc/StructuredTextRenderer/UnorderedListRenderer.html +169 -0
- data/doc/StructuredTextRenderer.html +155 -0
- data/doc/_index.html +403 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +496 -0
- data/doc/file.CHANGELOG.html +77 -0
- data/doc/file.LICENSE.html +70 -0
- data/doc/file.README.html +171 -0
- data/doc/file_list.html +66 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +171 -0
- data/doc/js/app.js +292 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +147 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/structured_text_renderer/base_node_renderer.rb +18 -0
- data/lib/structured_text_renderer/block_renderers/base_block_renderer.rb +20 -0
- data/lib/structured_text_renderer/block_renderers/entry_block_renderer.rb +13 -0
- data/lib/structured_text_renderer/block_renderers/heading_five_renderer.rb +12 -0
- data/lib/structured_text_renderer/block_renderers/heading_four_renderer.rb +12 -0
- data/lib/structured_text_renderer/block_renderers/heading_one_renderer.rb +12 -0
- data/lib/structured_text_renderer/block_renderers/heading_six_renderer.rb +12 -0
- data/lib/structured_text_renderer/block_renderers/heading_three_renderer.rb +12 -0
- data/lib/structured_text_renderer/block_renderers/heading_two_renderer.rb +12 -0
- data/lib/structured_text_renderer/block_renderers/hr_renderer.rb +11 -0
- data/lib/structured_text_renderer/block_renderers/hyperlink_renderer.rb +15 -0
- data/lib/structured_text_renderer/block_renderers/list_item_renderer.rb +12 -0
- data/lib/structured_text_renderer/block_renderers/ordered_list_renderer.rb +12 -0
- data/lib/structured_text_renderer/block_renderers/paragraph_renderer.rb +12 -0
- data/lib/structured_text_renderer/block_renderers/quote_renderer.rb +12 -0
- data/lib/structured_text_renderer/block_renderers/unordered_list_renderer.rb +12 -0
- data/lib/structured_text_renderer/block_renderers.rb +18 -0
- data/lib/structured_text_renderer/document_renderers/document_renderer.rb +13 -0
- data/lib/structured_text_renderer/document_renderers.rb +1 -0
- data/lib/structured_text_renderer/null_renderer.rb +19 -0
- data/lib/structured_text_renderer/renderer.rb +46 -0
- data/lib/structured_text_renderer/text_renderers/base_inline_renderer.rb +17 -0
- data/lib/structured_text_renderer/text_renderers/bold_renderer.rb +12 -0
- data/lib/structured_text_renderer/text_renderers/code_renderer.rb +12 -0
- data/lib/structured_text_renderer/text_renderers/italic_renderer.rb +12 -0
- data/lib/structured_text_renderer/text_renderers/text_renderer.rb +19 -0
- data/lib/structured_text_renderer/text_renderers/underline_renderer.rb +12 -0
- data/lib/structured_text_renderer/text_renderers.rb +5 -0
- data/lib/structured_text_renderer/version.rb +4 -0
- data/lib/structured_text_renderer.rb +2 -0
- data/spec/lib/structured_text_renderer/block_renderers/base_block_renderer_spec.rb +26 -0
- data/spec/lib/structured_text_renderer/block_renderers/entry_block_renderer_spec.rb +15 -0
- data/spec/lib/structured_text_renderer/block_renderers/heading_five_renderer_spec.rb +24 -0
- data/spec/lib/structured_text_renderer/block_renderers/heading_four_renderer_spec.rb +24 -0
- data/spec/lib/structured_text_renderer/block_renderers/heading_one_renderer_spec.rb +24 -0
- data/spec/lib/structured_text_renderer/block_renderers/heading_six_renderer_spec.rb +24 -0
- data/spec/lib/structured_text_renderer/block_renderers/heading_three_renderer_spec.rb +24 -0
- data/spec/lib/structured_text_renderer/block_renderers/heading_two_renderer_spec.rb +24 -0
- data/spec/lib/structured_text_renderer/block_renderers/hr_renderer_spec.rb +13 -0
- data/spec/lib/structured_text_renderer/block_renderers/hyperlink_renderer_spec.rb +24 -0
- data/spec/lib/structured_text_renderer/block_renderers/list_item_renderer_spec.rb +24 -0
- data/spec/lib/structured_text_renderer/block_renderers/ordered_list_renderer_spec.rb +56 -0
- data/spec/lib/structured_text_renderer/block_renderers/paragraph_renderer_spec.rb +24 -0
- data/spec/lib/structured_text_renderer/block_renderers/quote_renderer_spec.rb +25 -0
- data/spec/lib/structured_text_renderer/block_renderers/unordered_list_renderer_spec.rb +56 -0
- data/spec/lib/structured_text_renderer/document_renderers/document_renderer_spec.rb +42 -0
- data/spec/lib/structured_text_renderer/null_renderer_spec.rb +19 -0
- data/spec/lib/structured_text_renderer/renderer_spec.rb +308 -0
- data/spec/lib/structured_text_renderer/text_renderers/base_inline_renderer_spec.rb +11 -0
- data/spec/lib/structured_text_renderer/text_renderers/bold_renderer_spec.rb +11 -0
- data/spec/lib/structured_text_renderer/text_renderers/code_renderer_spec.rb +11 -0
- data/spec/lib/structured_text_renderer/text_renderers/italic_renderer_spec.rb +11 -0
- data/spec/lib/structured_text_renderer/text_renderers/text_renderer_spec.rb +53 -0
- data/spec/lib/structured_text_renderer/text_renderers/underline_renderer_spec.rb +11 -0
- data/spec/spec_helper.rb +82 -0
- data/structured_text_renderer.gemspec +30 -0
- metadata +361 -0
@@ -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,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,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,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
|