Class: EditorJs::Blocks::ListBlock
- Inherits:
-
Base
- Object
- Base
- EditorJs::Blocks::ListBlock
show all
- Defined in:
- lib/editor_js/blocks/list_block.rb
Overview
Constant Summary
Constants inherited
from Base
Base::InvalidBlockDataError, Base::InvalidBlockTypeError
Instance Attribute Summary
Attributes inherited from Base
#output_buffer, #raw
Instance Method Summary
collapse
Methods inherited from Base
#css_name, #data, #decode_html, inherited, #initialize, load, #output, registry, type, #type, #valid?
Instance Method Details
#plain ⇒ Object
56
57
58
59
60
|
# File 'lib/editor_js/blocks/list_block.rb', line 56
def plain
data['items'].map do |text|
decode_html(Sanitize.fragment(text)).strip
end.join(', ')
end
|
#render(_options = {}) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/editor_js/blocks/list_block.rb', line 22
def render(_options = {})
tag = data['style'] == 'unordered' ? :ul : :ol
content_tag(tag, class: css_name) do
children_tag_string = ''
data['items'].each do |v|
children_tag_string += content_tag(:li, v.html_safe)
end
children_tag_string.html_safe
end
end
|
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/editor_js/blocks/list_block.rb', line 33
def safe_tags
{
'b' => nil,
'i' => nil,
'u' => ['class'],
'del' => ['class'],
'a' => ['href'],
'mark' => ['class'],
'code' => ['class']
}
end
|
#sanitize! ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/editor_js/blocks/list_block.rb', line 45
def sanitize!
data['items'] = data['items'].map do |text|
Sanitize.fragment(
text,
elements: safe_tags.keys,
attributes: safe_tags.select { |_k, v| v },
remove_contents: true
)
end
end
|
#schema ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/editor_js/blocks/list_block.rb', line 7
def schema
YAML.safe_load(<<~YAML)
type: object
additionalProperties: false
properties:
style:
type: string
pattern: ^(un)?ordered$
items:
type: array
items:
type: string
YAML
end
|