Search in sources :

Example 1 with LocalComponentProp

use of com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponentProp in project vue-gwt by Axellience.

the class TemplateParser method processElementAttributes.

/**
 * Process an {@link Element} and check for vue attributes.
 * @param element Current element being processed
 */
private void processElementAttributes(Element element) {
    Optional<LocalComponent> localComponent = getLocalComponentForElement(element);
    // Iterate on element attributes
    Set<LocalComponentProp> foundProps = new HashSet<>();
    for (Attribute attribute : element.getAttributes()) {
        if ("v-for".equals(attribute.getKey()) || "v-model".equals(attribute.getKey()))
            continue;
        Optional<LocalComponentProp> optionalProp = localComponent.flatMap(lc -> lc.getPropForAttribute(attribute.getName()));
        optionalProp.ifPresent(foundProps::add);
        if (!VUE_ATTR_PATTERN.matcher(attribute.getKey()).matches()) {
            optionalProp.ifPresent(this::validateStringPropBinding);
            continue;
        }
        context.setCurrentSegment(attribute);
        currentAttribute = attribute;
        currentProp = optionalProp.orElse(null);
        currentExpressionReturnType = getExpressionReturnTypeForAttribute(attribute);
        String processedExpression = processExpression(attribute.getValue());
        if (attribute.getValueSegment() != null)
            outputDocument.replace(attribute.getValueSegment(), processedExpression);
    }
    localComponent.ifPresent(lc -> validateRequiredProps(lc, foundProps));
}
Also used : LocalComponentProp(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponentProp) Attribute(net.htmlparser.jericho.Attribute) LocalComponent(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent) HashSet(java.util.HashSet)

Aggregations

LocalComponent (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent)1 LocalComponentProp (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponentProp)1 HashSet (java.util.HashSet)1 Attribute (net.htmlparser.jericho.Attribute)1