Skip to content

Instantly share code, notes, and snippets.

@acdlite
Created March 10, 2014 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acdlite/9466131 to your computer and use it in GitHub Desktop.
Save acdlite/9466131 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.3.3)
// Compass (v1.0.0.alpha.18)
// Sassy Maps (v0.3.2)
// ----
@import "sassy-maps";
$__namespaces: ();
@mixin create-namespace($name) {
$__namespaces: map-set($__namespaces, $name, ());
}
@function namespace-set($name, $args...) {
$length: length($args);
$namespace: map-get($__namespaces, $name);
@if length($args) == 1 {
@if type-of(nth($args, 1)) == map {
$namespace: map-merge($namespace, nth($args, 1));
} @else {
@warn "Must pass either a map or 2 or more values."
}
}
@else {
$keys: nth($args, 1);
@if length($keys) == 1 {
$namespace: map-set($namespace, $args...);
} @else {
$namespace: map-set-deep($namespace, $args...);
}
}
$__namespaces: map-merge($__namespaces, ($name: $namespace));
@return $namespace;
}
@function namespace-get($name, $args...) {
$length: length($args);
$namespace: map-get($__namespaces, $name);
@if $length > 0 {
$keys: nth($args, 1);
@if length($keys) == 1 {
@return map-get($namespace, $args...);
} @else {
@return map-get-deep($namespace, $args...);
}
} @else {
@return $namespace;
}
}
@mixin namespace-set($name, $args...) {
$namespace: namespace-set($name, $args...);
}
///
@include create-namespace(color);
@function color($key) {
@return namespace-get(color, $key);
}
output {
@include namespace-set(color, primary, red);
foo: namespace-get(color, primary);
bar: color(primary);
}
output {
foo: red;
bar: red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment