Sha256: 517386b81382c9733165c4d4f6818c3357b1754b82bca04aa859a4d278f18aee

Contents?: true

Size: 1.13 KB

Versions: 18

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

# :markup: markdown

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

18 entries across 18 versions & 2 rubygems

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