Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitm@lovullo.com>2016-06-23 10:09:45 -0400
committerMike Gerwitz <gerwitm@lovullo.com>2016-06-24 15:57:10 -0400
commit4aa88fc08c3912f378875ae06c0b3f92c8da6607 (patch)
tree06a429006f7baa91013582e8d38b42c91edd6ae5
parentbc45b70644c51e3b35b6332449939254dee3627f (diff)
downloadliza-4aa88fc08c3912f378875ae06c0b3f92c8da6607.tar.gz
liza-4aa88fc08c3912f378875ae06c0b3f92c8da6607.tar.bz2
liza-4aa88fc08c3912f378875ae06c0b3f92c8da6607.zip
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.
-rw-r--r--src/validate/formatter/UnorderedList.js (renamed from src/validate/formatter/UnorderedListFormatter.js)12
-rw-r--r--test/validate/formatter/UnorderedListTest.js (renamed from test/validate/formatter/UnorderedListFormatterTest.js)21
2 files changed, 22 insertions, 11 deletions
diff --git a/src/validate/formatter/UnorderedListFormatter.js b/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 <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++ )
diff --git a/test/validate/formatter/UnorderedListFormatterTest.js b/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", "<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>'
+ );
} );