mirror of
https://github.com/kbparagua/paloma
synced 2023-03-27 23:21:17 -04:00
Working with filters
This commit is contained in:
parent
f4d353f911
commit
65fdedd27c
1 changed files with 50 additions and 0 deletions
50
vendor/assets/javascripts/paloma_core.js
vendored
50
vendor/assets/javascripts/paloma_core.js
vendored
|
@ -29,3 +29,53 @@ Paloma.execute = function(controller, action, params){
|
|||
|
||||
callback(params);
|
||||
};
|
||||
|
||||
|
||||
Paloma._filters = {};
|
||||
|
||||
// Filter class
|
||||
Paloma.Filter = function(name){
|
||||
this.name = name;
|
||||
this.type = undefined;
|
||||
this.only = undefined;
|
||||
this.func = undefined;
|
||||
};
|
||||
|
||||
|
||||
Paloma.Filter.prototype.before = function(only, func){
|
||||
this.type = 'before';
|
||||
this._setProperties(only, func);
|
||||
};
|
||||
|
||||
|
||||
Paloma.Filter.prototype.after = function(only, func){
|
||||
this.type = 'after';
|
||||
this._setProperty(only, func);
|
||||
};
|
||||
|
||||
|
||||
Paloma.Filter.prototype.around = function(only, func){
|
||||
this.type = 'around';
|
||||
this._setProperty(only, func);
|
||||
};
|
||||
|
||||
|
||||
var types = ['before', 'after', 'around'];
|
||||
for (var i = 0, n = types.length; i < n; i++)}{
|
||||
var type = types[i];
|
||||
Paloma.Filter.prototype[type + '_all'] = function(){};
|
||||
Paloma.Filter.prototype['except_' + type] = function(){};
|
||||
}
|
||||
|
||||
|
||||
Paloma.Filter.prototype._setProperties = function(only, func){
|
||||
this.only = only;
|
||||
this.func = func;
|
||||
};
|
||||
|
||||
|
||||
// API
|
||||
Paloma.filter = function(namespace_or_controller){
|
||||
Paloma._filters[namespace_or_controller] = new Paloma.Filter(namespace_or_controller);
|
||||
return Paloma._filters[namespace_or_controller];
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue