storyblok-richtext-renderer 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bd667e62ab735283652c282968f376195914598e6ec6eb55a839a6a80f836bf
|
4
|
+
data.tar.gz: 3bed9652f7f9eeedca3eedeaec2113286bf34e54e89bdbe142193be46fb3c950
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccd700dde808fff8168c2454aec3567e8163b33cb2ec97ad7f625aaca671fb9e234d45f3fdc02423949f6de031744e173c9b31417f2d9bc5ace599f9ddebb62f
|
7
|
+
data.tar.gz: 4a3cdb496f897df411159e1108ad1a957d52d1201efec70d597e375a7cfa899483667c38be8067ffb1dce44d2994ebfdef9008bc2fb1988c42d7b3a3f5e43748
|
data/README.md
CHANGED
@@ -19,6 +19,12 @@ renderer.render({'type' => 'doc', 'content' => [{'type' => 'paragraph', 'content
|
|
19
19
|
# -> <p>Good</p>
|
20
20
|
```
|
21
21
|
|
22
|
+
### Run all tests
|
23
|
+
|
24
|
+
```bash
|
25
|
+
rspec spec/richtext_spec.rb
|
26
|
+
```
|
27
|
+
|
22
28
|
### License
|
23
29
|
|
24
30
|
This project is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
|
@@ -7,9 +7,15 @@ module Storyblok::Richtext
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def tag
|
10
|
+
attrs = @node['attrs']
|
11
|
+
|
12
|
+
if attrs['anchor'].is_a?(String) and !attrs['anchor'].empty?
|
13
|
+
attrs['href'] = "#{attrs['href']}##{attrs['anchor']}"
|
14
|
+
end
|
15
|
+
|
10
16
|
[{
|
11
17
|
tag: "a",
|
12
|
-
attrs:
|
18
|
+
attrs: attrs.slice('href', 'target')
|
13
19
|
}]
|
14
20
|
end
|
15
21
|
end
|
data/spec/richtext_spec.rb
CHANGED
@@ -17,12 +17,167 @@ describe 'richtext' do
|
|
17
17
|
'class' => 'red'
|
18
18
|
}
|
19
19
|
}
|
20
|
+
],
|
21
|
+
},
|
22
|
+
{
|
23
|
+
'type' => 'paragraph',
|
24
|
+
'content' => [
|
25
|
+
{
|
26
|
+
'type' => 'text',
|
27
|
+
'marks' => [
|
28
|
+
{
|
29
|
+
'type' => 'i'
|
30
|
+
}
|
31
|
+
],
|
32
|
+
'text' => 'Italic'
|
33
|
+
}
|
34
|
+
]
|
35
|
+
},
|
36
|
+
{
|
37
|
+
'type' => 'paragraph',
|
38
|
+
'content' => [
|
39
|
+
{
|
40
|
+
'type' => 'text',
|
41
|
+
'marks' => [
|
42
|
+
{
|
43
|
+
'type' => 'em'
|
44
|
+
}
|
45
|
+
],
|
46
|
+
'text' => 'Italic too'
|
47
|
+
}
|
48
|
+
]
|
49
|
+
}
|
50
|
+
]
|
51
|
+
}
|
52
|
+
|
53
|
+
renderer = Storyblok::Richtext::HtmlRenderer.new
|
54
|
+
expect(renderer.render(doc)).to eq('<span class="red">red text</span><p><i>Italic</i></p><p><i>Italic too</i></p>')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'richtext' do
|
59
|
+
it 'horizontal_rule to generate hr tag' do
|
60
|
+
doc = {
|
61
|
+
'type' => 'doc',
|
62
|
+
'content' => [
|
63
|
+
{
|
64
|
+
'type' => 'horizontal_rule'
|
65
|
+
}
|
66
|
+
]
|
67
|
+
}
|
68
|
+
|
69
|
+
renderer = Storyblok::Richtext::HtmlRenderer.new
|
70
|
+
expect(renderer.render(doc)).to eq('<hr />')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'richtext' do
|
75
|
+
it 'hard_break to generate br tag' do
|
76
|
+
doc = {
|
77
|
+
'type' => 'doc',
|
78
|
+
'content' => [
|
79
|
+
{
|
80
|
+
'type' => 'hard_break'
|
81
|
+
}
|
82
|
+
]
|
83
|
+
}
|
84
|
+
|
85
|
+
renderer = Storyblok::Richtext::HtmlRenderer.new
|
86
|
+
expect(renderer.render(doc)).to eq('<br />')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'richtext' do
|
91
|
+
it 'image to generate img tag' do
|
92
|
+
doc = {
|
93
|
+
'type' => 'doc',
|
94
|
+
'content' => [
|
95
|
+
{
|
96
|
+
'type' => 'image',
|
97
|
+
'attrs' => {
|
98
|
+
'src' => 'https://asset'
|
99
|
+
}
|
100
|
+
}
|
101
|
+
]
|
102
|
+
}
|
103
|
+
|
104
|
+
renderer = Storyblok::Richtext::HtmlRenderer.new
|
105
|
+
expect(renderer.render(doc)).to eq('<img src="https://asset" />')
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'richtext' do
|
110
|
+
it 'link to generate a tag' do
|
111
|
+
doc = {
|
112
|
+
'type' => 'doc',
|
113
|
+
'content' => [
|
114
|
+
{
|
115
|
+
'text' => 'link text',
|
116
|
+
'type' => 'text',
|
117
|
+
'marks' => [
|
118
|
+
{
|
119
|
+
'type' => 'link',
|
120
|
+
'attrs' => {
|
121
|
+
'href' => '/link',
|
122
|
+
'target' => '_blank',
|
123
|
+
'uuid' => '300aeadc-c82d-4529-9484-f3f8f09cf9f5'
|
124
|
+
}
|
125
|
+
}
|
20
126
|
]
|
21
127
|
}
|
22
128
|
]
|
23
129
|
}
|
24
130
|
|
25
131
|
renderer = Storyblok::Richtext::HtmlRenderer.new
|
26
|
-
expect(renderer.render(doc)).to eq('<
|
132
|
+
expect(renderer.render(doc)).to eq('<a href="/link" target="_blank">link text</a>')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe 'richtext' do
|
137
|
+
it 'code_block to generate a pre and code tag' do
|
138
|
+
doc = {
|
139
|
+
'type' => 'doc',
|
140
|
+
'content' => [
|
141
|
+
{
|
142
|
+
'type' => 'code_block',
|
143
|
+
'attrs' => {},
|
144
|
+
'content' => [{
|
145
|
+
'text' => 'code',
|
146
|
+
'type' => 'text'
|
147
|
+
}]
|
148
|
+
}
|
149
|
+
]
|
150
|
+
}
|
151
|
+
|
152
|
+
renderer = Storyblok::Richtext::HtmlRenderer.new
|
153
|
+
expect(renderer.render(doc)).to eq('<pre><code>code</code></pre>')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'richtext' do
|
158
|
+
it 'anchor links test' do
|
159
|
+
doc = {
|
160
|
+
'type' => 'doc',
|
161
|
+
'content' => [
|
162
|
+
{
|
163
|
+
'text' => 'link text',
|
164
|
+
'type' => 'text',
|
165
|
+
'marks' => [
|
166
|
+
{
|
167
|
+
'type' => 'link',
|
168
|
+
'attrs' => {
|
169
|
+
'href' => '/link',
|
170
|
+
'target' => '_blank',
|
171
|
+
'uuid' => '300aeadc-c82d-4529-9484-f3f8f09cf9f5',
|
172
|
+
'anchor' => 'anchor-text'
|
173
|
+
}
|
174
|
+
}
|
175
|
+
]
|
176
|
+
}
|
177
|
+
]
|
178
|
+
}
|
179
|
+
|
180
|
+
renderer = Storyblok::Richtext::HtmlRenderer.new
|
181
|
+
expect(renderer.render(doc)).to eq('<a href="/link#anchor-text" target="_blank">link text</a>')
|
27
182
|
end
|
28
183
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: storyblok-richtext-renderer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Storyblok (Alexander Feiglstorfer)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|