Skip to content

Instantly share code, notes, and snippets.

@micahgodbolt
Created March 16, 2015 21:14
Show Gist options
  • Save micahgodbolt/bc0f7b8ad402225e4bb1 to your computer and use it in GitHub Desktop.
Save micahgodbolt/bc0f7b8ad402225e4bb1 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
//$namespace: null !default;
//$#{$namespace}variable: value;
// Want output like:
// $namespaced-variable: value;
// Reasoning:
// I'm building a scss/css framework
// and started realizing that variable
// names like $base-font-size might
// cause conflicts for people.
// I could just namespace all of my
// variables, but I personally hate
// namespacing in my own stuff so I
// want it to be optional. Would like
// a $namespace variable that is set
// to null !default
// If someone wants a namespace on
// all the variables, they just change
// that variable to a real value and
// everything has a namespace now.
// You can see a similar approach to
// namespacing selectors here:
// https://github.com/ScalesCSS/base-forms/blob/master/_forms.scss
// line 12 and line 41
// If I can do this with maps, I'm
// missing how.
$my-framework-vars: (
base-font-size: 16px,
base-font-color: #333,
);
@function get-var($var) {
@return map-get($my-framework-vars, $var)
}
body {
font-size: get-var(base-font-size);
color: get-var(base-font-color);
}
body {
font-size: 16px;
color: #333;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment