Sha256: 94fd75a38640789edabb6fbab41c0fa45215cf1b6d7fe239b2d0db0061998e0f

Contents?: true

Size: 1.04 KB

Versions: 84

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require "active_support/core_ext/object/try"

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.render(partial: partial_path, formats: :html, object: self, as: model_name.element)
          end
        end
    end
  end
end

Version data entries

84 entries across 79 versions & 8 rubygems

Version Path
actiontext-7.1.3.2 lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.3.1 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.8.1 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.7.7 lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.3 lib/action_text/attachments/trix_conversion.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actiontext-7.0.3.1/lib/action_text/attachments/trix_conversion.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actiontext-6.1.6.1/lib/action_text/attachments/trix_conversion.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actiontext-7.0.2.3/lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.2 lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.1 lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.0 lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.0.rc2 lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.0.rc1 lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.0.beta1 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.8 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.7.2 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.7.6 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.7.1 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.7.5 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.7 lib/action_text/attachments/trix_conversion.rb