Search in sources :

Example 1 with TextTemplateNode

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

the class ScriptParsingTest method inlineStyles.

@Test
public void inlineStyles() {
    String contents = // 
    ".foo {\n" + // 
    "  font-weight: bold;\n" + "}\n";
    TemplateNode templateNode = parse(// 
    "<style>" + contents + // 
    "</style>");
    // 
    Assert.assertEquals(ElementTemplateNode.class, templateNode.getClass());
    ElementTemplateNode elementTemplate = (ElementTemplateNode) templateNode;
    Assert.assertEquals("style", elementTemplate.getTag());
    TextTemplateNode textNode = ((TextTemplateNode) elementTemplate.getChild(0));
    String nodeContents = (String) textNode.getTextBinding().getValue(new StateNode());
    Assert.assertEquals(contents, nodeContents);
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 2 with TextTemplateNode

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

the class ScriptParsingTest method inlineScript.

@Test
public void inlineScript() {
    String script = "window.alert('hello');\n" + "window.alert('world');\n";
    TemplateNode templateNode = parse(// 
    "<script>" + script + // 
    "</script>");
    // 
    Assert.assertEquals(ElementTemplateNode.class, templateNode.getClass());
    ElementTemplateNode elementTemplate = (ElementTemplateNode) templateNode;
    Assert.assertEquals("script", elementTemplate.getTag());
    TextTemplateNode textNode = ((TextTemplateNode) elementTemplate.getChild(0));
    String nodeContents = (String) textNode.getTextBinding().getValue(new StateNode());
    Assert.assertEquals(script, nodeContents);
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) StateNode(com.vaadin.flow.internal.StateNode) Test(org.junit.Test)

Example 3 with TextTemplateNode

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

the class TemplateBuilderTest method testBasicTemplate.

@Test
public void testBasicTemplate() {
    // <div baz="lorem" foo="bar">baz</div> where baz is an attribute and
    // foo a property
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setProperty("foo", new StaticBindingValueProvider("bar")).setAttribute("baz", new StaticBindingValueProvider("lorem")).setClassName("a-name", new StaticBindingValueProvider("a-value")).addChild(new TextTemplateBuilder(new StaticBindingValueProvider("baz")));
    List<TemplateNode> nodes = builder.build(null);
    Assert.assertFalse(nodes.isEmpty());
    ElementTemplateNode node = (ElementTemplateNode) nodes.get(0);
    Assert.assertFalse(node.getParent().isPresent());
    Assert.assertEquals("div", node.getTag());
    Assert.assertArrayEquals(new String[] { "foo" }, node.getPropertyNames().toArray());
    Assert.assertEquals("bar", node.getPropertyBinding("foo").get().getValue(null));
    Assert.assertArrayEquals(new String[] { "baz" }, node.getAttributeNames().toArray());
    Assert.assertEquals("lorem", node.getAttributeBinding("baz").get().getValue(null));
    Assert.assertArrayEquals(new String[] { "a-name" }, node.getClassNames().toArray());
    Assert.assertEquals("a-value", node.getClassNameBinding("a-name").get().getValue(null));
    Assert.assertEquals(1, node.getChildCount());
    TextTemplateNode child = (TextTemplateNode) node.getChild(0);
    Assert.assertSame(node, child.getParent().get());
    Assert.assertEquals("baz", child.getTextBinding().getValue(null));
    Assert.assertEquals(0, child.getChildCount());
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) TextTemplateBuilder(com.vaadin.flow.template.angular.TextTemplateBuilder) TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) StaticBindingValueProvider(com.vaadin.flow.template.angular.StaticBindingValueProvider) Test(org.junit.Test)

Example 4 with TextTemplateNode

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

the class DefaultTextModelBuiderFactoryTest method parseNotInclude.

@Test
public void parseNotInclude() {
    TemplateNode node = TemplateParser.parse("<div>foo@include.com, baz@foo.com</div>", null);
    Assert.assertEquals(1, node.getChildCount());
    TemplateNode child = node.getChild(0);
    Assert.assertTrue(child instanceof TextTemplateNode);
    TextTemplateNode text = (TextTemplateNode) child;
    Assert.assertEquals("foo@include.com, baz@foo.com", text.getTextBinding().getValue(null));
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) TemplateNode(com.vaadin.flow.template.angular.TemplateNode) TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) Test(org.junit.Test)

Example 5 with TextTemplateNode

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

the class AngularTemplateParserTest method parseBasicTemplate.

@Test
public void parseBasicTemplate() {
    ElementTemplateNode rootNode = (ElementTemplateNode) parse("<div id=bar>baz<input></div>");
    Assert.assertEquals("div", rootNode.getTag());
    Assert.assertEquals(0, rootNode.getPropertyNames().count());
    Assert.assertEquals(0, rootNode.getClassNames().count());
    Assert.assertEquals(1, rootNode.getAttributeNames().count());
    Assert.assertEquals("bar", rootNode.getAttributeBinding("id").get().getValue(null));
    Assert.assertEquals(2, rootNode.getChildCount());
    TextTemplateNode textChild = (TextTemplateNode) rootNode.getChild(0);
    Assert.assertEquals("baz", textChild.getTextBinding().getValue(null));
    ElementTemplateNode inputChild = (ElementTemplateNode) rootNode.getChild(1);
    Assert.assertEquals("input", inputChild.getTag());
    Assert.assertEquals(0, inputChild.getAttributeNames().count());
    Assert.assertEquals(0, inputChild.getChildCount());
}
Also used : TextTemplateNode(com.vaadin.flow.template.angular.TextTemplateNode) ElementTemplateNode(com.vaadin.flow.template.angular.ElementTemplateNode) Test(org.junit.Test)

Aggregations

TextTemplateNode (com.vaadin.flow.template.angular.TextTemplateNode)7 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)6 Test (org.junit.Test)6 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)4 StateNode (com.vaadin.flow.internal.StateNode)3 BindingValueProvider (com.vaadin.flow.template.angular.BindingValueProvider)1 ElementTemplateBuilder (com.vaadin.flow.template.angular.ElementTemplateBuilder)1 StaticBindingValueProvider (com.vaadin.flow.template.angular.StaticBindingValueProvider)1 TextTemplateBuilder (com.vaadin.flow.template.angular.TextTemplateBuilder)1