From 3eb47937060bed01ef25e81c835dcadf2d25e64f Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Sun, 19 Jan 2020 00:37:31 -0700 Subject: [PATCH] Generate parent directory link instead of using '..' --- app/Providers/TwigProvider.php | 1 + app/ViewFunctions/ParentDir.php | 25 ++++++++++++++++++++++++ app/resources/views/components/file.twig | 2 +- app/resources/views/index.twig | 4 +--- tests/ViewFunctions/ParentTest.php | 16 +++++++++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 app/ViewFunctions/ParentDir.php create mode 100644 tests/ViewFunctions/ParentTest.php diff --git a/app/Providers/TwigProvider.php b/app/Providers/TwigProvider.php index 51537ed..45177eb 100644 --- a/app/Providers/TwigProvider.php +++ b/app/Providers/TwigProvider.php @@ -19,6 +19,7 @@ class TwigProvider ViewFunctions\Config::class, ViewFunctions\Icon::class, ViewFunctions\Markdown::class, + ViewFunctions\ParentDir::class, ViewFunctions\SizeForHumans::class, ]; diff --git a/app/ViewFunctions/ParentDir.php b/app/ViewFunctions/ParentDir.php new file mode 100644 index 0000000..e59366f --- /dev/null +++ b/app/ViewFunctions/ParentDir.php @@ -0,0 +1,25 @@ +filter()->slice(0, -1)->implode('/'); + } +} diff --git a/app/resources/views/components/file.twig b/app/resources/views/components/file.twig index 4b61f43..ab6cb76 100644 --- a/app/resources/views/components/file.twig +++ b/app/resources/views/components/file.twig @@ -1,5 +1,5 @@
diff --git a/app/resources/views/index.twig b/app/resources/views/index.twig index 1161b61..9cd1615 100644 --- a/app/resources/views/index.twig +++ b/app/resources/views/index.twig @@ -20,9 +20,7 @@
{% if not search and not is_root %} - {{ include('components/file.twig', { - parentDir: true - }, with_context = false) }} + {{ include('components/file.twig', { parentDir: true }) }} {% endif %} {% for file in files %} diff --git a/tests/ViewFunctions/ParentTest.php b/tests/ViewFunctions/ParentTest.php new file mode 100644 index 0000000..6f6c0f4 --- /dev/null +++ b/tests/ViewFunctions/ParentTest.php @@ -0,0 +1,16 @@ +container, $this->config); + + $this->assertEquals('foo/bar', $parentDir('foo/bar/baz')); + } +}