Sha256: d953b965bc857313383294c1e5a6aa8a188416d9b0a88d72212c4cda6ee807ac

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module Middleman::Features::AutomaticImageSizes
  class << self
    def registered(app)
      require "middleman/features/automatic_image_sizes/fastimage"

      app.send :include, InstanceMethods
    end
    alias :included :registered
  end
  
  module InstanceMethods
    def image_tag(path, params={})
      if !params.has_key?(:width) && !params.has_key?(:height) && !path.include?("://")
        params[:alt] ||= ""
        http_prefix = self.http_images_path rescue self.images_dir

        begin
          real_path = File.join(self.views, self.images_dir, path)
          full_path = File.expand_path(real_path, self.root)
          http_prefix = self.http_images_path rescue self.images_dir
          if File.exists? full_path
            dimensions = ::FastImage.size(full_path, :raise_on_failure => true)
            params[:width]  = dimensions[0]
            params[:height] = dimensions[1]
          end
        rescue
          # $stderr.puts params.inspect
        end
      end
      
      super(path, params)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-3.0.0.alpha.2 lib/middleman/features/automatic_image_sizes.rb