Search in sources :

Example 11 with ElementTemplateBuilder

use of com.vaadin.flow.template.angular.ElementTemplateBuilder in project flow by vaadin.

the class TemplateElementStateProviderTest method testElementAttributes.

@Test
public void testElementAttributes() {
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setAttribute("a1", new StaticBindingValueProvider("v1")).setAttribute("a2", new StaticBindingValueProvider("v2"));
    Element element = createElement(builder);
    Assert.assertEquals("v1", element.getAttribute("a1"));
    Assert.assertEquals("v2", element.getAttribute("a2"));
    Assert.assertEquals(new HashSet<>(Arrays.asList("a1", "a2")), element.getAttributeNames().collect(Collectors.toSet()));
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) StaticBindingValueProvider(com.vaadin.flow.template.angular.StaticBindingValueProvider) Test(org.junit.Test)

Example 12 with ElementTemplateBuilder

use of com.vaadin.flow.template.angular.ElementTemplateBuilder in project flow by vaadin.

the class DefaultElementBuilderFactory method createBuilder.

@Override
public TemplateNodeBuilder createBuilder(Element element, Function<Node, Optional<TemplateNodeBuilder>> builderProducer) {
    ElementTemplateBuilder builder = new ElementTemplateBuilder(element.tagName());
    element.attributes().forEach(attr -> setBinding(attr, builder, element));
    element.childNodes().stream().map(builderProducer::apply).filter(Optional::isPresent).map(Optional::get).forEach(builder::addChild);
    return builder;
}
Also used : Optional(java.util.Optional) ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder)

Aggregations

ElementTemplateBuilder (com.vaadin.flow.template.angular.ElementTemplateBuilder)12 Test (org.junit.Test)11 Element (com.vaadin.flow.dom.Element)10 StateNode (com.vaadin.flow.internal.StateNode)4 ModelValueBindingProvider (com.vaadin.flow.template.angular.ModelValueBindingProvider)4 StaticBindingValueProvider (com.vaadin.flow.template.angular.StaticBindingValueProvider)4 TextTemplateBuilder (com.vaadin.flow.template.angular.TextTemplateBuilder)2 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)1 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)1 TextTemplateNode (com.vaadin.flow.template.angular.TextTemplateNode)1 JsonObject (elemental.json.JsonObject)1 Optional (java.util.Optional)1