Skip to content

Commit

Permalink
Merge pull request #23 from cgkineo/issue/#22
Browse files Browse the repository at this point in the history
Fix for #22
  • Loading branch information
oliverfoster authored May 21, 2019
2 parents af8d6fb + 2d8b4bb commit dd085ce
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 dd085ce

Please sign in to comment.