fix auto image sizes, make default helpers first feature
This commit is contained in:
parent
8b00e830f9
commit
d638fe8ce2
3 changed files with 239 additions and 234 deletions
|
@ -25,10 +25,10 @@ module Middleman
|
|||
end
|
||||
|
||||
# livereload
|
||||
%w(asset_host
|
||||
%w(default_helpers
|
||||
asset_host
|
||||
automatic_image_sizes
|
||||
cache_buster
|
||||
default_helpers
|
||||
minify_css
|
||||
minify_javascript
|
||||
relative_assets
|
||||
|
|
|
@ -2,8 +2,8 @@ class Middleman::Features::AutomaticImageSizes
|
|||
def initialize(app, config)
|
||||
require "middleman/features/automatic_image_sizes/fastimage"
|
||||
|
||||
Middleman::Server.send :alias_method, :pre_automatic_image_tag, :image_tag
|
||||
Middleman::Server.helpers do
|
||||
alias_method :pre_automatic_image_tag, :image_tag
|
||||
def image_tag(path, params={})
|
||||
if (!params[:width] || !params[:height]) && !path.include?("://")
|
||||
params[:alt] ||= ""
|
||||
|
@ -12,7 +12,7 @@ class Middleman::Features::AutomaticImageSizes
|
|||
begin
|
||||
real_path = File.join(settings.public, settings.images_dir, path)
|
||||
if File.exists? real_path
|
||||
dimensions = Middleman::FastImage.size(real_path, :raise_on_failure => true)
|
||||
dimensions = ::FastImage.size(real_path, :raise_on_failure => true)
|
||||
params[:width] ||= dimensions[0]
|
||||
params[:height] ||= dimensions[1]
|
||||
end
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
require 'net/https'
|
||||
require 'open-uri'
|
||||
|
||||
module Middleman
|
||||
class FastImage
|
||||
attr_reader :size, :type
|
||||
|
||||
|
@ -137,16 +136,22 @@ module Middleman
|
|||
@property = options[:type_only] ? :type : :size
|
||||
@timeout = options[:timeout] || DefaultTimeout
|
||||
@uri = uri
|
||||
@parsed_uri = URI.parse(uri.gsub(/\s/, "%20"))
|
||||
begin
|
||||
@parsed_uri = URI.parse(uri)
|
||||
rescue URI::InvalidURIError
|
||||
fetch_using_open_uri
|
||||
else
|
||||
if @parsed_uri.scheme == "http" || @parsed_uri.scheme == "https"
|
||||
fetch_using_http
|
||||
else
|
||||
fetch_using_open_uri
|
||||
end
|
||||
end
|
||||
raise SizeNotFound if options[:raise_on_failure] && @property == :size && !@size
|
||||
rescue Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET, ImageFetchFailure
|
||||
rescue Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET,
|
||||
ImageFetchFailure, Net::HTTPBadResponse, EOFError, Errno::ENOENT
|
||||
raise ImageFetchFailure if options[:raise_on_failure]
|
||||
rescue Errno::ENOENT
|
||||
rescue NoMethodError # 1.8.7p248 can raise this due to a net/http bug
|
||||
raise ImageFetchFailure if options[:raise_on_failure]
|
||||
rescue UnknownImageType
|
||||
raise UnknownImageType if options[:raise_on_failure]
|
||||
|
@ -198,6 +203,7 @@ module Middleman
|
|||
|
||||
def parse_size
|
||||
@type = parse_type unless @type
|
||||
@strpos = 0
|
||||
send("parse_size_for_#{@type}")
|
||||
end
|
||||
|
||||
|
@ -237,11 +243,11 @@ module Middleman
|
|||
end
|
||||
|
||||
def parse_size_for_gif
|
||||
get_chars(9)[4..8].unpack('SS')
|
||||
get_chars(11)[6..10].unpack('SS')
|
||||
end
|
||||
|
||||
def parse_size_for_png
|
||||
get_chars(23)[14..22].unpack('NN')
|
||||
get_chars(25)[16..24].unpack('NN')
|
||||
end
|
||||
|
||||
def parse_size_for_jpeg
|
||||
|
@ -275,8 +281,7 @@ module Middleman
|
|||
end
|
||||
|
||||
def parse_size_for_bmp
|
||||
d = get_chars(27)[12..26]
|
||||
d[0] == 40 ? d[4..-1].unpack('LL') : d[4..8].unpack('SS')
|
||||
end
|
||||
d = get_chars(29)[14..28]
|
||||
d.unpack("C")[0] == 40 ? d[4..-1].unpack('LL') : d[4..8].unpack('SS')
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue