Skip to content

Instantly share code, notes, and snippets.

@MoOx
Created October 4, 2013 20:13
Show Gist options
  • Save MoOx/6832028 to your computer and use it in GitHub Desktop.
Save MoOx/6832028 to your computer and use it in GitHub Desktop.
module.exports = function getThemeConfig(grunt, prop) {
"use strict";
var happyplan = grunt.config.getRaw('happyplan')
, theme = happyplan
, finalValue = grunt.util.namespace.get(theme, grunt.config.getPropString(prop))
, value
, stupidityLimit = 20
, stupidityChecker = 0
while(theme.parent) {
if (!happyplan.theme[theme.parent]) {
grunt.fail.warn("Specified parent theme '" + theme.parent + "' doesn't exist")
}
theme = happyplan.theme[theme.parent]
value = grunt.util.namespace.get(theme, grunt.config.getPropString(prop))
if (finalValue instanceof Array) {
if (value instanceof Array) {
finalValue = value.concat(finalValue);
}
else {
finalValue.unshift(value);
}
}
else if (finalValue instanceof Object) {
if (value instanceof Object) {
for(i in value) {
if(value.hasOwnProperty(i)) {
theme[i] = custom[i]
}
}
finalValue = value.concat(finalValue);
}
else {
grunt.fail.warn("Can't append a simple typed value into an object, check your configuration to match parent one")
}
}
else {
if (value instanceof Array) {
value.push(finalValue);
}
else {
grunt.fail.warn("Can't append a simple typed value into an object or an array, check your configuration to match parent one")
}
}
// prevent stupid infinite loop
if (++stupidityChecker>stupidityLimit) {
grunt.fail.warn("Your theme tree is deeper than " + stupidityLimit + ", stupidity limit reached.")
}
}
return finalValue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment