1
0
Fork 0

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.
master
Mike Gerwitz 2016-06-23 10:09:45 -04:00
parent bc45b70644
commit 4aa88fc08c
2 changed files with 22 additions and 11 deletions

View File

@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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++ )

View File

@ -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", "<ul><li>no semi</li></ul>" ],
@ -138,4 +139,14 @@ describe( 'UnorderedListFormatter', function()
"<ul><li>semi</li><li>colon</li></ul>"
],
} );
common.testMixin(
EchoFormatter,
Sut,
'foo;',
'bar',
'foo; bar',
'<ul><li>foo</li><li>bar</li></ul>'
);
} );