url_generator_extensions.rb 623 B

123456789101112131415161718192021
  1. # frozen_string_literal: true
  2. module Paperclip
  3. module UrlGeneratorExtensions
  4. # Monkey-patch Paperclip to use Addressable::URI's normalization instead
  5. # of the long-deprecated URI.esacpe
  6. def escape_url(url)
  7. if url.respond_to?(:escape)
  8. url.escape
  9. else
  10. Addressable::URI.parse(url).normalize.to_str.gsub(escape_regex) { |m| "%#{m.ord.to_s(16).upcase}" }
  11. end
  12. end
  13. def for_as_default(style_name)
  14. attachment_options[:interpolator].interpolate(default_url, @attachment, style_name)
  15. end
  16. end
  17. end
  18. Paperclip::UrlGenerator.prepend(Paperclip::UrlGeneratorExtensions)