Skip to content

Commit 552741a

Browse files
committed
strip also "Bundle" from template folding and provide test
1 parent 3279d37 commit 552741a

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

src/fr/adrienbrault/idea/symfony2plugin/navigation/PhpFoldingBuilder.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
1212
import fr.adrienbrault.idea.symfony2plugin.Settings;
1313
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
14+
import fr.adrienbrault.idea.symfony2plugin.TwigHelper;
1415
import fr.adrienbrault.idea.symfony2plugin.config.SymfonyPhpReferenceContributor;
1516
import fr.adrienbrault.idea.symfony2plugin.routing.PhpRouteReferenceContributor;
1617
import fr.adrienbrault.idea.symfony2plugin.routing.Route;
1718
import fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper;
19+
import fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil;
1820
import fr.adrienbrault.idea.symfony2plugin.util.MethodMatcher;
1921
import org.jetbrains.annotations.NotNull;
2022
import org.jetbrains.annotations.Nullable;
@@ -142,15 +144,9 @@ private void attachTemplateShortcuts(List<FoldingDescriptor> descriptors, final
142144
}
143145

144146
String content = stringLiteralExpression.getContents();
145-
String templateShortcutName = null;
146147

147-
if(content.endsWith(".html.twig") && content.length() > 10) {
148-
templateShortcutName = content.substring(0, content.length() - 10);
149-
} else if(content.endsWith(".html.php") && content.length() > 9) {
150-
templateShortcutName = content.substring(0, content.length() - 9);
151-
}
152-
153-
if(templateShortcutName == null || templateShortcutName.length() == 0) {
148+
String templateShortcutName = TwigUtil.getFoldingTemplateName(content);
149+
if(templateShortcutName == null) {
154150
return;
155151
}
156152

src/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,31 @@ public static HashMap<String, Set<String>> collectControllerTemplateVariables(Ps
303303

304304
}
305305

306+
@Nullable
307+
public static String getFoldingTemplateName(String content) {
308+
309+
String templateShortcutName = null;
310+
if(content.endsWith(".html.twig") && content.length() > 10) {
311+
templateShortcutName = content.substring(0, content.length() - 10);
312+
} else if(content.endsWith(".html.php") && content.length() > 9) {
313+
templateShortcutName = content.substring(0, content.length() - 9);
314+
}
315+
316+
if(templateShortcutName == null || templateShortcutName.length() == 0) {
317+
return null;
318+
}
319+
320+
// template FooBundle:Test:edit.html.twig
321+
if(templateShortcutName.length() <= "Bundle:".length()) {
322+
return templateShortcutName;
323+
}
324+
325+
int split = templateShortcutName.indexOf("Bundle:");
326+
if(split > 0) {
327+
templateShortcutName = templateShortcutName.substring(0, split) + templateShortcutName.substring("Bundle".length() + split);
328+
}
329+
330+
return templateShortcutName;
331+
}
332+
306333
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package fr.adrienbrault.idea.symfony2plugin.tests.templating.util;
2+
3+
import fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
8+
public class TwigUtilTest extends Assert {
9+
10+
@Test
11+
public void testGetFoldingTemplateName() {
12+
13+
assertEquals("Foo:edit", TwigUtil.getFoldingTemplateName("FooBundle:edit.html.twig"));
14+
assertEquals("Foo:edit", TwigUtil.getFoldingTemplateName("FooBundle:edit.html.php"));
15+
assertEquals("Bundle:", TwigUtil.getFoldingTemplateName("Bundle:.html.twig"));
16+
assertEquals("edit", TwigUtil.getFoldingTemplateName("edit.html.twig"));
17+
assertNull(TwigUtil.getFoldingTemplateName("FooBundle:edit.foo.twig"));
18+
19+
}
20+
21+
}

0 commit comments

Comments
 (0)