Skip to content

Commit

Permalink
Ensure to get templates filenames without path and extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisermann committed Aug 17, 2017
1 parent 0a0f1dc commit 33b981c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit 33b981c

Please sign in to comment.