Sha256: 85012aec63284d4fb553458da82a786e63ba77eed3303666ccd6ce6fd08e4983

Contents?: true

Size: 1.12 KB

Versions: 36

Compression:

Stored size: 1.12 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 has_tinymce?
        true
      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

36 entries across 36 versions & 1 rubygems

Version Path
alchemy_cms-7.4.2 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.3.6 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.2.9 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.4.1 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.4.0 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.3.5 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.2.8 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.1.13 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.3.4 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.3.3 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.3.2 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.2.7 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.3.1 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.3.0 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.2.6 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.2.5 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.1.12 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.2.4 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.1.11 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-7.2.3 app/models/alchemy/ingredients/richtext.rb