Class: EditorJs::Blocks::ChecklistBlock
- Inherits:
-
Base
- Object
- Base
- EditorJs::Blocks::ChecklistBlock
show all
- Defined in:
- lib/editor_js/blocks/checklist_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
62
63
64
|
# File 'lib/editor_js/blocks/checklist_block.rb', line 62
def plain
data['items'].map { |item| decode_html(item['text']).strip }.join(', ')
end
|
#render(_options = {}) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/editor_js/blocks/checklist_block.rb', line 27
def render(_options = {})
content_tag :div, class: css_name do
data['items'].map do |item|
content_tag(:div, class: css_name('__warrper')) do
html_str = content_tag(:input, nil, type: 'checkbox', disabled: true, checked: item['checked'])
html_str += content_tag(:label, item['text'].html_safe)
html_str.html_safe
end.html_safe
end.join.html_safe
end
end
|
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/editor_js/blocks/checklist_block.rb', line 39
def safe_tags
{
'b' => nil,
'i' => nil,
'u' => ['class'],
'del' => ['class'],
'a' => ['href'],
'mark' => ['class'],
'code' => ['class']
}
end
|
#sanitize! ⇒ Object
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/editor_js/blocks/checklist_block.rb', line 51
def sanitize!
data['items'].each do |item|
item['text'] = Sanitize.fragment(
item['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
21
22
23
24
25
|
# File 'lib/editor_js/blocks/checklist_block.rb', line 7
def schema
YAML.safe_load(<<~YAML)
type: object
additionalProperties: false
properties:
items:
type: array
items:
type: object
additionalProperties: false
properties:
text:
type: string
checked:
type: boolean
required:
- text
YAML
end
|