automatic image size calculations
This commit is contained in:
parent
9e40e36b2c
commit
8fcb1d0133
|
@ -4,10 +4,10 @@ class Middleman::Base
|
||||||
alias_method :pre_automatic_image_tag, :image_tag
|
alias_method :pre_automatic_image_tag, :image_tag
|
||||||
helpers do
|
helpers do
|
||||||
def image_tag(path, params={})
|
def image_tag(path, params={})
|
||||||
|
if (!params[:width] || !params[:height]) && !path.include?("://")
|
||||||
params[:alt] ||= ""
|
params[:alt] ||= ""
|
||||||
prefix = options.http_images_path rescue options.images_dir
|
prefix = options.http_images_path rescue options.images_dir
|
||||||
|
|
||||||
if (!params[:width] || !params[:height]) && !path.include?("://")
|
|
||||||
begin
|
begin
|
||||||
real_path = File.join(options.public, asset_url(path, prefix))
|
real_path = File.join(options.public, asset_url(path, prefix))
|
||||||
if File.exists? real_path
|
if File.exists? real_path
|
||||||
|
@ -17,11 +17,13 @@ class Middleman::Base
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
params = params.merge(:src => asset_url(path, prefix))
|
params = params.merge(:src => asset_url(path, prefix))
|
||||||
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
|
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
|
||||||
"<img #{params} />"
|
"<img #{params} />"
|
||||||
|
else
|
||||||
|
pre_automatic_image_tag(path, params)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue