Sha256: a278504df5d6c456ed268987c007d5bb9969e127bd72822120d2b66620959fcd

Contents?: true

Size: 937 Bytes

Versions: 5

Compression:

Stored size: 937 Bytes

Contents

# frozen_string_literal: true

module RenderEditorjs
  # Built in renderer with healthy defaults
  class DefaultRenderer
    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

    attr_reader :mapping

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
render_editorjs-0.1.5 lib/render_editorjs/default_renderer.rb
render_editorjs-0.1.4 lib/render_editorjs/default_renderer.rb
render_editorjs-0.1.3 lib/render_editorjs/default_renderer.rb
render_editorjs-0.1.2 lib/render_editorjs/default_renderer.rb
render_editorjs-0.1.1 lib/render_editorjs/default_renderer.rb