Skip to content

Instantly share code, notes, and snippets.

@chriseppstein chriseppstein/Sass.scss forked from Snugug/Sass.scss
Last active Dec 11, 2015

Embed
What would you like to do?
@function add-grid($grid-definition) {
$grid-split: split_string($grid-definition, 'at');
$number: to-number(nth($grid-split, 2));
@debug $number;
@debug type-of($number);
@return $number;
}
#foo {
$width: add-grid("5 at 500px");
@if ($width > 500px) {
width: 100%;
}
@else {
width: 80%;
}
}
module Sass::Script::Functions
def split_string(string, key)
items = string.value.split(/\s+#{Regexp.escape(key.value)}\s+/)
if items.count == 1
Sass::Script::Bool.new(false)
else
Sass::Script::List.new(items.map{|i| Sass::Script::String.new(i)}, :comma)
end
end
def to_number(string)
result = Sass::Script::Parser.parse(string.value, string.line || 0, 0)
case result
when Sass::Script::Number
result
else
raise Sass::SyntaxError, "#{string.to_sass} is not a number"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.