lib/dynamic_image/helper.rb in dynamic_image-2.0.0.beta5 vs lib/dynamic_image/helper.rb in dynamic_image-2.0.0.beta6
- old
+ new
@@ -28,11 +28,11 @@
# dynamic_image_tag(image)
# # => <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_record(record_or_array)
+ record = extract_dynamic_image_record(record_or_array)
options = {
alt: image_alt(record.filename)
}.merge(options)
size = fit_size!(record_or_array, options)
@@ -128,34 +128,43 @@
def dynamic_image_path_with_size(record_or_array, size=nil, options={})
dynamic_image_url_with_size(record_or_array, size, { routing_type: :path }.merge(options))
end
def dynamic_image_url_with_size(record_or_array, size=nil, options={})
- record = extract_record(record_or_array)
+ record = extract_dynamic_image_record(record_or_array)
options = {
routing_type: :url,
action: nil,
format: default_format_for_image(record),
size: size
}.merge(options)
options[:digest] = dynamic_image_digest(record, options[:action], options[:size])
polymorphic_url(record_or_array, options)
end
+ def extract_dynamic_image_record(record_or_array)
+ case record_or_array
+ when Array
+ record_or_array.last
+ else
+ record_or_array
+ end
+ end
+
def fit_size!(record_or_array, options)
- record = extract_record(record_or_array)
+ record = extract_dynamic_image_record(record_or_array)
action = options[:action].try(:to_s)
size_opts = options.extract!(:size, :crop, :upscale)
if size_opts[:size]
DynamicImage::ImageSizing.new(
record,
uncropped: (action == "uncropped")
).fit(size_opts[:size], size_opts).floor.to_s
- elsif action != "original"
- record.size.floor.to_s
+ elsif action == "original"
+ record.real_size.floor.to_s
else
- nil
+ record.size.floor.to_s
end
end
end
end