Sha256: ad2f48807fdcf037c831c371f57244bfd16f294b4f57f77a230d039fa9fa460e
Contents?: true
Size: 1.67 KB
Versions: 5
Compression:
Stored size: 1.67 KB
Contents
# frozen_string_literal: true module EditorJs module Blocks # image block class ImageBlock < Base def schema YAML.safe_load(<<~YAML) type: object additionalProperties: false properties: caption: type: string url: type: string stretched: type: boolean withBackground: type: boolean withBorder: type: boolean required: - url YAML end def render(_options = {}) content_tag :div, class: css_name do url = data['url'] caption = data['caption'] withBorder = data['withBorder'] withBackground = data['withBackground'] stretched = data['stretched'] html_class = "#{css_name}__picture" html_class += " #{css_name}__picture--stretched" if stretched html_class += " #{css_name}__picture--with-background" if withBackground html_class += " #{css_name}__picture--with-border" if withBorder html_str = content_tag :div, class: html_class do content_tag :img, '', src: url end html_str << content_tag(:div, caption.html_safe, class: "#{css_name}__caption").html_safe end end def sanitize! %w[caption url].each do |key| str = Sanitize.fragment(data[key], remove_contents: true).strip if key == 'url' str.gsub!('&', '&') end data[key] = str end end def plain decode_html data['caption'].strip end end end end
Version data entries
5 entries across 5 versions & 1 rubygems