AlchemyCMS/alchemy_cms

View on GitHub
app/models/alchemy/ingredients/html.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module Alchemy
  module Ingredients
    # A HTML string
    #
    class Html < Alchemy::Ingredient
      # The first 30 escaped characters from value
      #
      # Used by the Element#preview_text method.
      #
      # @param [Integer] max_length (30)
      #
      def preview_text(max_length = 30)
        ::CGI.escapeHTML(value.to_s)[0..max_length - 1]
      end
    end
  end
end