-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read template attributes as properties (#8988)
Read template attributes as properties Fixes #8974 # Conflicts: # flow-server/src/main/java/com/vaadin/flow/component/littemplate/LitTemplateDataAnalyzer.java # flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/IdCollector.java # flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/TemplateDataAnalyzer.java # flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/TemplateInitializer.java # flow-server/src/test/java/com/vaadin/flow/component/polymertemplate/PolymerTemplateTest.java # flow-tests/test-root-context/frontend/AttributeTemplate.js # flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/template/TemplateAttributeView.java # flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/template/TemplateAttributeIT.java
- Loading branch information
Showing
25 changed files
with
934 additions
and
75 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
.../src/main/java/com/vaadin/flow/component/littemplate/InjectableLitElementInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2000-2020 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.component.littemplate; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.vaadin.flow.component.Component; | ||
import com.vaadin.flow.component.template.internal.AbstractInjectableElementInitializer; | ||
import com.vaadin.flow.dom.Element; | ||
|
||
/** | ||
* Initialize a lit template element with data. | ||
* | ||
* @author Vaadin Ltd | ||
* @since | ||
* | ||
*/ | ||
public class InjectableLitElementInitializer | ||
extends AbstractInjectableElementInitializer { | ||
|
||
private static final String DYNAMIC_ATTRIBUTE_PREFIX = "Template {} contains an attribute {} in element {} which"; | ||
private final Class<? extends Component> templateClass; | ||
|
||
/** | ||
* Creates an initializer for the {@code element}. | ||
* | ||
* @param element | ||
* element to initialize | ||
* @param templateClass | ||
* the class of the template component | ||
*/ | ||
public InjectableLitElementInitializer(Element element, | ||
Class<? extends Component> templateClass) { | ||
super(element); | ||
this.templateClass = templateClass; | ||
} | ||
|
||
@Override | ||
protected boolean isStaticAttribute(String name, String value) { | ||
if (name.startsWith("?")) { | ||
// this is a boolean attribute binding, ignore it since we don't | ||
// support bindings: the value is not an expression | ||
getLogger().debug( | ||
"{} starts with '?' and ignored by initialization since this is an attribute binding", | ||
DYNAMIC_ATTRIBUTE_PREFIX, templateClass.getSimpleName(), | ||
name, getElement().getTag()); | ||
return false; | ||
} | ||
if (name.startsWith(".")) { | ||
// this is a property binding, ignore it since we don't support | ||
// bindings: the value is not an expression | ||
getLogger().debug( | ||
"{} starts with '.' and ignored by initialization since this is a property binding", | ||
DYNAMIC_ATTRIBUTE_PREFIX, templateClass.getSimpleName(), | ||
name, getElement().getTag()); | ||
return false; | ||
} | ||
if (name.startsWith("@")) { | ||
// this is an event listener | ||
getLogger().debug( | ||
"{} starts with '@' and ignored by initialization since this is an event listener declration", | ||
DYNAMIC_ATTRIBUTE_PREFIX, templateClass.getSimpleName(), | ||
name, getElement().getTag()); | ||
return false; | ||
} | ||
if (value == null) { | ||
return true; | ||
} | ||
if (value.contains("${") && value.contains("}")) { | ||
// this is a dynamic value | ||
getLogger().debug( | ||
"Template {} contains an attribute {} in element {} whose value" | ||
+ " is dynamic and it's ignored by initilization", | ||
templateClass.getSimpleName(), name, getElement().getTag()); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private static Logger getLogger() { | ||
return LoggerFactory.getLogger(InjectableLitElementInitializer.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...n/java/com/vaadin/flow/component/polymertemplate/InjectablePolymerElementInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2000-2020 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.component.polymertemplate; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.vaadin.flow.component.Component; | ||
import com.vaadin.flow.component.template.internal.AbstractInjectableElementInitializer; | ||
import com.vaadin.flow.dom.Element; | ||
|
||
/** | ||
* Initialize a polymer template element with data. | ||
* | ||
* @author Vaadin Ltd | ||
* @since | ||
* | ||
*/ | ||
public class InjectablePolymerElementInitializer | ||
extends AbstractInjectableElementInitializer { | ||
|
||
private static final String DYNAMIC_ATTRIBUTE_PREFIX = "Template {} contains an attribute {} in element {} whose value"; | ||
private final Class<? extends Component> templateClass; | ||
|
||
/** | ||
* Creates an initializer for the {@code element}. | ||
* | ||
* @param element | ||
* element to initialize | ||
* @param templateClass | ||
* the class of the template component | ||
*/ | ||
public InjectablePolymerElementInitializer(Element element, | ||
Class<? extends Component> templateClass) { | ||
super(element); | ||
this.templateClass = templateClass; | ||
} | ||
|
||
@Override | ||
protected boolean isStaticAttribute(String name, String value) { | ||
if (name.endsWith("$")) { | ||
// this is an attribute binding, ignore it since we don't support | ||
// bindings: the value is not an expression | ||
getLogger().debug( | ||
"Template {} contains an attribute {} in element {} which " | ||
+ "ends with $ and ignored by initialization since this is an attribute binding", | ||
templateClass.getSimpleName(), name, getElement().getTag()); | ||
return false; | ||
} | ||
if (value == null) { | ||
return true; | ||
} | ||
if (value.contains("{{") && value.contains("}}")) { | ||
// this is a binding, skip it | ||
getLogger().debug( | ||
"{} contains two-way binding and it's ignored by initilization", | ||
DYNAMIC_ATTRIBUTE_PREFIX, templateClass.getSimpleName(), | ||
name, getElement().getTag()); | ||
return false; | ||
} | ||
if (value.contains("[[") && value.contains("]]")) { | ||
// this is another binding, skip it | ||
getLogger().debug( | ||
"{} contains binding and it's ignored by initilization", | ||
DYNAMIC_ATTRIBUTE_PREFIX, templateClass.getSimpleName(), | ||
name, getElement().getTag()); | ||
return false; | ||
} | ||
if (value.contains("${") && value.contains("}")) { | ||
// this is a dynamic value | ||
getLogger().debug("{} is dynamic and it's ignored by initilization", | ||
DYNAMIC_ATTRIBUTE_PREFIX, templateClass.getSimpleName(), | ||
name, getElement().getTag()); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private static Logger getLogger() { | ||
return LoggerFactory | ||
.getLogger(InjectablePolymerElementInitializer.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.