Search in sources :

Example 1 with TagInTag

use of cn.bran.japid.compiler.Tag.TagInTag in project japid42 by branaway.

the class JapidAbstractCompiler method pushToStack.

/**
	 * @param tag
	 */
protected void pushToStack(Tag tag) {
    // if calling inside a TagInTag tag, put it in the scope
    TagInTag tagtagf = getTagInTag();
    if (tagtagf != null) {
        if (tag instanceof TagInTag) {
            throw new JapidCompilationException(template, tag.startLine, "Syntax error: def/set tag cannot be nested in another def/set tag.");
        }
        if (!(tag instanceof TagIf))
            tagtagf.tags.add(tag);
    }
    tagsStackShadow.push(tag);
    if (!(tag instanceof TagIf))
        tagsStack.push(tag);
}
Also used : TagInTag(cn.bran.japid.compiler.Tag.TagInTag) TagIf(cn.bran.japid.compiler.Tag.TagIf)

Example 2 with TagInTag

use of cn.bran.japid.compiler.Tag.TagInTag in project Japid by branaway.

the class JapidAbstractCompiler method pushToStack.

/**
	 * @param tag
	 */
protected void pushToStack(Tag tag) {
    // if calling inside a TagInTag tag, put it in the scope
    TagInTag tagtagf = getTagInTag();
    if (tagtagf != null) {
        if (tag instanceof TagInTag) {
            throw new JapidCompilationException(template, tag.startLine, "Syntax error: def/set tag cannot be nested in another def/set tag.");
        }
        if (!(tag instanceof TagIf))
            tagtagf.tags.add(tag);
    }
    tagsStackShadow.push(tag);
    if (!(tag instanceof TagIf))
        tagsStack.push(tag);
}
Also used : TagInTag(cn.bran.japid.compiler.Tag.TagInTag) TagIf(cn.bran.japid.compiler.Tag.TagIf)

Example 3 with TagInTag

use of cn.bran.japid.compiler.Tag.TagInTag in project Japid by branaway.

the class JapidAbstractCompiler method endRegularTag.

/**
	 * @param tag
	 */
protected void endRegularTag(Tag tag) {
    if (tag.hasBody) {
        InnerClassMeta bodyInner = this.getTemplateClassMetaData().addCallTagBodyInnerClass(tag.tagName, tag.tagIndex, tag.callbackArgs, tag.getBodyText());
        if (bodyInner == null)
            throw new RuntimeException("compiler bug? " + tag.tagName + " not allowed to have instance of this tag");
        String tagVar = tag.getTagVarName();
        String tagClassName = tag.tagName;
        if (tagClassName.equals("this")) {
            // call itself
            tagClassName = this.getTemplateClassMetaData().getClassName();
        }
        //			String tagline = "final " + tagClassName + " " + tagVar + " = new " + tagClassName + "(getOut()); "
        //					+ tagVar;
        String tagline = "new " + tagClassName + "(" + getTemplateClassMetaData().getClassName() + ".this)";
        //			tagline += ".setOut(getOut()); " + tagVar;
        if (tag.argsNamed()) {
            tagline += ".render( " + makeLineMarker(tag.startLine) + "\n" + bodyInner.getAnonymous(makeLineMarker(tag.startLine)) + ", " + (WebUtils.asBoolean(tag.args) ? tag.args : "") + ");";
        } else {
            tagline += ".render(" + makeLineMarker(tag.startLine) + "\n" + (WebUtils.asBoolean(tag.args) ? tag.args + ", " : "") + bodyInner.getAnonymous(makeLineMarker(tag.startLine)) + ");";
        }
        // tagline += makeLineMarker(tag.startLine);
        print(tagline);
    } else {
        // for simple tag call without call back:
        this.getTemplateClassMetaData().addCallTagBodyInnerClass(tag.tagName, tag.tagIndex, null, null);
    // the calling statement has been added in the regularTagInvoke()
    // method
    }
    // is inside of a tag of own scope and retract the tag inner body class
    TagInTag def = getTagInTag();
    if (def != null) {
        this.getTemplateClassMetaData().removeLastCallTagBodyInnerClass();
    }
}
Also used : TagInTag(cn.bran.japid.compiler.Tag.TagInTag) InnerClassMeta(cn.bran.japid.classmeta.InnerClassMeta)

Example 4 with TagInTag

use of cn.bran.japid.compiler.Tag.TagInTag in project japid42 by branaway.

the class JapidAbstractCompiler method endRegularTag.

/**
	 * @param tag
	 */
protected void endRegularTag(Tag tag) {
    if (tag.hasBody) {
        InnerClassMeta bodyInner = this.getTemplateClassMetaData().addCallTagBodyInnerClass(tag.tagName, tag.tagIndex, tag.callbackArgs, tag.getBodyText());
        if (bodyInner == null)
            throw new RuntimeException("compiler bug? " + tag.tagName + " not allowed to have instance of this tag");
        String tagVar = tag.getTagVarName();
        String tagClassName = tag.tagName;
        if (tagClassName.equals("this")) {
            // call itself
            tagClassName = this.getTemplateClassMetaData().getClassName();
        }
        //			String tagline = "final " + tagClassName + " " + tagVar + " = new " + tagClassName + "(getOut()); "
        //					+ tagVar;
        String tagline = "new " + tagClassName + "(" + getTemplateClassMetaData().getClassName() + ".this)";
        //			tagline += ".setOut(getOut()); " + tagVar;
        if (tag.argsNamed()) {
            tagline += ".render( " + makeLineMarker(tag.startLine) + "\n" + bodyInner.getAnonymous(makeLineMarker(tag.startLine)) + ", " + (WebUtils.asBoolean(tag.args) ? tag.args : "") + ");";
        } else {
            tagline += ".render(" + makeLineMarker(tag.startLine) + "\n" + (WebUtils.asBoolean(tag.args) ? tag.args + ", " : "") + bodyInner.getAnonymous(makeLineMarker(tag.startLine)) + ");";
        }
        //			tagline += makeLineMarker(tag.startLine);
        print(tagline);
    } else {
        // for simple tag call without call back:
        this.getTemplateClassMetaData().addCallTagBodyInnerClass(tag.tagName, tag.tagIndex, null, null);
    // the calling statement has been added in the regularTagInvoke()
    // method
    }
    // is inside of a tag of own scope and retract the tag inner body class
    TagInTag def = getTagInTag();
    if (def != null) {
        this.getTemplateClassMetaData().removeLastCallTagBodyInnerClass();
    }
}
Also used : TagInTag(cn.bran.japid.compiler.Tag.TagInTag) InnerClassMeta(cn.bran.japid.classmeta.InnerClassMeta)

Aggregations

TagInTag (cn.bran.japid.compiler.Tag.TagInTag)4 InnerClassMeta (cn.bran.japid.classmeta.InnerClassMeta)2 TagIf (cn.bran.japid.compiler.Tag.TagIf)2