]> khamidou — GitHub mirrors - kite.git/commitdiff
added filters
authorkarim hamidou <khamidou@gmail.com>
Sun, 13 Oct 2013 15:30:59 +0000 (17:30 +0200)
committerkarim hamidou <khamidou@gmail.com>
Sun, 13 Oct 2013 15:30:59 +0000 (17:30 +0200)
src/front/app/js/filters.js
src/front/test/unit/filtersSpec.js

index aa7d692dc2af8ce2493618d6887e494b44950e7a..cf72dbc7eb936914b5f34a4a2d081782e5ade4a3 100644 (file)
@@ -3,8 +3,26 @@
 /* Filters */
 
 angular.module('KiteMail.filters', []).
-  filter('interpolate', ['version', function(version) {
-    return function(text) {
-      return String(text).replace(/\%VERSION\%/mg, version);
-    }
-  }]);
+    filter('truncate', function() {
+            return function(text) {
+            return text.slice(0, 35) + "...";
+        }
+    }).
+    
+    /* takes a date object and returns a formatted object */
+    filter('formatDate', function() {
+        return function(date) {
+            var date2array = function(date) {
+                return (date+'').split(' ');
+            }
+
+            var today = date2array(new Date(Date.now()));
+            var da = date2array(date);
+
+            if(da[3] == today[3]) {
+                return da[1] + ", " + da[2];
+            } else {
+                return da[1] + ", " + da[2] + ", " + da[3];
+            }
+        }  
+    });
index fa5e9b9533a4c9662b87656449b362cc690a8445..c4170c944351fe133b3b60a4b6dbb4ee3b0e72b2 100644 (file)
@@ -3,17 +3,30 @@
 /* jasmine specs for filters go here */
 
 describe('filter', function() {
-  beforeEach(module('KiteMail.filters'));
+    beforeEach(module('KiteMail.filters'));
 
 
-  describe('interpolate', function() {
-    beforeEach(module(function($provide) {
-      $provide.value('version', 'TEST_VER');
+    describe('setup suite', function() {
+        beforeEach(module(function($provide) {
     }));
 
 
-    it('should replace VERSION', inject(function(interpolateFilter) {
-      expect(interpolateFilter('before %VERSION% after')).toEqual('before TEST_VER after');
+    it('should truncate text', inject(function(truncateFilter) {
+        var testStr = "This is a long string with a lot of chars";
+        var resStr = "This is a long string with a lot of" + "...";
+        expect(truncateFilter(testStr)).toEqual(resStr);
     }));
+
+    it('should format a date', inject(function(formatDateFilter) {
+        var date = new Date(2013, 9, 13);
+        expect(formatDateFilter(date)).toEqual("Oct, 13");
+    }));
+
+    it('should have the year in the string if the date is not from this year', inject(function(formatDateFilter) {
+        var date = new Date(2009, 9, 13);
+        expect(formatDateFilter(date)).toEqual("Oct, 13, 2009");
+    }));
+
+
   });
 });