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-6.1.5.1 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.5 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.2.3 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.4.7 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.2.2 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.4.6 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.4.5 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.2.1 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.2 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.1 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.0 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.4.4 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.0.rc3 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.4.3 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.4.2 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.0.rc2 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.0.rc1 lib/action_text/attachments/trix_conversion.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/actiontext-6.1.4.1/lib/action_text/attachments/trix_conversion.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/actiontext-6.1.4.1/lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.0.alpha2 lib/action_text/attachments/trix_conversion.rb