Skip to content

Commit

Permalink
new method K.Plugin.templatesByPlaceholder
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanocudini committed Apr 1, 2018
1 parent caaff4b commit 1c79019
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ keplerjs:robots
keplerjs:routing

keplerjs:wunderground
keplerjs:googlemaps
keplerjs:googlemaps
30 changes: 30 additions & 0 deletions packages/core/modules/Plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
core module for define and manage Kepler plugins
*/

//TODO add new field 'replace'

Kepler.plugins = {};

Kepler.Plugin = function(plugin) {
Expand Down Expand Up @@ -39,6 +41,34 @@ Kepler.Plugin = function(plugin) {
console.warn("Plugin: require name", plugin)
};

Kepler.Plugin.templatesByPlaceholder = function(placeholderName, placeholderData) {
var tmpls = [];

if(!placeholderName) return tmpls;

for(var parentName in K.templates) {

if(parentName === placeholderName) {

K.templates[parentName] = _.sortBy(K.templates[parentName],'order');

_.chain(K.templates[parentName])
.pluck('name')
.each(function(name) {
if(Template[name]) {
tmpls.push({
pluginTemplate: name,
pluginData: placeholderData
});
}
});
}
}

return tmpls;
};


if(Meteor.isServer) {
Meteor.startup(function() {
console.log('Plugins: ', _.keys(K.plugins).join(','));
Expand Down
30 changes: 2 additions & 28 deletions packages/ui/client/views/pluginsTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,9 @@
{{> pluginsTemplate name='panelPlace'}}
*/

Template.pluginsTemplate.helpers({
templates: function() {

var self = this,
tmpls = [];

if(!self.name) return tmpls;

_.each(K.templates, function(pluginTmpls, parentName) {

if(parentName === self.name) {

var pluginData = Template.parentData();

//TODO replace field

pluginTmpls = _.sortBy(pluginTmpls,'order');
pluginTmpls = _.pluck(pluginTmpls,'name');

_.each(pluginTmpls, function(pluginTemplate) {
if(Template[pluginTemplate]) {
tmpls.push({
pluginTemplate: pluginTemplate,
pluginData: pluginData
});
}
});
}
});
return tmpls;
return K.Plugin.templatesByPlaceholder(this.name, Template.parentData());
}
});

0 comments on commit 1c79019

Please sign in to comment.