Sha256: b4013463eb538040036e9137685dcf1fe83b8a8d9dbca9fbd1ef881d5f88f502

Contents?: true

Size: 918 Bytes

Versions: 16

Compression:

Stored size: 918 Bytes

Contents

# frozen_string_literal: true

module ActionText
  module Attachables
    class ContentAttachment # :nodoc:
      include ActiveModel::Model

      def self.from_node(node)
        attachment = new(content_type: node["content-type"], content: node["content"])
        attachment if attachment.valid?
      end

      attr_accessor :content_type, :content

      validates_format_of :content_type, with: /html/
      validates_presence_of :content

      def attachable_plain_text_representation(caption)
        content_instance.fragment.source
      end

      def to_html
        @to_html ||= content_instance.render(content_instance)
      end

      def to_s
        to_html
      end

      def to_partial_path
        "action_text/attachables/content_attachment"
      end

      private
        def content_instance
          @content_instance ||= ActionText::Content.new(content)
        end
    end
  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
actiontext-7.1.5 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.4.2 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.4.1 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.4 lib/action_text/attachables/content_attachment.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actiontext-7.1.3.4/lib/action_text/attachables/content_attachment.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/actiontext-7.1.3.4/lib/action_text/attachables/content_attachment.rb
actiontext-7.1.3.4 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.3.2 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.3.1 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.3 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.2 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.1 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.0 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.0.rc2 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.0.rc1 lib/action_text/attachables/content_attachment.rb
actiontext-7.1.0.beta1 lib/action_text/attachables/content_attachment.rb