/* 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];
+ }
+ }
+ });
/* 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");
+ }));
+
+
});
});