Sha256: 4a0e5cd3cfbf7fe082f528e400917130ab339f86ff9fe4355461524593fd68e7

Contents?: true

Size: 1001 Bytes

Versions: 11

Compression:

Stored size: 1001 Bytes

Contents

# @Opulent
module Opulent
  module Utils
    # Used by escape_html
    #
    EscapeHTML = {
      '&'  => '&',
      '"'  => '"',
      '\'' => ''',
      '<'  => '&lt;',
      '>'  => '&gt;'
    }.freeze

    # Pattern matching for html escape characters
    EscapeHTMLPattern = Regexp.union(*EscapeHTML.keys)

    # Ruby interpolation pattern
    InterpolationPattern = /\#\{([^}]+)\}/

    # @Utils
    class << self
      if defined?(EscapeUtils)
        # Returns an escaped copy of `html`.
        #
        # @param html [String] The string to escape
        # @return [String] The escaped string
        def escape(html)
          EscapeUtils.escape_html html.to_s.chomp, false
        end
      else
        # Returns an escaped copy of `html`.
        #
        # @param html [String] The string to escape
        # @return [String] The escaped string
        def escape(html)
          html.to_s.chomp.gsub EscapeHTMLPattern, EscapeHTML
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
opulent-1.5.5 lib/opulent/utils.rb
opulent-1.5.4 lib/opulent/utils.rb
opulent-1.5.3 lib/opulent/utils.rb
opulent-1.5.2 lib/opulent/utils.rb
opulent-1.5.1 lib/opulent/utils.rb
opulent-1.5.0 lib/opulent/utils.rb
opulent-1.4.8 lib/opulent/utils.rb
opulent-1.4.7 lib/opulent/utils.rb
opulent-1.4.6 lib/opulent/utils.rb
opulent-1.4.5 lib/opulent/utils.rb
opulent-1.4.3 lib/opulent/utils.rb