Sha256: 3f4a6efbaa6304077da5b64a3bc58ef51f9341060ab523dc760fdc5d2f996d59
Contents?: true
Size: 802 Bytes
Versions: 4
Compression:
Stored size: 802 Bytes
Contents
# Automatic Image alt tags from image names extension class Middleman::Extensions::AutomaticAltTags < ::Middleman::Extension def initialize(app, options_hash={}, &block) super end helpers do # Override default image_tag helper to automatically insert alt tag # containing image name. def image_tag(path) if !path.include?('://') params[:alt] ||= '' real_path = path real_path = File.join(images_dir, real_path) unless real_path.start_with?('/') full_path = File.join(source_dir, real_path) if File.exists?(full_path) begin alt_text = File.basename(full_path, '.*') alt_text.capitalize! params[:alt] = alt_text end end end super(path) end end end
Version data entries
4 entries across 4 versions & 1 rubygems