Sha256: afab3ba27753468ca54068109fc6c4ae9aaa6f7ef28d42fac5df9ac9c7d8cfc0

Contents?: true

Size: 1.34 KB

Versions: 19

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Alchemy
  module Ingredients
    # A blob of richtext
    #
    class Richtext < Alchemy::Ingredient
      store_accessor :data,
        :stripped_body,
        :sanitized_body

      allow_settings %i[
        plain_text
        sanitizer
        tinymce
      ]

      before_save :strip_content
      before_save :sanitize_content

      # The first 30 characters of the stripped_body
      #
      # Used by the Element#preview_text method.
      #
      # @param [Integer] max_length (30)
      #
      def preview_text(max_length = 30)
        stripped_body.to_s[0..max_length - 1]
      end

      def element_id
        "tinymce_#{id}"
      end

      def has_tinymce?
        true
      end

      # Returns true if there is a tinymce setting defined that contains settings.
      def has_custom_tinymce_config?
        custom_tinymce_config.is_a?(Hash)
      end

      def custom_tinymce_config
        settings[:tinymce]
      end

      private

      def strip_content
        self.stripped_body = Rails::Html::FullSanitizer.new.sanitize(value)
      end

      def sanitize_content
        self.sanitized_body = Rails::Html::SafeListSanitizer.new.sanitize(
          value,
          sanitizer_settings
        )
      end

      def sanitizer_settings
        settings[:sanitizer] || {}
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
alchemy_cms-7.0.15 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.14 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.13 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.12 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.11 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.10 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.9 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.8 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.7 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.6 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.5 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.4 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.3 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.2 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.1 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.0 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.0.pre.rc1 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.0.pre.c app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.0.0.pre.b app/models/alchemy/ingredients/richtext.rb