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
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/actiontext-7.1.3.4/lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.5.1 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.8.7 lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.5 lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.4.2 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.8.6 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.7.10 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.7.9 lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.4.1 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.8.5 lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.4 lib/action_text/attachments/trix_conversion.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actiontext-7.1.3.4/lib/action_text/attachments/trix_conversion.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actiontext-7.0.8.4/lib/action_text/attachments/trix_conversion.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/actiontext-7.0.5.1/lib/action_text/attachments/trix_conversion.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/actiontext-7.0.5.1/lib/action_text/attachments/trix_conversion.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/actiontext-7.0.5.1/lib/action_text/attachments/trix_conversion.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/actiontext-7.1.3.4/lib/action_text/attachments/trix_conversion.rb
actiontext-7.1.3.4 lib/action_text/attachments/trix_conversion.rb
actiontext-7.0.8.4 lib/action_text/attachments/trix_conversion.rb
actiontext-6.1.7.8 lib/action_text/attachments/trix_conversion.rb