Sha256: c83d4652b7c3deeab731dea8e227eb14e9e8433def5a36f851a1538a2e7a5256

Contents?: true

Size: 1004 Bytes

Versions: 5

Compression:

Stored size: 1004 Bytes

Contents

require "middleman/fastimage"

class Middleman::Base
  alias_method :pre_automatic_image_tag, :image_tag
  helpers do
    def image_tag(path, params={})
      if !options.respond_to?(:automatic_image_sizes?) || !options.automatic_image_sizes?
        return pre_automatic_image_tag(path, params)
      end

      if (!params[:width] || !params[:height]) && !path.include?("://")
        params[:alt] ||= ""
        http_prefix = options.http_images_path rescue options.images_dir

        begin
          real_path = File.join(options.public, options.images_dir, path)
          if File.exists? real_path
            dimensions = Middleman::FastImage.size(real_path, :raise_on_failure => true)
            params[:width]  ||= dimensions[0]
            params[:height] ||= dimensions[1]
          end
        rescue
        end

        capture_haml { haml_tag(:img, params.merge(:src => asset_url(path, http_prefix))) }
      else
        pre_automatic_image_tag(path, params)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
middleman-0.12.2 lib/middleman/features/automatic_image_sizes.rb
middleman-0.12.1 lib/middleman/features/automatic_image_sizes.rb
middleman-0.12.0.pre3 lib/middleman/features/automatic_image_sizes.rb
middleman-0.12.0.pre2 lib/middleman/features/automatic_image_sizes.rb
middleman-0.12.0.pre lib/middleman/features/automatic_image_sizes.rb