Sha256: 6e8a0cf93f6b8ca5d8729e94f05b637eecd6799eeb174bdd44ed69ef07b53d13

Contents?: true

Size: 1.15 KB

Versions: 12

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Maglev
  module Content
    class Image < Base
      def url
        return image[:url] if asset_host.nil? || !hosted_on_platform?

        URI.join(asset_host, URI.parse(image[:url]).path).to_s
      end

      def width
        image[:width]
      end

      def height
        image[:height]
      end

      def alt_text
        image[:alt_text]
      end

      def to_s
        url
      end

      def tag(view_context, options = {})
        view_context.tag(:img,
                         {
                           src: url,
                           alt: alt_text,
                           data: (options.delete(:data) || {}).merge(tag_data)
                         }.merge(options),
                         false)
      end

      private

      def image
        @image ||= if @content.is_a?(String)
                     { url: @content }
                   elsif @content
                     @content
                   else
                     {}
                   end
      end

      def hosted_on_platform?
        (width.present? && height.present?) || image[:url] =~ %r{^/themes?/}
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
maglevcms-1.1.7 app/components/maglev/content/image.rb
maglevcms-1.1.6 app/components/maglev/content/image.rb
maglevcms-1.1.5 app/components/maglev/content/image.rb
maglevcms-1.1.4 app/components/maglev/content/image.rb
maglevcms-1.1.3 app/components/maglev/content/image.rb
maglevcms-1.1.2 app/components/maglev/content/image.rb
maglevcms-1.1.1 app/components/maglev/content/image.rb
maglevcms-1.1.0 app/components/maglev/content/image.rb
maglevcms-1.0.0 app/components/maglev/content/image.rb
maglevcms-1.0.0.rc3 app/components/maglev/content/image.rb
maglevcms-1.0.0.rc2 app/components/maglev/content/image.rb
maglevcms-1.0.0.rc1 app/components/maglev/content/image.rb