Sha256: 4466327bf78b26ab4ff7a1ff41bf351be754534581376e40ad73b383acfe9dca

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

module Panda
  module CMS
    module EditorJs
      module Blocks
        class Quote < Base
          def render
            text = data["text"]
            caption = data["caption"]
            alignment = data["alignment"] || "left"

            # Build the HTML structure
            html = "<figure class=\"text-#{alignment}\">" \
              "<blockquote>#{wrap_text_in_p(text)}</blockquote>" \
              "#{caption_element(caption)}" \
              "</figure>"

            # Return raw HTML - validation will be handled by the main renderer if enabled
            html_safe(html)
          end

          private

          def wrap_text_in_p(text)
            # Only wrap in <p> if it's not already wrapped
            text = sanitize(text)
            if text.start_with?("<p>") && text.end_with?("</p>")
              text
            else
              "<p>#{text}</p>"
            end
          end

          def caption_element(caption)
            return "" if caption.blank?
            "<figcaption>#{sanitize(caption)}</figcaption>"
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
panda-cms-0.7.3 lib/panda/cms/editor_js/blocks/quote.rb
panda-cms-0.7.2 lib/panda/cms/editor_js/blocks/quote.rb
panda-cms-0.7.0 lib/panda/cms/editor_js/blocks/quote.rb