From 65fdedd27c8ffd3d2832c14e0b51a0c66e62b03c Mon Sep 17 00:00:00 2001 From: kbparagua Date: Tue, 19 Feb 2013 21:30:33 +0800 Subject: [PATCH] Working with filters --- vendor/assets/javascripts/paloma_core.js | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/vendor/assets/javascripts/paloma_core.js b/vendor/assets/javascripts/paloma_core.js index ae5ef28..f4e9176 100644 --- a/vendor/assets/javascripts/paloma_core.js +++ b/vendor/assets/javascripts/paloma_core.js @@ -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]; +};