class EditorJs::Blocks::WarningBlock

warning block

Public Instance Methods

plain() click to toggle source
# File lib/editor_js/blocks/warning_block.rb, line 52
def plain
  string = [
    Sanitize.fragment(data['title']).strip,
    Sanitize.fragment(data['message']).strip
  ].join(', ')
  decode_html(string)
end
render(_options = {}) click to toggle source
# File lib/editor_js/blocks/warning_block.rb, line 19
def render(_options = {})
  title = data['title'].html_safe
  message = data['message'].html_safe

  content_tag :div, class: css_name do
    html_str = content_tag :div, title, class: "#{css_name}__title"
    html_str << content_tag(:div, message, class: "#{css_name}__message")
  end
end
safe_tags() click to toggle source
# File lib/editor_js/blocks/warning_block.rb, line 29
def safe_tags
  {
    'b' => nil,
    'i' => nil,
    'u' => ['class'],
    'del' => ['class'],
    'a' => ['href'],
    'mark' => ['class'],
    'code' => ['class']
  }
end
sanitize!() click to toggle source
# File lib/editor_js/blocks/warning_block.rb, line 41
def sanitize!
  %w[title message].each do |key|
    data[key] = Sanitize.fragment(
      data[key],
      elements: safe_tags.keys,
      attributes: safe_tags.select { |_k, v| v },
      remove_contents: false
    )
  end
end
schema() click to toggle source
# File lib/editor_js/blocks/warning_block.rb, line 7
      def schema
        YAML.safe_load(<<~YAML)
          type: object
          additionalProperties: false
          properties:
            title:
              type: string
            message:
              type: string
        YAML
      end