Class: EditorJs::Blocks::WarningBlock
- Inherits:
-
Base
- Object
- Base
- EditorJs::Blocks::WarningBlock
show all
- Defined in:
- lib/editor_js/blocks/warning_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
52
53
54
55
56
57
58
|
# File 'lib/editor_js/blocks/warning_block.rb', line 52
def plain
string = [
Sanitize.fragment(data['title']).strip,
Sanitize.fragment(data['message']).strip
].join(', ')
decode_html(string)
end
|
#render(_options = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/editor_js/blocks/warning_block.rb', line 19
def render(_options = {})
title = data['title'].html_safe
message = data['message'].html_safe
content_tag :div, class: css_name do
html_str = content_tag :div, title, class: "#{css_name}__title"
html_str << content_tag(:div, message, class: "#{css_name}__message")
end
end
|
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/editor_js/blocks/warning_block.rb', line 29
def safe_tags
{
'b' => nil,
'i' => nil,
'u' => ['class'],
'del' => ['class'],
'a' => ['href'],
'mark' => ['class'],
'code' => ['class']
}
end
|
#sanitize! ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/editor_js/blocks/warning_block.rb', line 41
def sanitize!
%w[title message].each do |key|
data[key] = Sanitize.fragment(
data[key],
elements: safe_tags.keys,
attributes: safe_tags.select { |_k, v| v },
remove_contents: false
)
end
end
|
#schema ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/editor_js/blocks/warning_block.rb', line 7
def schema
YAML.safe_load(<<~YAML)
type: object
additionalProperties: false
properties:
title:
type: string
message:
type: string
YAML
end
|