Sha256: 78ef224065692b6a062ea958a8a25d42db2a4bf121d824f87fec5fa6b1215f6d

Contents?: true

Size: 1 KB

Versions: 38

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module ActionText
  # The RichText record holds the content produced by the Trix editor in a serialized +body+ attribute.
  # It also holds all the references to the embedded files, which are stored using Active Storage.
  # This record is then associated with the Active Record model the application desires to have
  # rich text content using the +has_rich_text+ class method.
  class RichText < Record
    self.table_name = "action_text_rich_texts"

    serialize :body, ActionText::Content
    delegate :to_s, :nil?, to: :body

    belongs_to :record, polymorphic: true, touch: true
    has_many_attached :embeds

    before_save do
      self.embeds = body.attachables.grep(ActiveStorage::Blob).uniq if body.present?
    end

    def to_plain_text
      body&.to_plain_text.to_s
    end

    def to_trix_html
      body&.to_trix_html
    end

    delegate :blank?, :empty?, :present?, to: :to_plain_text
  end
end

ActiveSupport.run_load_hooks :action_text_rich_text, ActionText::RichText

Version data entries

38 entries across 36 versions & 4 rubygems

Version Path
actiontext-7.0.8.7 app/models/action_text/rich_text.rb
actiontext-7.0.8.6 app/models/action_text/rich_text.rb
actiontext-7.0.8.5 app/models/action_text/rich_text.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actiontext-7.0.8.4/app/models/action_text/rich_text.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/actiontext-7.0.5.1/app/models/action_text/rich_text.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/actiontext-7.0.5.1/app/models/action_text/rich_text.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/actiontext-7.0.5.1/app/models/action_text/rich_text.rb
actiontext-7.0.8.4 app/models/action_text/rich_text.rb
actiontext-7.0.8.1 app/models/action_text/rich_text.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actiontext-7.0.3.1/app/models/action_text/rich_text.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actiontext-7.0.2.3/app/models/action_text/rich_text.rb
actiontext-7.0.8 app/models/action_text/rich_text.rb
actiontext-7.0.7.2 app/models/action_text/rich_text.rb
actiontext-7.0.7.1 app/models/action_text/rich_text.rb
actiontext-7.0.7 app/models/action_text/rich_text.rb
actiontext-7.0.6 app/models/action_text/rich_text.rb
actiontext-7.0.5.1 app/models/action_text/rich_text.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/actiontext-7.0.2.3/app/models/action_text/rich_text.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/actiontext-7.0.3.1/app/models/action_text/rich_text.rb
actiontext-7.0.5 app/models/action_text/rich_text.rb