From 33b981c4fcae55b1ca237da9fa859f828b9ede7e Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Tue, 8 Aug 2017 18:17:02 -0300 Subject: [PATCH] Ensure to get templates filenames without path and extension. --- app/helpers.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/helpers.php b/app/helpers.php index e9f1036..6a50e1a 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -81,12 +81,25 @@ function asset_path($asset) */ function filter_templates($templates) { + $paths = apply_filters('sage/filter_templates/paths', [ + 'views', + 'resources/views' + ]); + $paths_pattern = "#^(" . implode('|', $paths) . ")/#"; + return collect($templates) - ->map(function ($template) { - return preg_replace('#\.(blade\.)?php$#', '', ltrim($template)); + ->map(function ($template) use ($paths_pattern) { + /** Remove .blade.php/.blade/.php from template names */ + $template = preg_replace('#\.(blade\.?)?(php)?$#', '', ltrim($template)); + + /** Remove partial $paths from the beginning of template names */ + if (strpos($template, '/')) { + $template = preg_replace($paths_pattern, '', $template); + } + + return $template; }) - ->flatMap(function ($template) { - $paths = apply_filters('sage/filter_templates/paths', ['views', 'resources/views']); + ->flatMap(function ($template) use ($paths) { return collect($paths) ->flatMap(function ($path) use ($template) { return [