Module: Sass::SCSS::RX

Included in:
Parser, Sass::Script::Lexer
Defined in:
/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/scss/rx.rb

Overview

A module containing regular expressions used for lexing tokens in an SCSS document. Most of these are taken from the CSS3 spec, although some have been modified for various reasons.

Constant Summary

Class Method Summary (collapse)

Class Method Details

+ (String) escape_ident(str)

Takes a string and returns a CSS identifier that will have the value of the given string.

Parameters:

  • str (String)

    The string to escape

Returns:

  • (String)

    The escaped string



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/scss/rx.rb', line 14

def self.escape_ident(str)
  return "" if str.empty?
  return "\\#{str}" if str == '-' || str == '_'
  out = ""
  value = str.dup
  out << value.slice!(0...1) if value =~ /^[-_]/
  if value[0...1] =~ NMSTART
    out << value.slice!(0...1)
  else
    out << escape_char(value.slice!(0...1))
  end
  out << value.gsub(/[^a-zA-Z0-9_-]/) {|c| escape_char c}
  out
end