-
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.
Implement lit template parser for limited template formats which exte…
…nds LitTemplate element (#8979) Implement lit template parser for limited template formats which extends LitTemplate element Fixes #8966 # Conflicts: # flow-server/src/main/java/com/vaadin/flow/component/littemplate/LitTemplateDataAnalyzer.java # flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/BundleParser.java # flow-server/src/test/resources/META-INF/VAADIN/config/stats.json
- Loading branch information
Showing
12 changed files
with
898 additions
and
24 deletions.
There are no files selected for viewing
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
124 changes: 124 additions & 0 deletions
124
flow-server/src/main/java/com/vaadin/flow/component/littemplate/LitTemplateParser.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,124 @@ | ||
/* | ||
* 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.jsoup.nodes.Element; | ||
|
||
import com.vaadin.flow.di.Instantiator; | ||
import com.vaadin.flow.server.VaadinService; | ||
|
||
/** | ||
* Lit template content parser. | ||
* <p> | ||
* It returns a JSOUP element representing the content of template for the given | ||
* template class. | ||
* | ||
* @see LitTemplateParserImpl | ||
* | ||
* @author Vaadin Ltd | ||
* @since | ||
* | ||
*/ | ||
@FunctionalInterface | ||
public interface LitTemplateParser { | ||
|
||
/** | ||
* Lit template parser factory. | ||
* <p> | ||
* To be able to create a parser which can be provided as SPI use | ||
* {@link Instantiator} to create the factory and then get a parser from it: | ||
* | ||
* <pre> | ||
* <code> | ||
* Instantiator instantiator = ...; | ||
* LitTemplateParserFactory factory = instantiator.getOrCreate(LitTemplateParserFactory.class); | ||
* LitTemplateParser parser = factory.createParser(); | ||
* </code> | ||
* </pre> | ||
* <p> | ||
* | ||
* @author Vaadin Ltd | ||
* @see LitTemplateParser | ||
* @since | ||
* | ||
*/ | ||
class LitTemplateParserFactory { | ||
|
||
/** | ||
* Creates a Lit template parser instance. | ||
* | ||
* @return a lit template parser instance | ||
*/ | ||
public LitTemplateParser createParser() { | ||
return LitTemplateParserImpl.getInstance(); | ||
} | ||
} | ||
|
||
/** | ||
* Wrapper for the parsing result. | ||
* <p> | ||
* The data contains path uri where the template is declared and its content | ||
* as an {@link Element} instance. | ||
* | ||
* @author Vaadin Ltd | ||
* @since | ||
* | ||
*/ | ||
class TemplateData { | ||
|
||
private final String modulePath; | ||
private final Element templateElement; | ||
|
||
public TemplateData(String uri, Element element) { | ||
modulePath = uri; | ||
templateElement = element; | ||
} | ||
|
||
/** | ||
* Gets the uri where the template is declared. | ||
* | ||
* @return template uri | ||
*/ | ||
public String getModulePath() { | ||
return modulePath; | ||
} | ||
|
||
/** | ||
* Gets the content of the template. | ||
* | ||
* @return the content of the template | ||
*/ | ||
public Element getTemplateElement() { | ||
return templateElement; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the template data which contains a JSOUP {@link Element} | ||
* representing the template content and the template uri. | ||
* | ||
* @param clazz | ||
* the template class | ||
* @param tag | ||
* the template tag name | ||
* @param service | ||
* the related Vaadin service | ||
* | ||
* @return the template data, may be {@code null} | ||
*/ | ||
TemplateData getTemplateContent(Class<? extends LitTemplate> clazz, | ||
String tag, VaadinService service); | ||
} |
Oops, something went wrong.