Sha256: 8a6741598eccd3b9d29fd99cb8f53de1fd6f4ad5480c2d8604b3aef19ae0f3c4

Contents?: true

Size: 908 Bytes

Versions: 114

Compression:

Stored size: 908 Bytes

Contents

# frozen_string_literal: true

module ActionText
  module Attachables
    class ContentAttachment
      include ActiveModel::Model

      def self.from_node(node)
        if node["content-type"]
          if matches = node["content-type"].match(/vnd\.rubyonrails\.(.+)\.html/)
            attachment = new(name: matches[1])
            attachment if attachment.valid?
          end
        end
      end

      attr_accessor :name
      validates_inclusion_of :name, in: %w( horizontal-rule )

      def attachable_plain_text_representation(caption)
        case name
        when "horizontal-rule"
          " ┄ "
        else
          " "
        end
      end

      def to_partial_path
        "action_text/attachables/content_attachment"
      end

      def to_trix_content_attachment_partial_path
        "action_text/attachables/content_attachments/#{name.underscore}"
      end
    end
  end
end

Version data entries

114 entries across 110 versions & 10 rubygems

Version Path
actiontext-7.0.8.6 lib/action_text/attachables/content_attachment.rb
actiontext-6.1.7.10 lib/action_text/attachables/content_attachment.rb
actiontext-6.1.7.9 lib/action_text/attachables/content_attachment.rb
actiontext-7.0.8.5 lib/action_text/attachables/content_attachment.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actiontext-7.0.8.4/lib/action_text/attachables/content_attachment.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/actiontext-7.0.5.1/lib/action_text/attachables/content_attachment.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/actiontext-7.0.5.1/lib/action_text/attachables/content_attachment.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/actiontext-7.0.5.1/lib/action_text/attachables/content_attachment.rb
actiontext-7.0.8.4 lib/action_text/attachables/content_attachment.rb
actiontext-6.1.7.8 lib/action_text/attachables/content_attachment.rb
actiontext-7.0.8.1 lib/action_text/attachables/content_attachment.rb
actiontext-6.1.7.7 lib/action_text/attachables/content_attachment.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actiontext-7.0.2.3/lib/action_text/attachables/content_attachment.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actiontext-7.0.3.1/lib/action_text/attachables/content_attachment.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actiontext-6.1.6.1/lib/action_text/attachables/content_attachment.rb
actiontext-7.0.8 lib/action_text/attachables/content_attachment.rb
actiontext-7.0.7.2 lib/action_text/attachables/content_attachment.rb
actiontext-6.1.7.6 lib/action_text/attachables/content_attachment.rb
actiontext-7.0.7.1 lib/action_text/attachables/content_attachment.rb
actiontext-6.1.7.5 lib/action_text/attachables/content_attachment.rb