if( isCustomTag ) {
section.startSubSection();
} else if(textContentOnlyTag[tagName]) {
state.textContentOnly = new TextSectionBuilder();
}
}
state.node =null;
},
close: function( tagName ) {
var matchedNamespace = namespaces[tagName];
if (matchedNamespace ) {
state.namespaceStack.pop();
}
var isCustomTag = viewCallbacks.tag(tagName),
renderer;
if( isCustomTag ) {
renderer = section.endSubSectionAndReturnRenderer();
}
if(textContentOnlyTag[tagName]) {
section.last().add(state.textContentOnly.compile(copyState()));
state.textContentOnly = null;
}
var oldNode = section.pop();
if( isCustomTag ) {
addAttributesCallback(oldNode, function(scope, options, parentNodeList){
viewCallbacks.tagHandler(this,tagName, {
scope: scope,
options: options,
subtemplate: renderer,
templateType: "stache",
parentNodeList: parentNodeList
});
});
}
state.sectionElementStack.pop();
},
attrStart: function(attrName){
if(state.node.section) {
state.node.section.add(attrName+"=\"");
} else {
state.attr = {
name: attrName,
value: ""
};
}
},
attrEnd: function(attrName){
if(state.node.section) {
state.node.section.add("\" ");
} else {
if(!state.node.attrs) {
state.node.attrs = {};
}
state.node.attrs[state.attr.name] =
state.attr.section ? state.attr.section.compile(copyState()) : state.attr.value;
var attrCallback = viewCallbacks.attr(attrName);
if(attrCallback) {
if( !state.node.attributes ) {
state.node.attributes = [];
}
state.node.attributes.push(function(scope, options, nodeList){
attrCallback(this,{
attributeName: attrName,
scope: scope,
options: options,
nodeList: nodeList
});
});
}
state.attr = null;
}
},
attrValue: function(value){
var section = state.node.section || state.attr.section;
if(section){
section.add(value);
} else {
state.attr.value += value;
}
},
chars: function( text ) {
(state.textContentOnly || section).add(text);
},
special: function( text ){
var firstAndText = mustacheCore.splitModeFromExpression(text, state),
mode = firstAndText.mode,
expression = firstAndText.expression;
if(expression === "else") {
var inverseSection;
if(state.attr && state.attr.section) {
inverseSection = state.attr.section;
} else if(state.node && state.node.section ) {
inverseSection = state.node.section;
} else {
inverseSection = state.textContentOnly || section;
}
inverseSection.inverse();
return;
}
if(mode === "!") {
return;
}
if(state.node && state.node.section) {
makeRendererAndUpdateSection(state.node.section, mode, expression);
if(state.node.section.subSectionDepth() === 0){
state.node.attributes.push( state.node.section.compile(copyState()) );
delete state.node.section;
}
}