Sha256: 9fe8c30a6971d71a92f9082e26d163b925f2ebd724447610c0bbce87711076c2

Contents?: true

Size: 1.11 KB

Versions: 93

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module ActionText
  module Attachables
    class RemoteImage
      extend ActiveModel::Naming

      class << self
        def from_node(node)
          if node["url"] && content_type_is_image?(node["content-type"])
            new(attributes_from_node(node))
          end
        end

        private
          def content_type_is_image?(content_type)
            content_type.to_s.match?(/^image(\/.+|$)/)
          end

          def attributes_from_node(node)
            { url: node["url"],
              content_type: node["content-type"],
              width: node["width"],
              height: node["height"] }
          end
      end

      attr_reader :url, :content_type, :width, :height

      def initialize(attributes = {})
        @url = attributes[:url]
        @content_type = attributes[:content_type]
        @width = attributes[:width]
        @height = attributes[:height]
      end

      def attachable_plain_text_representation(caption)
        "[#{caption || "Image"}]"
      end

      def to_partial_path
        "action_text/attachables/remote_image"
      end
    end
  end
end

Version data entries

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