From 4aa88fc08c3912f378875ae06c0b3f92c8da6607 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 23 Jun 2016 10:09:45 -0400 Subject: [PATCH] UnorderedList{Formatter=>} now a trait This adds a great deal of flexibility through composition via trait stacking. * src/validate/formatter/UnorderedList.js: Renamed from UnorderedListFormatter; now a trait. * test/validate/formatter/UnorderedListTest.js: Renamed from UnorderedListFormatterTest and adjusted to instantiate trait. --- ...deredListFormatter.js => UnorderedList.js} | 12 +++++------ ...tFormatterTest.js => UnorderedListTest.js} | 21 ++++++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) rename src/validate/formatter/{UnorderedListFormatter.js => UnorderedList.js} (90%) rename test/validate/formatter/{UnorderedListFormatterTest.js => UnorderedListTest.js} (89%) diff --git a/src/validate/formatter/UnorderedListFormatter.js b/src/validate/formatter/UnorderedList.js similarity index 90% rename from src/validate/formatter/UnorderedListFormatter.js rename to src/validate/formatter/UnorderedList.js index 6515f62..06625e4 100644 --- a/src/validate/formatter/UnorderedListFormatter.js +++ b/src/validate/formatter/UnorderedList.js @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -var Class = require( 'easejs' ).Class, +var Trait = require( 'easejs' ).Trait, ValidatorFormatter = require( '../ValidatorFormatter' ); @@ -27,7 +27,7 @@ var Class = require( 'easejs' ).Class, * Formats delimited items as an HTML unordered list, storing as a * delimited string. */ -module.exports = Class( 'UnorderedListFormatter' ) +module.exports = Trait( 'UnorderedList' ) .implement( ValidatorFormatter ) .extend( { @@ -41,12 +41,12 @@ module.exports = Class( 'UnorderedListFormatter' ) * * @return {string} formatted string */ - 'public parse': function( data ) + 'virtual abstract override public parse': function( data ) { // strip HTMl elements before processing (closing li tag // is translated into a semicolon) return this.getParts( - data + this.__super( data ) .replace( /<\/li>/g, ';' ) .replace( /\s*<.*?>\s*/g, '' ) ).join( '; ' ); @@ -67,9 +67,9 @@ module.exports = Class( 'UnorderedListFormatter' ) * * @return {string} data formatted for display */ - 'public retrieve': function( data ) + 'virtual abstract override public retrieve': function( data ) { - var parts = this.getParts( data ), + var parts = this.getParts( this.__super( data ) ), items = ''; for ( var i = 0; i < parts.length; i++ ) diff --git a/test/validate/formatter/UnorderedListFormatterTest.js b/test/validate/formatter/UnorderedListTest.js similarity index 89% rename from test/validate/formatter/UnorderedListFormatterTest.js rename to test/validate/formatter/UnorderedListTest.js index 3f3a037..6802239 100644 --- a/test/validate/formatter/UnorderedListFormatterTest.js +++ b/test/validate/formatter/UnorderedListTest.js @@ -20,14 +20,15 @@ */ -var liza = require( '../../../' ), - Sut = liza.validate.formatter.UnorderedListFormatter, - testValidate = require( './common' ).testValidate; +var liza = require( '../../../' ), + Sut = liza.validate.formatter.UnorderedList, + EchoFormatter = liza.validate.formatter.EchoFormatter, + common = require( './common' ); -describe( 'UnorderedListFormatter', function() +describe( 'UnorderedList', function() { - testValidate( Sut(), { + common.testValidate( EchoFormatter.use( Sut )(), { "": [ "", "" ], "no semi": [ "no semi", "" ], @@ -138,4 +139,14 @@ describe( 'UnorderedListFormatter', function() "" ], } ); + + + common.testMixin( + EchoFormatter, + Sut, + 'foo;', + 'bar', + 'foo; bar', + '' + ); } );