Sha256: 3ebdd58557f482f686f63df17d3d5d350457680c5a3b35c0432ca658a1d1daf6

Contents?: true

Size: 1.22 KB

Versions: 29

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module PandaCms
  # Text component
  # @param key [Symbol] The key to use for the text component
  # @param text [String] The text to display
  # @param editable [Boolean] If the text is editable or not (defaults to true)
  # @param options [Hash] The options to pass to the content_tag
  class RichTextComponent < ViewComponent::Base
    KIND = "rich_text"

    def initialize(key: :text_component, text: "Lorem ipsum...", editable: true, **options)
      @key = key
      @text = text
      @options = options || {}
      @editable = editable
    end

    # Check if the element is editable and set up the content
    def before_render
      @editable &&= params[:embed_id].present? && params[:embed_id] == Current.page.id && Current.user&.admin?

      block = PandaCms::Block.find_by(kind: "rich_text", key: @key, panda_cms_template_id: Current.page.panda_cms_template_id)
      block_content = block.block_contents.find_by(panda_cms_page_id: Current.page.id)
      @content = block_content.content.html_safe
      @options[:id] = "editor_rich_text_#{block_content&.id&.tr("-", "_")}"

      if @editable
        @options[:data] = {
          block_content_id: block_content&.id
        }
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
panda_cms-0.5.4 app/components/panda_cms/rich_text_component.rb
panda_cms-0.5.3 app/components/panda_cms/rich_text_component.rb
panda_cms-0.5.2 app/components/panda_cms/rich_text_component.rb
panda_cms-0.5.1 app/components/panda_cms/rich_text_component.rb
panda_cms-0.5.0 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.15 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.14 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.13 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.12 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.11 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.10 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.9 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.8 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.7 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.6 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.5 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.4 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.3 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.2 app/components/panda_cms/rich_text_component.rb
panda_cms-0.3.1 app/components/panda_cms/rich_text_component.rb