/* * Copyright 2011 eBay Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 'use strict'; var escapeXml = require('raptor-util/escapeXml'); var escapeXmlAttr = escapeXml.attr; var runtime = require('./'); // Circular dependency, but that is okay var extend = require('raptor-util/extend'); var attr = require('raptor-util/attr'); var attrs = require('raptor-util/attrs'); var arrayFromArguments = require('raptor-util/arrayFromArguments'); var logger = require('raptor-logging').logger(module); var isArray = Array.isArray; function notEmpty(o) { if (o == null) { return false; } else if (Array.isArray(o)) { return !!o.length; } else if (o === '') { return false; } return true; } function createDeferredRenderer(handler) { function deferredRenderer(input, out) { deferredRenderer.renderer(input, out); } // This is the initial function that will do the rendering. We replace // the renderer with the actual renderer func on the first render deferredRenderer.renderer = function(input, out) { var rendererFunc = handler.renderer || handler.render; if (typeof rendererFunc !== 'function') { throw new Error('Invalid tag handler: ' + handler); } // Use the actual renderer from now on deferredRenderer.renderer = rendererFunc; rendererFunc(input, out); }; return deferredRenderer; } var WARNED_INVOKE_BODY = 0; module.exports = { /** * Internal helper method to prevent null/undefined from being written out * when writing text that resolves to null/undefined * @private */ s: function(str) { return (str == null) ? '' : str; }, /** * Internal helper method to handle loops with a status variable * @private */ fv: function (array, callback) { if (!array) { return; } if (!array.forEach) { array = [array]; } var i = 0; var len = array.length; var loopStatus = { getLength: function () { return len; }, isLast: function () { return i === len - 1; }, isFirst: function () { return i === 0; }, getIndex: function () { return i; } }; for (; i < len; i++) { var o = array[i]; callback(o, loopStatus); } }, /** * Internal helper method to handle loops without a status variable * @private */ f: function forEach(array, callback) { if (isArray(array)) { for (var i=0; i