/*
* Helma License Notice
*
* The contents of this file are subject to the Helma License
* Version 2.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://adele.helma.org/download/helma/license.txt
*
* Copyright 1998-2005 Helma Software. All Rights Reserved.
*
* $RCSfile: HopObject.js,v $
* $Author$
* $Revision$
* $Date$
*/
/**
* @fileoverview Adds useful methods to Helma's built-in HopObject prototype.
*
* To use this optional module, its repository needs to be added to the
* application, for example by calling app.addRepository('modules/core/HopObject.js')
*/
app.addRepository("modules/core/Number.js");
app.addRepository("modules/core/String.js");
/**
* Iterates over each child node of the HopObject.
* @external
* @memberof {HopObject}
* @param {Function} callback The callback function to be
* called for each child node. On every call the first
* argument of this function is set to the current value
* of the counter variable i
.
*/
HopObject.prototype.forEach = function(callback) {
if (!callback || callback instanceof Function == false) {
return;
}
for (var i=0; iparam
* argument:
*
* - param.none - not a single child node
* - param.one - exactly one child node
* - param.many - more than one child node
*
* @external
* @memberof {HopObject}
* @param {Object} param The default macro parameter
* @param {String} name The default name for a child node
*/
HopObject.prototype.size_macro = function(param, name) {
var EMPTYSTR = "";
var n = this.size();
if (name) {
var text;
var plural = name.endsWith("s") ? "es" : "s";
if (n > 0) {
if (n > 1) {
text = n + " " + name + plural;
} else {
text = (param.one !== null) ? param.one : "one " + name;
}
} else {
text = (param.none !== null) ? param.none : "no " + name + plural;
}
res.write(text);
} else {
res.write(n);
}
return;
};