Skip to content

Instantly share code, notes, and snippets.

@rowanmanning
Created June 16, 2012 18:06
Show Gist options
  • Save rowanmanning/2942116 to your computer and use it in GitHub Desktop.
Save rowanmanning/2942116 to your computer and use it in GitHub Desktop.
LESS Hackery
// Allows specifying default variables in LESS
// Some really sneaky shit that will shoot me in the foot if
// LESS changes too much...
@--lol: ~`"" + ( root._less = root._less || this )`;
@--lol: ~`"" + ( root.getLessVar = function (name) { return root._less[name] ? root._less[name].toJS() : '' } )`;
@--lol: ~`"" + ( root.getLessVarDefault = function (name, def) { return root.getLessVar(name) !== '' ? root.getLessVar(name) : root.getLessVar(def) } )`;
// Example:
//
// If we were to set the variable `@override-variable` here, then `@variable`
// would be set to that value instead.
//
@default-variable: 1200px;
@variable: ~`root.getLessVarDefault('override-variable', 'default-variable')`;
// There are problems with this approach, but they relate to problems with
// calculation. See https://github.com/cloudhead/less.js/issues/816 for
// more info.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment