Makes it possible to put templates in subdirectories
This commit is contained in:
parent
c1c062b6cf
commit
68dc70c176
4 changed files with 14 additions and 10 deletions
|
@ -21,6 +21,7 @@ import nu.zoom.dsl.ast.DocumentNode;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.FileVisitOption;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
|
@ -50,17 +51,20 @@ public class Generator {
|
|||
}
|
||||
|
||||
public List<Path> generate() throws IOException, TemplateException {
|
||||
try (Stream<Path> files = Files.list(templatesDir)) {
|
||||
List<String> templates = files
|
||||
.map(Path::getFileName)
|
||||
.map(Path::toString)
|
||||
.filter(p -> p.length() > TEMPLATE_EXTENSION_LENGTH && p.endsWith(TEMPLATE_EXTENSION)
|
||||
)
|
||||
.toList();
|
||||
try (Stream<Path> files = Files.walk(templatesDir)) {
|
||||
List<Path> templates = files
|
||||
.filter(p -> {
|
||||
var fname = p.getFileName().toString();
|
||||
return fname.length() > TEMPLATE_EXTENSION_LENGTH && fname.endsWith(TEMPLATE_EXTENSION) ;
|
||||
}
|
||||
)
|
||||
.map(p -> templatesDir.relativize(p))
|
||||
.toList();
|
||||
ArrayList<Path> out = new ArrayList<>();
|
||||
for (String template : templates) {
|
||||
Path outpath = outputDir.resolve(outputFilenameFromTemplate(template));
|
||||
Template ftl = this.cfg.getTemplate(template);
|
||||
for (Path template : templates) {
|
||||
Path outpath = outputDir.resolve(outputFilenameFromTemplate(template.toString()));
|
||||
Files.createDirectories(outpath.getParent());
|
||||
Template ftl = this.cfg.getTemplate(template.toString());
|
||||
try (var outw = Files.newBufferedWriter(outpath, StandardCharsets.UTF_8)) {
|
||||
ftl.process(this.data, outw);
|
||||
out.add(outpath);
|
||||
|
|
Loading…
Add table
Reference in a new issue