/* * 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. */ define.Class( 'raptor/templating/compiler/Taglib', ['raptor'], function(raptor, require) { "use strict"; var Taglib = function() { this.uri = null; this.shortName = null; this.aliases = []; this.tags = {}; this.textTransformers = []; this.attributeMap = {}; this.functions = []; this.helperObject = null; this.patternAttributes = []; }; Taglib.prototype = { addAttribute: function(attribute) { if (attribute.uri) { throw raptor.createError(new Error('"uri" is not allowed for taglib attributes')); } if (attribute.name) { this.attributeMap[attribute.name] = attribute; } else { this.patternAttributes.push(attribute); } }, getAttribute: function(name) { var attribute = this.attributeMap[name]; if (!attribute) { for (var i=0, len=this.patternAttributes.length; i]"; }, forEachAttribute: function(callback, thisObj) { raptor.forEachEntry(this.attributeMap, function(attrName, attr) { callback.call(thisObj, attr); }); }, addNestedVariable: function(nestedVariable) { var key = nestedVariable.nameFromAttribute ? 'attr:' + nestedVariable.nameFromAttribute : nestedVariable.name; this.nestedVariables[key] = nestedVariable; }, addImportedVariable: function(importedVariable) { var key = importedVariable.targetProperty; this.importedVariables[key] = importedVariable; }, addTransformer: function(transformer) { var key = transformer.className; this.transformers[key] = transformer; }, addStaticProperty: function(prop) { var key = prop.name; this.staticProperties[key] = prop; } }; return Tag; }); Taglib.Attribute = define.Class(function() { var Attribute = function() { this.name = null; this.uri = null; this.type = null; this.required = false; this.type = "string"; this.allowExpressions = true; }; Attribute.prototype = { }; return Attribute; }); Taglib.Property = define.Class(function() { var Property = function() { this.name = null; this.type = "string"; this.value = undefined; }; Property.prototype = { }; return Property; }); Taglib.NestedVariable = define.Class(function() { var NestedVariable = function() { this.name = null; }; NestedVariable.prototype = { }; return NestedVariable; }); Taglib.ImportedVariable = define.Class(function() { var ImportedVariable = function() { this.targetProperty = null; this.expression = null; }; ImportedVariable.prototype = { }; return ImportedVariable; }); Taglib.Transformer = define.Class(function() { var uniqueId = 0; var Transformer = function() { this.id = uniqueId++; this.tag = null; this.className = null; this.after = null; this.before = null; this.instance = null; this.properties = {}; }; Transformer.prototype = { getInstance: function() { if (!this.className) { throw raptor.createError(new Error("Transformer class not defined for tag transformer (tag=" + this.tag + ")")); } if (!this.instance) { var Clazz = require(this.className); if (Clazz.process) { return Clazz; } this.instance = new Clazz(); this.instance.id = this.id; } return this.instance; }, toString: function() { return '[Taglib.Transformer: ' + this.className + ']'; } }; return Transformer; }); Taglib.Function = define.Class(function() { var Function = function() { this.name = null; this.functionClass = null; this.bindToContext = false; }; Function.prototype = { }; return Function; }); Taglib.HelperObject = define.Class(function() { var HelperObject = function() { this.className = null; this.moduleName = null; }; HelperObject.prototype = { }; return HelperObject; }); return Taglib; });