Skip to content

Instantly share code, notes, and snippets.

@bernardo-cs
Last active August 29, 2015 14:18
Show Gist options
  • Save bernardo-cs/14cf45c4e297bd43b582 to your computer and use it in GitHub Desktop.
Save bernardo-cs/14cf45c4e297bd43b582 to your computer and use it in GitHub Desktop.
Auto register jpg methods in middleman in middleman
# place me inside the helpers folder on the root of the middleman project
# ex.:
# (given that you have an image name slider.jpg inside the images folder)
#
# slider_image()
# => "<img src=\"slider.jpg\" />"
#
# slider_image( class: 'foo', 'data-attribute': 'bar')
# => "<img class=\"foo\" data-attribute=\"bar\" src=\"slider.jpg\" />"
module ImageHelper
Dir.glob('source/images/*.jpg').each do |file_name|
define_method( ( File.basename( file_name,".*") + "_image" ).to_sym ) do |hsh={}|
hsh[:src] = file_name.gsub(/source/, '')
tag :img, hsh
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment