Sha256: 8a26db27e587d66bd2a99048d8fd9f843e7a8cf3eb3411915a636db9d58897bb

Contents?: true

Size: 1.11 KB

Versions: 40

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 =~ /^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

40 entries across 40 versions & 5 rubygems

Version Path
actiontext-6.0.6.1 lib/action_text/attachables/remote_image.rb
actiontext-6.0.6 lib/action_text/attachables/remote_image.rb
actiontext-6.0.5.1 lib/action_text/attachables/remote_image.rb
actiontext5-5.2.0 lib/action_text/attachables/remote_image.rb
actiontext-6.0.5 lib/action_text/attachables/remote_image.rb
actiontext-6.0.4.8 lib/action_text/attachables/remote_image.rb
actiontext-6.0.4.7 lib/action_text/attachables/remote_image.rb
actiontext-6.0.4.6 lib/action_text/attachables/remote_image.rb
actiontext-6.0.4.5 lib/action_text/attachables/remote_image.rb
actiontext-6.0.4.4 lib/action_text/attachables/remote_image.rb
actiontext-6.0.4.3 lib/action_text/attachables/remote_image.rb
actiontext-6.0.4.2 lib/action_text/attachables/remote_image.rb
actiontext-6.0.4.1 lib/action_text/attachables/remote_image.rb
actiontext-6.0.4 lib/action_text/attachables/remote_image.rb
actiontext-6.0.3.7 lib/action_text/attachables/remote_image.rb
actiontext-6.0.3.6 lib/action_text/attachables/remote_image.rb
actiontext-6.0.3.5 lib/action_text/attachables/remote_image.rb
actiontext-6.0.3.4 lib/action_text/attachables/remote_image.rb
actiontext-6.0.3.3 lib/action_text/attachables/remote_image.rb
actiontext-6.0.3.2 lib/action_text/attachables/remote_image.rb