Class: PandaCms::EditorJs::Blocks::Image

Inherits:
Base
  • Object
show all
Defined in:
app/lib/panda_cms/editor_js/blocks/image.rb

Instance Attribute Summary

Attributes inherited from Base

#data, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from PandaCms::EditorJs::Blocks::Base

Instance Method Details

#renderObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/lib/panda_cms/editor_js/blocks/image.rb', line 5

def render
  url = data["url"]
  caption = sanitize(data["caption"])
  with_border = data["withBorder"]
  with_background = data["withBackground"]
  stretched = data["stretched"]

  css_classes = ["prose"]
  css_classes << "border" if with_border
  css_classes << "bg-gray-100" if with_background
  css_classes << "w-full" if stretched

  html_safe(<<~HTML)
    <figure class="#{css_classes.join(" ")}">
      <img src="#{url}" alt="#{caption}" />
      #{caption_element(caption)}
    </figure>
  HTML
end