Skip to content

Instantly share code, notes, and snippets.

@ff6347
Forked from jonsuh/url_encode.rb
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save ff6347/b9936b2892065272c1b6 to your computer and use it in GitHub Desktop.

Select an option

Save ff6347/b9936b2892065272c1b6 to your computer and use it in GitHub Desktop.
# _plugins/url_encode.rb
require 'liquid'
require 'uri'
# Percent encoding for URI conforming to RFC 3986.
# Ref: http://tools.ietf.org/html/rfc3986#page-12
module URLEncode
def url_encode(url)
return URI.escape(url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end
end
Liquid::Template.register_filter(URLEncode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment