Last active
August 29, 2015 14:18
-
-
Save bernardo-cs/14cf45c4e297bd43b582 to your computer and use it in GitHub Desktop.
Auto register jpg methods in middleman in middleman
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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