lib/dynamic_image/helper.rb in dynamic_image-2.0.13 vs lib/dynamic_image/helper.rb in dynamic_image-2.0.14

- old
+ new

@@ -29,11 +29,11 @@ # # => <img alt="My file" height="200" src="..." width="320" /> # dynamic_image_tag(image, size: "100x100", alt="Avatar") # # => <img alt="Avatar" height="62" src="..." width="100" /> def dynamic_image_tag(record_or_array, options = {}) record = extract_dynamic_image_record(record_or_array) - options = { alt: image_alt(record.filename) }.merge(options) + options = { alt: filename_to_alt(record.filename) }.merge(options) size = fit_size!(record_or_array, options) url_options = options.extract!(*allowed_dynamic_image_url_options) html_options = { size: size }.merge(options) @@ -157,9 +157,16 @@ when Array record_or_array.last else record_or_array end + end + + def filename_to_alt(str) + File.basename(str, ".*".freeze) + .sub(/-[[:xdigit:]]{32,64}\z/, "".freeze) + .tr("-_".freeze, " ".freeze) + .capitalize end def fit_size!(record_or_array, options) record = extract_dynamic_image_record(record_or_array) action = options[:action].try(:to_s)