Class: RenderEditorjs::DefaultRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/render_editorjs/default_renderer.rb

Overview

Built in renderer with healthy defaults

Constant Summary collapse

SCHEMA =
YAML.safe_load(<<~YAML)
  type: object
  additionalProperties: false
  properties:
    time:
      type: number
    blocks:
      type: array
      items:
        type: object
    version:
      type: string
  required:
  - time
  - blocks
  - version
YAML
DEFAULT_MAPPING =
{
  "paragraph" => RenderEditorjs::Blocks::Paragraph.new,
  "header" => RenderEditorjs::Blocks::Header.new,
  "list" => RenderEditorjs::Blocks::List.new,
  "image" => RenderEditorjs::Blocks::Image.new
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(custom_mapping = {}) ⇒ DefaultRenderer

Returns a new instance of DefaultRenderer.



33
34
35
# File 'lib/render_editorjs/default_renderer.rb', line 33

def initialize(custom_mapping = {})
  @mapping = DEFAULT_MAPPING.merge(custom_mapping)
end

Instance Attribute Details

#mappingObject (readonly)

Returns the value of attribute mapping.



31
32
33
# File 'lib/render_editorjs/default_renderer.rb', line 31

def mapping
  @mapping
end

Instance Method Details

#validator(content) ⇒ Object



37
38
39
# File 'lib/render_editorjs/default_renderer.rb', line 37

def validator(content)
  RenderEditorjs::Validator.new(content, SCHEMA)
end