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