Module: Sass::Script::Value::String::Dashy

Included in:
Sass::Script::Value::String
Defined in:
lib/sass/script/value/string/dashy.rb

Instance Method Summary collapse

Instance Method Details

#to_s(*sig) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sass/script/value/string/dashy.rb', line 4

def to_s *sig
  return super unless :selector === type
  selector = self.value.dup

  # Escape...
  # 
  # ...decimals:
  # 
  selector.gsub! %r{ (?<=[0-9])                             (?=[.][0-9]) }x, '\\' # Escape any unescaped decimal points...
  selector.gsub! %r{ (?<=[0-9]) ( [\\][.] [0-9]{2} ) [0-9]+              }x, '\1' # Remove extra precision (> 2).
  selector.gsub! %r{ (?<=[0-9]) ( [\\][.] [0-9]*?  )   [0]+   (?=[^0-9]) }x, '\1' # Remove trailing zeroes.
  selector.gsub! %r{ (?<=[0-9]) ( [\\][.]          )          (?=[^0-9]) }x, ''   # Remove trailing dot.
  #
  # ...punctuation:
  #
  selector.gsub! %r{ (?<!\\) (?=[/%$?!]) }x, "\\" # Escape any unescaped punctuation...
  selector
end