Sha256: 3492f56b62b92d8e69e8f5556102af43c5c7bd65226cad529fbabc7f4ddfc563

Contents?: true

Size: 939 Bytes

Versions: 21

Compression:

Stored size: 939 Bytes

Contents

# frozen_string_literal: true

# :markup: markdown

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

21 entries across 21 versions & 2 rubygems

Version Path
actiontext-8.0.1 lib/action_text/attachables/content_attachment.rb
actiontext-8.0.0.1 lib/action_text/attachables/content_attachment.rb
actiontext-7.2.2.1 lib/action_text/attachables/content_attachment.rb
actiontext-8.0.0 lib/action_text/attachables/content_attachment.rb
actiontext-7.2.2 lib/action_text/attachables/content_attachment.rb
actiontext-8.0.0.rc2 lib/action_text/attachables/content_attachment.rb
actiontext-7.2.1.2 lib/action_text/attachables/content_attachment.rb
actiontext-8.0.0.rc1 lib/action_text/attachables/content_attachment.rb
actiontext-7.2.1.1 lib/action_text/attachables/content_attachment.rb
actiontext-8.0.0.beta1 lib/action_text/attachables/content_attachment.rb
omg-actiontext-8.0.0.alpha9 lib/action_text/attachables/content_attachment.rb
omg-actiontext-8.0.0.alpha8 lib/action_text/attachables/content_attachment.rb
omg-actiontext-8.0.0.alpha7 lib/action_text/attachables/content_attachment.rb
omg-actiontext-8.0.0.alpha4 lib/action_text/attachables/content_attachment.rb
omg-actiontext-8.0.0.alpha3 lib/action_text/attachables/content_attachment.rb
actiontext-7.2.1 lib/action_text/attachables/content_attachment.rb
actiontext-7.2.0 lib/action_text/attachables/content_attachment.rb
actiontext-7.2.0.rc1 lib/action_text/attachables/content_attachment.rb
actiontext-7.2.0.beta3 lib/action_text/attachables/content_attachment.rb
actiontext-7.2.0.beta2 lib/action_text/attachables/content_attachment.rb