Class: EditorJs::Blocks::HeaderBlock

Inherits:
Base
  • Object
show all
Defined in:
lib/editor_js/blocks/header_block.rb

Overview

header_block

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?

Constructor Details

This class inherits a constructor from EditorJs::Blocks::Base

Instance Method Details

#plainObject



45
46
47
# File 'lib/editor_js/blocks/header_block.rb', line 45

def plain
  decode_html data['text'].strip
end

#render(_options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/editor_js/blocks/header_block.rb', line 29

def render(_options = {})
  alignment = data['alignment']
  class_name_str = css_name
  if alignment.present?
    class_name_str = [
      class_name_str,
      css_name("__#{alignment}")
    ].join(' ')
  end
  (:"h#{data['level']}", data['text'].html_safe, class: class_name_str)
end

#sanitize!Object



41
42
43
# File 'lib/editor_js/blocks/header_block.rb', line 41

def sanitize!
  data['text'] = Sanitize.fragment(data['text'], remove_contents: true).strip
end

#schemaObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/editor_js/blocks/header_block.rb', line 7

def schema
  YAML.safe_load(<<~YAML)
    type: object
    additionalProperties: false
    properties:
      text:
        type: string
      level:
        type: number
        enum: [1,2,3,4,5,6]
      alignment:
        type: string
        enum:
          - align-left
          - align-center
          - align-right
    required:
    - text
    - level
  YAML
end