Sha256: 924fbfafac0379b1cec22c90beb4bcddc8c3a115fb2c1fa045de140edcd38f7e

Contents?: true

Size: 1017 Bytes

Versions: 7

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true
require 'dato/local/field_type/file'

module Dato
  module Local
    module FieldType
      class Image < Dato::Local::FieldType::File
        attr_reader :width, :height, :title, :alt

        def self.parse(value, _repo)
          value && new(
            value[:path],
            value[:format],
            value[:size],
            value[:width],
            value[:height],
            value[:alt],
            value[:title]
          )
        end

        def initialize(path, format, size, width, height, alt, title)
          super(path, format, size)
          @width = width
          @height = height
          @alt = alt
          @title = title
        end

        alias raw_file file

        def file
          super.ch('DPR', 'Width').auto('format')
        end

        def to_hash(*args)
          super.merge(
            width: width,
            height: height,
            alt: alt,
            title: title
          )
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dato-0.3.12 lib/dato/local/field_type/image.rb
dato-0.3.9.1 lib/dato/local/field_type/image.rb
dato-0.3.11 lib/dato/local/field_type/image.rb
dato-0.3.10 lib/dato/local/field_type/image.rb
dato-0.3.9 lib/dato/local/field_type/image.rb
dato-0.3.8 lib/dato/local/field_type/image.rb
dato-0.3.7 lib/dato/local/field_type/image.rb