structured_text_renderer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/structured_text_renderer/block_renderers/base_block_renderer.rb +8 -4
- data/lib/structured_text_renderer/block_renderers/hyperlink_renderer.rb +1 -5
- data/lib/structured_text_renderer/version.rb +1 -1
- data/spec/lib/structured_text_renderer/block_renderers/paragraph_renderer_spec.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff486ce1ca970aeaa56f4a3b3b7f07b4da32e97994572b4385599bd95829454d
|
4
|
+
data.tar.gz: 21f37a8f370e260a9e55db4629cce77a79e0a1b30e83ababe458bcfdc37e4bd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 239694eff6e0eb957ca0c4c0983c19204cdd73e2c83842d6013cec5808c81b9c8c553961d56ca19a9a9d3b0af6b9b51e034c18765d70fd9ecbe05108110929b1
|
7
|
+
data.tar.gz: 0d060f82f28032661089c29930756522ef8a6b4d5311596573b6761150e57ab92fa41ad10f59ecbb5256c210d2f04495efbb8cd931894875977f0acd6bc8310c
|
data/CHANGELOG.md
CHANGED
@@ -5,14 +5,18 @@ module StructuredTextRenderer
|
|
5
5
|
class BaseBlockRenderer < BaseNodeRenderer
|
6
6
|
# Renders block type nodes.
|
7
7
|
def render(node)
|
8
|
-
node
|
9
|
-
renderer = find_renderer(content_node)
|
10
|
-
result << "<#{render_tag}>#{renderer.render(content_node)}</#{render_tag}>"
|
11
|
-
end.join("\n")
|
8
|
+
"<#{render_tag}>#{render_content(node)}</#{render_tag}>"
|
12
9
|
end
|
13
10
|
|
14
11
|
protected
|
15
12
|
|
13
|
+
def render_content(node)
|
14
|
+
node['content'].each_with_object([]) do |content_node, result|
|
15
|
+
renderer = find_renderer(content_node)
|
16
|
+
result << renderer.render(content_node)
|
17
|
+
end.join
|
18
|
+
end
|
19
|
+
|
16
20
|
def render_tag
|
17
21
|
'div'
|
18
22
|
end
|
@@ -5,11 +5,7 @@ module StructuredTextRenderer
|
|
5
5
|
class HyperlinkRenderer < BaseBlockRenderer
|
6
6
|
# Renders hyperlink
|
7
7
|
def render(node)
|
8
|
-
|
9
|
-
renderer = find_renderer(content_node)
|
10
|
-
result << renderer.render(content_node)
|
11
|
-
end.join
|
12
|
-
"<a href=\"#{node['data']['uri']}\">#{content}</a>"
|
8
|
+
"<a href=\"#{node['data']['uri']}\">#{render_content(node)}</a>"
|
13
9
|
end
|
14
10
|
end
|
15
11
|
end
|
@@ -4,6 +4,8 @@ mock_node = {"content" => [{"value" => "foo", "nodeType" => "text"}]}
|
|
4
4
|
|
5
5
|
mock_node_with_marks = {"content" => [{"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]}]}
|
6
6
|
|
7
|
+
mock_node_with_multiple_content_nodes = {"content" => [{"value" => "foo", "nodeType" => "text"}, {"value" => " bar", "nodeType" => "text", "marks" => [{"type" => "bold"}]}]}
|
8
|
+
|
7
9
|
describe StructuredTextRenderer::ParagraphRenderer do
|
8
10
|
subject do
|
9
11
|
described_class.new(
|
@@ -20,5 +22,9 @@ describe StructuredTextRenderer::ParagraphRenderer do
|
|
20
22
|
it 'will propagate marks to text renderers' do
|
21
23
|
expect(subject.render(mock_node_with_marks)).to eq "<p><b>foo</b></p>"
|
22
24
|
end
|
25
|
+
|
26
|
+
it 'will properly render multiple content nodes' do
|
27
|
+
expect(subject.render(mock_node_with_multiple_content_nodes)).to eq "<p>foo<b> bar</b></p>"
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|