Class: EditorJs::Blocks::EmbedBlock

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

Overview

embed 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



55
56
57
# File 'lib/editor_js/blocks/embed_block.rb', line 55

def plain
  data['caption'].strip
end

#render(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/editor_js/blocks/embed_block.rb', line 33

def render(options = {})
   :div, class: css_name do
    concat (:iframe, '',
                       src: data['embed'],
                       width: data['width'],
                       height: data['height'],
                       frameborder: options.fetch('frameborder', '0'),
                       allowfullscreen: options.fetch('allowfullscreen', true))
    concat (:span, data['caption'])
  end
end

#sanitize!Object



45
46
47
48
49
50
51
52
53
# File 'lib/editor_js/blocks/embed_block.rb', line 45

def sanitize!
  %w[caption embed height service source width].each do |key|
    str = Sanitize.fragment(data[key], remove_contents: true).strip
    if %w[embed service source].include?(key)
      str.gsub!('&', '&')
    end
    data[key] = str
  end
end

#schemaObject



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

def schema
  YAML.safe_load(<<~YAML)
    type: object
    additionalProperties: false
    properties:
      caption:
        type: string
      embed:
        type: string
      height:
        type: string
      service:
        type: string
      source:
        type: string
      width:
        type: string
    required:
    - embed
    - service
    - source
    - width
    - height
  YAML
end