From 23a7d9d54070b8dc4f1b556169055e06ddd35336 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 18 Jan 2011 23:47:58 -0500 Subject: [PATCH] Began adding member_builder --- lib/member_builder.js | 47 +++++++++++++++++++++++++++++ test/test-member_builder-prop.js | 51 ++++++++++++++++++++++++++++++++ tools/combine | 2 +- 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 lib/member_builder.js create mode 100644 test/test-member_builder-prop.js diff --git a/lib/member_builder.js b/lib/member_builder.js new file mode 100644 index 0000000..f6b75ee --- /dev/null +++ b/lib/member_builder.js @@ -0,0 +1,47 @@ +/** + * Handles building members (properties, methods) + * + * Copyright (C) 2010 Mike Gerwitz + * + * This file is part of ease.js. + * + * ease.js is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * @author Mike Gerwitz + * @package core + */ + + +/** + * Copies a property to the appropriate member prototype, depending on + * visibility, and assigns necessary metadata from keywords + * + * @param {{public: Object, protected: Object, private: Object}} members + * + * @param {Object} meta metadata container + * @param {string} name property name + * @param {*} value property value + * + * @param {Object.} keywords parsed keywords + * + * @return {undefined} + */ +exports.buildProp = function( members, meta, name, value, keywords ) +{ + if ( keywords[ 'public' ] ) + { + members[ 'public' ][ name ] = value; + } +}; + diff --git a/test/test-member_builder-prop.js b/test/test-member_builder-prop.js new file mode 100644 index 0000000..321d9db --- /dev/null +++ b/test/test-member_builder-prop.js @@ -0,0 +1,51 @@ +/** + * Tests property builder + * + * Copyright (C) 2010 Mike Gerwitz + * + * This file is part of ease.js. + * + * ease.js is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * @author Mike Gerwitz + * @package test + */ + +var common = require( './common' ), + assert = require( 'assert' ), + buildProp = common.require( 'member_builder' ).buildProp + + // member visibility types are quoted because they are reserved keywords + members = { 'public': {}, 'protected': {}, 'private': {} }, + meta = {}, + + // stub values + name = 'foo', + value = 'bar' +; + + +( function testRecognizesPublicProperty() +{ + var keywords = { 'public': true }, + result = buildProp( members, meta, name, value, keywords ) + ; + + assert.equal( + members[ 'public' ][ name ], + value, + "Public properties are copied to the public member prototype" + ); +} )(); + diff --git a/tools/combine b/tools/combine index 70b09a8..dfdbd47 100755 --- a/tools/combine +++ b/tools/combine @@ -28,7 +28,7 @@ TPL_VAR='/**{CONTENT}**/' RMTRAIL="$PATH_TOOLS/rmtrail" # order matters -CAT_MODULES="prop_parser util class interface" +CAT_MODULES="prop_parser util member_builder class interface" ## # Output template header