Sha256: 5515479773e77833ae3c7dad7b286c8ad2c9acbdeeecd806d41d777dd7a957f2

Contents?: true

Size: 1.3 KB

Versions: 39

Compression:

Stored size: 1.3 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

      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

      # Returns css class names for the editor textarea.
      def tinymce_class_name
        "has_tinymce#{has_custom_tinymce_config? ? " #{element.name}_#{role}" : ""}"
      end

      def has_tinymce?
        true
      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

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

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
alchemy_cms-6.1.10 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.1.9 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.1.8 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.1.7 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.1.6 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.1.5 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.0.14 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.1.4 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.0.13 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.1.3 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.1.2 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.1.1 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.1.0 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.0.12 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.0.11 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.0.10 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.0.9 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.0.8 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.0.7 app/models/alchemy/ingredients/richtext.rb
alchemy_cms-6.0.6 app/models/alchemy/ingredients/richtext.rb