Sha256: 1232d5bf38ca33b75c8f8d843d915daf2c8dc39fb98a7d6c5abee18f963e0e59

Contents?: true

Size: 1013 Bytes

Versions: 35

Compression:

Stored size: 1013 Bytes

Contents

# frozen_string_literal: true

module ActionText
  module Attachments
    module TrixConversion
      extend ActiveSupport::Concern

      class_methods do
        def fragment_by_converting_trix_attachments(content)
          Fragment.wrap(content).replace(TrixAttachment::SELECTOR) do |node|
            from_trix_attachment(TrixAttachment.new(node))
          end
        end

        def from_trix_attachment(trix_attachment)
          from_attributes(trix_attachment.attributes)
        end
      end

      def to_trix_attachment(content = trix_attachment_content)
        attributes = full_attributes.dup
        attributes["content"] = content if content
        TrixAttachment.from_attributes(attributes)
      end

      private
        def trix_attachment_content
          if partial_path = attachable.try(:to_trix_content_attachment_partial_path)
            ActionText::Content.renderer.render(partial: partial_path, object: self, as: model_name.element)
          end
        end
    end
  end
end

Version data entries

35 entries across 35 versions & 4 rubygems

Version Path
actiontext-6.0.4.8 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.4.7 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.4.6 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.4.5 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.4.4 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.4.3 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.4.2 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.4.1 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.4 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.3.7 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.3.6 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.3.5 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.3.4 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.3.3 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.3.2 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.3.1 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.3 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.3.rc1 lib/action_text/attachments/trix_conversion.rb
actiontext-6.0.2.2 lib/action_text/attachments/trix_conversion.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/actiontext-6.0.2.1/lib/action_text/attachments/trix_conversion.rb