Sha256: 70c71347851ae2aa95435bcc81386b24a4900196e0c224bbbefd7572c9b303cd
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module RenderEditorjs module Blocks class Header < Base DEFAULT_OPTIONS = { alignment: "align-left" }.freeze 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 def render(data) return unless valid?(data) alignment = data["alignment"] class_name = "" if alignment.present? class_name = [ class_name, css_name("__#{alignment}") ].join(" ") end content_tag(:"h#{data["level"]}", sanitize(data["text"]).html_safe, class: class_name.presence) end def sanitize(text) Sanitize.fragment(text, remove_contents: true).strip end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
render_editorjs-0.1.0 | lib/render_editorjs/blocks/header.rb |