Class: EditorJs::Blocks::ImageBlock
- Defined in:
- lib/editor_js/blocks/image_block.rb
Overview
image block
Direct Known Subclasses
Constant Summary
Constants inherited from Base
Base::InvalidBlockDataError, Base::InvalidBlockTypeError
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#css_name, #data, #decode_html, inherited, #initialize, load, #output, registry, type, #type, #valid?
Constructor Details
This class inherits a constructor from EditorJs::Blocks::Base
Instance Method Details
#plain ⇒ Object
57 58 59 |
# File 'lib/editor_js/blocks/image_block.rb', line 57 def plain decode_html data['caption'].strip end |
#render(_options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/editor_js/blocks/image_block.rb', line 27 def render( = {}) content_tag :div, class: css_name do url = data['url'] = 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, .html_safe, class: "#{css_name}__caption").html_safe end end |
#sanitize! ⇒ Object
47 48 49 50 51 52 53 54 55 |
# 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!('&', '&') end data[key] = str end end |
#schema ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |