Skip to content

Commit

Permalink
Fix for #22
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-steele committed Mar 22, 2019
1 parent af8d6fb commit 2d8b4bb
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions patch/2_2_1grunt/grunt/tasks/schema-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,40 @@ module.exports = function(grunt) {

if (!currentPluginName || !currentSchemaJson.globals) return;

//iterate through schema globals attributes
_.each(currentSchemaJson.globals, function(item, attributeName) {
//translate schema attribute into globals object
var pluginTypeDefaults = globalsObject['_'+ pluginType] = globalsObject['_'+ pluginType] || {};
var pluginDefaults = pluginTypeDefaults['_' + currentPluginName] = pluginTypeDefaults['_' + currentPluginName] || {};

pluginDefaults[attributeName] = item['default'];
});
var pluginTypeDefaults = globalsObject['_'+ pluginType] = globalsObject['_'+ pluginType] || {};
var pluginDefaults = pluginTypeDefaults['_' + currentPluginName] = pluginTypeDefaults['_' + currentPluginName] || {};

copyToDefaults(currentSchemaJson.globals, pluginDefaults);

function copyToDefaults(obj, target) {
_.each(obj, function(val, key) {
if (val['type'] == 'array') {

if (val.hasOwnProperty('default')) {
target[key] = val['default'];
}

else if (val['items'] && val['items']['type'] == 'object') {
target[key] = [{}];
copyToDefaults(val['items']['properties'], target[key][0]);
}

else {
console.log('new array case for', key);
}

} else if (val['type'] == 'object') {

target[key] = {};
copyToDefaults(val['properties'], target[key]);

} else {

target[key] = val['default'];

}
});
}
});
});

Expand Down

0 comments on commit 2d8b4bb

Please sign in to comment.