Sha256: 438dcc649ec78ca16df8507f97e02e82fe15dfa3d48de742ae0a7646ce471a48
Contents?: true
Size: 1.65 KB
Versions: 2
Compression:
Stored size: 1.65 KB
Contents
# frozen_string_literal: true module EditorJs module Blocks class ChecklistBlock < Base def schema YAML.safe_load(<<~YAML) type: object additionalProperties: false properties: items: type: array items: type: object additionalProperties: false properties: text: type: string checked: type: boolean required: - text YAML end def render(_options = {}) content_tag :div, class: css_name do data['items'].map do |item| content_tag(:div, class: css_name('__warrper')) do html_str = content_tag(:input, nil, type: 'checkbox', disabled: true, checked: item['checked']) html_str += content_tag(:label, item['text'].html_safe) html_str.html_safe end.html_safe end.join.html_safe end end def sanitize! safe_tags = { 'b' => nil, 'i' => nil, 'u' => ['class'], 'del' => ['class'], 'a' => ['href'], 'mark' => ['class'], 'code' => ['class'] } data['items'].each do |item| item['text'] = Sanitize.fragment( item['text'], elements: safe_tags.keys, attributes: safe_tags.select {|k, v| v}, remove_contents: true ) end end def plain data['items'].map { |item| decode_html(item['text']).strip }.join(', ') end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
editor_js-0.3.3 | lib/editor_js/blocks/checklist_block.rb |
editor_js-0.3.2 | lib/editor_js/blocks/checklist_block.rb |