James Peret's blog. Built with Jekyll and the Mikey theme.

url_encode.rb 324B

12345678910111213
  1. # _plugins/url_encode.rb
  2. require 'liquid'
  3. require 'uri'
  4. # Percent encoding for URI conforming to RFC 3986.
  5. # Ref: http://tools.ietf.org/html/rfc3986#page-12
  6. module URLEncode
  7. def url_encode(url)
  8. return URI.escape(url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
  9. end
  10. end
  11. Liquid::Template.register_filter(URLEncode)