Skip to content

Commit

Permalink
#278 template names are properly normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
casid committed Sep 30, 2023
1 parent d940f92 commit 7cb7ff1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jte/src/main/java/gg/jte/compiler/TemplateCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ public ClassInfo generateTemplateCall(String name, LinkedHashSet<ClassDefinition
Module templateModule = module.resolve(name);
CodeResolver codeResolver = templateModule.getCodeResolver();

name = templateModule.normalize(name);

templateDependencies.add(new TemplateDependency(name, codeResolver.getLastModified(name)));
ClassInfo classInfo = new ClassInfo(name, config.packageName);

Expand Down
12 changes: 12 additions & 0 deletions jte/src/main/java/gg/jte/compiler/module/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public Module resolve(String name) {
return result;
}

public String normalize(String name) {
if (isRoot()) {
return name;
} else {
if (name.startsWith(alias + "/")) {
return name;
} else {
return alias + "/" + name;
}
}
}

public boolean isRoot() {
return alias.isEmpty();
}
Expand Down
16 changes: 16 additions & 0 deletions jte/src/test/java/gg/jte/TemplateEngine_ModulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.assertj.core.api.Assertions.catchThrowable;

import java.nio.file.Path;
import java.util.List;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -70,5 +71,20 @@ <p>line chart (checkout)</p>
line chart (core)""");
}

@Test
void emptyTopLevelModule_generateAll() {
DirectoryCodeResolver codeResolver = new DirectoryCodeResolver(Path.of("src/test/modules/empty-top-level-module"));
TemplateEngine templateEngine = TemplateEngine.create(codeResolver, ContentType.Html);

List<String> templates = templateEngine.generateAll();

assertThat(templates).containsExactlyInAnyOrder(
"gg/jte/generated/ondemand/apexcharts/JtelinechartGenerated.java",
"gg/jte/generated/ondemand/checkout/JtepageGenerated.java",
"gg/jte/generated/ondemand/core/JtelayoutGenerated.java",
"gg/jte/generated/ondemand/core/component/JtecssGenerated.java"
);
}

// TODO adjust precompileAll() and generateAll() to iterate over all module files as well!
}

0 comments on commit 7cb7ff1

Please sign in to comment.