Sha256: 0b04d1e6a724a81db7e570e4a1e0f4ffbc40d776cb992c917e1b33e7936ada69
Contents?: true
Size: 1.11 KB
Versions: 14
Compression:
Stored size: 1.11 KB
Contents
# Borrow from ERB Source # ERB::Util module Slight module Utils public # A utility method for escaping HTML tag characters in _s_. # # require "erb" # include ERB::Util # # puts html_escape("is a > 0 & a < 10?") # # _Generates_ # # is a > 0 & a < 10? # # [Slight] => Add: gsub(/[[:blank:]]/," ") to support space. def html_escape(s) s.to_s.gsub(/&/, "&").gsub(/[[:blank:]]/," ").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<") end module_function :html_escape # A utility method for encoding the String _s_ as a URL. # # require "erb" # include ERB::Util # # puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide") # # _Generates_ # # Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide # def url_encode(s) s.to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) } end module_function :url_encode end end
Version data entries
14 entries across 14 versions & 1 rubygems