Search in sources :

Example 1 with TemplateParserResult

use of com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult in project vue-gwt by Axellience.

the class TemplateParser method parseHtmlTemplate.

/**
 * Parse a given HTML template and return the a result object containing the expressions
 * and a transformed HTML.
 * @param htmlTemplate The HTML template to process, as a String
 * @param context Context of the Component we are currently processing
 * @param messager Used to report errors in template during Annotation Processing
 * @return A {@link TemplateParserResult} containing the processed template and expressions
 */
public TemplateParserResult parseHtmlTemplate(String htmlTemplate, TemplateParserContext context, Messager messager) {
    this.context = context;
    this.logger = new TemplateParserLogger(context, messager);
    initJerichoConfig(this.logger);
    Source source = new Source(htmlTemplate);
    outputDocument = new OutputDocument(source);
    result = new TemplateParserResult(context);
    processImports(source);
    source.getChildElements().forEach(this::processElement);
    result.setProcessedTemplate(outputDocument.toString());
    return result;
}
Also used : OutputDocument(net.htmlparser.jericho.OutputDocument) TemplateParserResult(com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult) Source(net.htmlparser.jericho.Source)

Example 2 with TemplateParserResult

use of com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult in project vue-gwt by Axellience.

the class ComponentTemplateProcessor method processComponentTemplate.

public void processComponentTemplate(TypeElement componentTypeElement, Builder componentJsTypeBuilder) {
    ClassName componentTypeName = ClassName.get(componentTypeElement);
    Optional<String> optionalTemplateContent = getTemplateContent(componentTypeName, componentTypeElement);
    if (!optionalTemplateContent.isPresent())
        return;
    LocalComponents localComponents = new LocalComponents();
    findLocalComponentsForComponent(localComponents, componentTypeElement);
    // Initialize the template parser context based on the VueComponent type element
    TemplateParserContext templateParserContext = new TemplateParserContext(componentTypeElement, localComponents);
    registerFieldsAndMethodsInContext(templateParserContext, componentTypeElement, new HashSet<>(), new HashSet<>());
    // Parse the template
    TemplateParserResult templateParserResult = new TemplateParser().parseHtmlTemplate(optionalTemplateContent.get(), templateParserContext, messager);
    // Add expressions from the template to JsType and compile template
    TemplateMethodsBuilder templateMethodsBuilder = new TemplateMethodsBuilder();
    templateMethodsBuilder.addTemplateMethodsToComponentJsType(componentJsTypeBuilder, templateParserResult);
}
Also used : TemplateParserContext(com.axellience.vuegwt.processors.component.template.parser.context.TemplateParserContext) TemplateMethodsBuilder(com.axellience.vuegwt.processors.component.template.builder.TemplateMethodsBuilder) ClassName(com.squareup.javapoet.ClassName) TemplateParser(com.axellience.vuegwt.processors.component.template.parser.TemplateParser) TemplateParserResult(com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult) ComponentGeneratorsUtil.getComponentLocalComponents(com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil.getComponentLocalComponents) LocalComponents(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponents)

Aggregations

TemplateParserResult (com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult)2 TemplateMethodsBuilder (com.axellience.vuegwt.processors.component.template.builder.TemplateMethodsBuilder)1 TemplateParser (com.axellience.vuegwt.processors.component.template.parser.TemplateParser)1 TemplateParserContext (com.axellience.vuegwt.processors.component.template.parser.context.TemplateParserContext)1 LocalComponents (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponents)1 ComponentGeneratorsUtil.getComponentLocalComponents (com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil.getComponentLocalComponents)1 ClassName (com.squareup.javapoet.ClassName)1 OutputDocument (net.htmlparser.jericho.OutputDocument)1 Source (net.htmlparser.jericho.Source)1