Search in sources :

Example 1 with Identifier

use of com.google.template.soy.base.internal.Identifier in project closure-templates by google.

the class TemplateBasicNodeBuilder method setCommandValues.

@Override
public TemplateNodeBuilder setCommandValues(Identifier templateName, List<CommandTagAttribute> attrs) {
    this.cmdText = templateName.identifier() + " " + Joiner.on(' ').join(attrs);
    setCommonCommandValues(attrs);
    visibility = Visibility.PUBLIC;
    for (CommandTagAttribute attribute : attrs) {
        Identifier name = attribute.getName();
        if (COMMON_ATTRIBUTE_NAMES.contains(name.identifier())) {
            continue;
        }
        switch(name.identifier()) {
            case "visibility":
                visibility = attribute.valueAsVisibility(errorReporter);
                break;
            default:
                errorReporter.report(name.location(), CommandTagAttribute.UNSUPPORTED_ATTRIBUTE_KEY, name.identifier(), "template", ImmutableList.builder().add("visibility").addAll(COMMON_ATTRIBUTE_NAMES).build());
        }
    }
    setTemplateNames(soyFileHeaderInfo.namespace + templateName.identifier(), templateName.identifier());
    return this;
}
Also used : Identifier(com.google.template.soy.base.internal.Identifier)

Example 2 with Identifier

use of com.google.template.soy.base.internal.Identifier in project closure-templates by google.

the class TemplateNodeBuilder method setCommonCommandValues.

protected void setCommonCommandValues(List<CommandTagAttribute> attrs) {
    AutoescapeMode autoescapeMode = soyFileHeaderInfo.defaultAutoescapeMode;
    SanitizedContentKind kind = null;
    SourceLocation kindLocation = null;
    for (CommandTagAttribute attribute : attrs) {
        Identifier name = attribute.getName();
        switch(name.identifier()) {
            case "autoescape":
                autoescapeMode = attribute.valueAsAutoescapeMode(errorReporter);
                break;
            case "kind":
                kind = attribute.valueAsContentKind(errorReporter);
                kindLocation = attribute.getValueLocation();
                if (kind == SanitizedContentKind.HTML) {
                    errorReporter.report(kindLocation, CommandTagAttribute.EXPLICIT_DEFAULT_ATTRIBUTE, "kind", "html");
                }
                break;
            case "requirecss":
                setRequiredCssNamespaces(attribute.valueAsRequireCss(errorReporter));
                break;
            case "cssbase":
                setCssBaseNamespace(attribute.valueAsCssBase(errorReporter));
                break;
            case "deprecatedV1":
                markDeprecatedV1(attribute.valueAsEnabled(errorReporter));
                break;
            case "stricthtml":
                strictHtmlDisabled = attribute.valueAsDisabled(errorReporter);
                break;
            default:
                break;
        }
    }
    setAutoescapeInfo(autoescapeMode, kind, kindLocation);
}
Also used : SourceLocation(com.google.template.soy.base.SourceLocation) Identifier(com.google.template.soy.base.internal.Identifier) SanitizedContentKind(com.google.template.soy.base.internal.SanitizedContentKind)

Example 3 with Identifier

use of com.google.template.soy.base.internal.Identifier in project closure-templates by google.

the class TemplateDelegateNodeBuilder method setCommandValues.

@Override
public TemplateNodeBuilder setCommandValues(Identifier templateName, List<CommandTagAttribute> attrs) {
    this.cmdText = templateName.identifier() + " " + Joiner.on(' ').join(attrs);
    setCommonCommandValues(attrs);
    this.delTemplateName = templateName.identifier();
    for (CommandTagAttribute attribute : attrs) {
        Identifier name = attribute.getName();
        if (COMMON_ATTRIBUTE_NAMES.contains(name.identifier())) {
            continue;
        }
        switch(name.identifier()) {
            case "variant":
                // need to get variant parsing out of this.  maybe we can expose some sort of limited
                // primitiveOrGlobal parsing solution?
                ExprNode variantExpr = attribute.valueAsExpr(errorReporter);
                validateVariantExpression(variantExpr, errorReporter);
                this.delTemplateVariantExpr = new ExprRootNode(variantExpr);
                break;
            default:
                errorReporter.report(name.location(), CommandTagAttribute.UNSUPPORTED_ATTRIBUTE_KEY, name.identifier(), "deltemplate", ImmutableList.builder().addAll(COMMON_ATTRIBUTE_NAMES).add("variant").build());
        }
    }
    this.delPriority = soyFileHeaderInfo.priority;
    genInternalTemplateNameHelper();
    return this;
}
Also used : ExprNode(com.google.template.soy.exprtree.ExprNode) Identifier(com.google.template.soy.base.internal.Identifier) ExprRootNode(com.google.template.soy.exprtree.ExprRootNode)

Example 4 with Identifier

use of com.google.template.soy.base.internal.Identifier in project closure-templates by google.

the class CommandTagAttribute method removeDuplicatesAndReportErrors.

/**
 * Identifies duplicate attributes, reports an error for each one, and removes them from the
 * {@link Iterable}.
 */
// used by parser
@SuppressWarnings("unused")
public static void removeDuplicatesAndReportErrors(Iterable<CommandTagAttribute> attrs, ErrorReporter errorReporter) {
    Set<String> seenAttributes = new HashSet<>();
    for (Iterator<CommandTagAttribute> iterator = attrs.iterator(); iterator.hasNext(); ) {
        CommandTagAttribute attr = iterator.next();
        Identifier name = attr.getName();
        if (!seenAttributes.add(name.identifier())) {
            errorReporter.report(name.location(), DUPLICATE_ATTRIBUTE, name.identifier());
            iterator.remove();
        }
    }
}
Also used : Identifier(com.google.template.soy.base.internal.Identifier) HashSet(java.util.HashSet)

Aggregations

Identifier (com.google.template.soy.base.internal.Identifier)4 SourceLocation (com.google.template.soy.base.SourceLocation)1 SanitizedContentKind (com.google.template.soy.base.internal.SanitizedContentKind)1 ExprNode (com.google.template.soy.exprtree.ExprNode)1 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)1 HashSet (java.util.HashSet)1