class EditorJs::Blocks::ImageBlock

image block

Public Instance Methods

plain() click to toggle source
# File lib/editor_js/blocks/image_block.rb, line 57
def plain
  decode_html data['caption'].strip
end
render(_options = {}) click to toggle source
# File lib/editor_js/blocks/image_block.rb, line 27
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
sanitize!() click to toggle source
# File lib/editor_js/blocks/image_block.rb, line 47
def sanitize!
  %w[caption url].each do |key|
    str = Sanitize.fragment(data[key], remove_contents: true).strip
    if key == 'url'
      str.gsub!('&amp;', '&')
    end
    data[key] = str
  end
end
schema() click to toggle source
# File lib/editor_js/blocks/image_block.rb, line 7
      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