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 &gt; 0 &amp; a &lt; 10?
      #
      # [Slight] => Add: gsub(/[[:blank:]]/,"&nbsp;") to support space.
      def html_escape(s)
        s.to_s.gsub(/&/, "&amp;").gsub(/[[:blank:]]/,"&nbsp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
      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

Version Path
slight-lang-1.3.6 lib/slight/utils.rb
slight-lang-1.3.5 lib/slight/utils.rb
slight-lang-1.3.4 lib/slight/utils.rb
slight-lang-1.3.3 lib/slight/utils.rb
slight-lang-1.3.2 lib/slight/utils.rb
slight-lang-1.3.1 lib/slight/utils.rb
slight-lang-1.3.0 lib/slight/utils.rb
slight-lang-1.2.3 lib/slight/utils.rb
slight-lang-1.2.1.3 lib/slight/utils.rb
slight-lang-1.2.1.2 lib/slight/utils.rb
slight-lang-1.2.1.1 lib/slight/utils.rb
slight-lang-1.1.6 lib/slight/utils.rb
slight-lang-1.2.0 lib/slight/utils.rb
slight-lang-1.0.1 lib/slight/utils.rb