Method: Sass::SCSS::RX.escape_ident
- Defined in:
- lib/sass/scss/rx.rb
.escape_ident(str) ⇒ String
Takes a string and returns a CSS identifier that will have the value of the given string.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sass/scss/rx.rb', line 13
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}
return out
end
|