Sha256: a3b026c366b0cce6e2badf4159139b4d66d5f7b6482b8329750f03d16cbfa6df

Contents?: true

Size: 814 Bytes

Versions: 3

Compression:

Stored size: 814 Bytes

Contents

# encoding: UTF-8


module Spontaneous
  module Extensions
    module String
      def /(path)
        File.join(self, path.to_s)
      end

      HTML_ESCAPE_TABLE = {
        '&' => '&',
        '<' => '&lt;',
        '>' => '&gt;',
        '"' => '&quot;',
        "'" => '&#039;',
      }

      def escape_html
        self.gsub(%r{[#{HTML_ESCAPE_TABLE.keys.join}]}) { |s| HTML_ESCAPE_TABLE[s] }
      end

      JS_ESCAPE_MAP = {
        '\\' => '\\\\',
        '</' => '<\/',
        "\r\n" => '\n',
        "\n" => '\n',
        "\r" => '\n',
        '"' => '\\"',
        "'" => "\\'"
      } unless defined?(JS_ESCAPE_MAP)

      def escape_js
        self.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { JS_ESCAPE_MAP[$1] }
      end

    end
  end
end


class String
  include Spontaneous::Extensions::String
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spontaneous-0.2.0.alpha2 lib/spontaneous/extensions/string.rb
spontaneous-0.2.0.alpha1 lib/spontaneous/extensions/string.rb
spontaneous-0.1.0.alpha1 lib/spontaneous/extensions/string.rb