Sha256: 9fe8c30a6971d71a92f9082e26d163b925f2ebd724447610c0bbce87711076c2

Contents?: true

Size: 1.11 KB

Versions: 94

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

94 entries across 89 versions & 9 rubygems

Version Path
actiontext-7.0.2.4 lib/action_text/attachables/remote_image.rb
actiontext-6.1.5.1 lib/action_text/attachables/remote_image.rb
actiontext-6.1.5 lib/action_text/attachables/remote_image.rb
actiontext-7.0.2.3 lib/action_text/attachables/remote_image.rb
actiontext-6.1.4.7 lib/action_text/attachables/remote_image.rb
actiontext-7.0.2.2 lib/action_text/attachables/remote_image.rb
actiontext-6.1.4.6 lib/action_text/attachables/remote_image.rb
actiontext-6.1.4.5 lib/action_text/attachables/remote_image.rb
actiontext-7.0.2.1 lib/action_text/attachables/remote_image.rb
actiontext-7.0.2 lib/action_text/attachables/remote_image.rb
actiontext-7.0.1 lib/action_text/attachables/remote_image.rb
actiontext-7.0.0 lib/action_text/attachables/remote_image.rb
actiontext-6.1.4.4 lib/action_text/attachables/remote_image.rb
actiontext-7.0.0.rc3 lib/action_text/attachables/remote_image.rb
actiontext-6.1.4.3 lib/action_text/attachables/remote_image.rb
actiontext-6.1.4.2 lib/action_text/attachables/remote_image.rb
actiontext-7.0.0.rc2 lib/action_text/attachables/remote_image.rb
actiontext-7.0.0.rc1 lib/action_text/attachables/remote_image.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/actiontext-6.1.4.1/lib/action_text/attachables/remote_image.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/actiontext-6.1.4.1/lib/action_text/attachables/remote_image.rb