Skip to content

Instantly share code, notes, and snippets.

@chriseppstein
Forked from Snugug/Sass.scss
Last active December 11, 2015 12:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriseppstein/4599879 to your computer and use it in GitHub Desktop.
Save chriseppstein/4599879 to your computer and use it in GitHub Desktop.
@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