Skip to content

Commit

Permalink
Merge pull request #2267 from Haehnchen/feature/component-file-filter
Browse files Browse the repository at this point in the history
add Twig component twig filter and provide default for anonymous as fallback
  • Loading branch information
Haehnchen authored Dec 14, 2023
2 parents c29b3e0 + 253290b commit 53e2345
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ private static Set<String> getAnonymousTemplateDirectories(@NotNull Project proj
}
}

// provide default, is there was noting found
if (list.isEmpty()) {
list.add("components/");
}

return list;
}

Expand Down Expand Up @@ -255,12 +260,17 @@ public boolean visitFile(@NotNull VirtualFile file) {
return super.visitFile(file);
}

if (!"twig".equals(file.getExtension())) {
return super.visitFile(file);
}

String relativePath = VfsUtil.getRelativePath(file, finalRelativeFile, '/');
if (relativePath == null) {
return super.visitFile(file);
}

String replace = StringUtils.stripEnd(relativePath.replace("/", ":"), ".html.twig");
// replace ".html.twig" maybe also other formats
String replace = relativePath.replace("/", ":").replaceAll("((\\.html|\\.json)*\\.twig)$", "");
if (!names.containsKey(replace)) {
names.put(replace, new TwigComponent(replace, null, null));
}
Expand Down

0 comments on commit 53e2345

Please sign in to comment.