Module: Sass::Shared
- Extended by:
- Shared
- Included in:
- Shared
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/shared.rb
Overview
This module contains functionality that’s shared between Haml and Sass.
Instance Method Summary (collapse)
- - ((String, String)) balance(scanner, start, finish, count = 0)
Moves a scanner through a balanced pair of characters.
- - (String) handle_interpolation(str) {|scan| ... }
Scans through a string looking for the interoplation-opening
#{
and, when it’s found, yields the scanner to the calling code so it can handle it properly. The scanner will have any backslashes immediately in front of the#{
as the second capture group (scan[2]
), and the text prior to that as the first (scan[1]
).. - - (String) human_indentation(indentation, was = false)
Formats a string for use in error messages about indentation.
Instance Method Details
- ((String, String)) balance(scanner, start, finish, count = 0)
Moves a scanner through a balanced pair of characters. For example:
Foo (Bar (Baz bang) bop) (Bang (bop bip))
^ ^
from to
39 40 41 42 43 44 45 46 47 48 49 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/shared.rb', line 39
def balance(scanner, start, finish, count = 0)
str = ''
scanner = Sass::Util::MultibyteStringScanner.new(scanner) unless scanner.is_a? StringScanner
regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
while scanner.scan(regexp)
str << scanner.matched
count += 1 if scanner.matched[-1] == start
count -= 1 if scanner.matched[-1] == finish
return [str, scanner.rest] if count == 0
end
end |
- (String) handle_interpolation(str) {|scan| ... }
Scans through a string looking for the interoplation-opening #{
and, when it’s found, yields the scanner to the calling code so it can handle it properly.
The scanner will have any backslashes immediately in front of the #{
as the second capture group (scan[2]
), and the text prior to that as the first (scan[1]
).
16 17 18 19 20 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/shared.rb', line 16
def handle_interpolation(str)
scan = Sass::Util::MultibyteStringScanner.new(str)
yield scan while scan.scan(/(.*?)(\\*)\#\{/m)
scan.rest
end |
- (String) human_indentation(indentation, was = false)
Formats a string for use in error messages about indentation.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/shared.rb', line 57
def human_indentation(indentation, was = false)
if !indentation.include?(?\t)
noun = 'space'
elsif !indentation.include?(?\s)
noun = 'tab'
else
return indentation.inspect + (was ? ' was' : '')
end
singular = indentation.length == 1
if was
was = singular ? ' was' : ' were'
else
was = ''
end
"#{indentation.length} #{noun}#{'s' unless singular}#{was}"
end |