Sha256: 27339e2d53a42c55c4cc5020edede638f1c5c0633d0f9c30d260dc047680fe38

Contents?: true

Size: 1020 Bytes

Versions: 27

Compression:

Stored size: 1020 Bytes

Contents

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

    # Pattern matching for html escape characters
    ESCAPE_HTML_PATTERN = Regexp.union(*ESCAPE_HTML.keys)

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

    # @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 ESCAPE_HTML_PATTERN, ESCAPE_HTML
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
opulent-1.8.5 lib/opulent/utils.rb
opulent-1.8.4 lib/opulent/utils.rb
opulent-1.8.3 lib/opulent/utils.rb
opulent-1.8.2 lib/opulent/utils.rb
opulent-1.8.1 lib/opulent/utils.rb
opulent-1.8.0 lib/opulent/utils.rb
opulent-1.7.11 lib/opulent/utils.rb
opulent-1.7.10 lib/opulent/utils.rb
opulent-1.7.9 lib/opulent/utils.rb
opulent-1.7.8 lib/opulent/utils.rb
opulent-1.7.7 lib/opulent/utils.rb
opulent-1.7.6 lib/opulent/utils.rb
opulent-1.7.5 lib/opulent/utils.rb
opulent-1.7.4 lib/opulent/utils.rb
opulent-1.7.3 lib/opulent/utils.rb
opulent-1.7.2 lib/opulent/utils.rb
opulent-1.7.1 lib/opulent/utils.rb
opulent-1.7.0 lib/opulent/utils.rb
opulent-1.6.9 lib/opulent/utils.rb
opulent-1.6.8 lib/opulent/utils.rb