Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sage 9.0.0-beta.4? #1919

Merged
merged 22 commits into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions .eslintrc

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Include your project-specific ignores in this file
# Read about how to use .gitignore: https://help.github.com/articles/ignoring-files
.cache-loader
dist
bower_components
node_modules
npm-debug.log
yarn-error.log
vendor
resources/assets/config-local.json
3 changes: 0 additions & 3 deletions .stylelintrc

This file was deleted.

28 changes: 14 additions & 14 deletions app/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,7 @@
'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 'home',
'frontpage', 'page', 'paged', 'search', 'single', 'singular', 'attachment'
])->map(function ($type) {
add_filter("{$type}_template_hierarchy", function ($templates) {
return collect($templates)->flatMap(function ($template) {
$transforms = [
'%^/?(resources[\\/]views)?[\\/]?%' => '',
'%(\.blade)?(\.php)?$%' => ''
];
$normalizedTemplate = preg_replace(array_keys($transforms), array_values($transforms), $template);
return ["{$normalizedTemplate}.blade.php", "{$normalizedTemplate}.php"];
})->toArray();
});
add_filter("{$type}_template_hierarchy", __NAMESPACE__.'\\filter_templates');
});

/**
Expand All @@ -59,12 +50,21 @@
$data = collect(get_body_class())->reduce(function ($data, $class) use ($template) {
return apply_filters("sage/template/{$class}/data", $data, $template);
}, []);
echo template($template, $data);
// Return a blank file to make WordPress happy
return get_theme_file_path('index.php');
if ($template) {
echo template($template, $data);
return get_stylesheet_directory().'/index.php';
}
return $template;
}, PHP_INT_MAX);

/**
* Tell WordPress how to find the compiled path of comments.blade.php
*/
add_filter('comments_template', 'App\\template_path');
add_filter('comments_template', function ($comments_template) {
$comments_template = str_replace(
[get_stylesheet_directory(), get_template_directory()],
'',
$comments_template
);
return template_path(locate_template(["views/{$comments_template}", $comments_template]) ?: $comments_template);
});
44 changes: 39 additions & 5 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
namespace App;

use Roots\Sage\Container;
use Illuminate\Contracts\Container\Container as ContainerContract;

/**
* Get the sage container.
*
* @param string $abstract
* @param array $parameters
* @param ContainerContract $container
* @return ContainerContract|mixed
* @SuppressWarnings(PHPMD.StaticAccess)
* @param Container $container
* @return Container|mixed
*/
function sage($abstract = null, $parameters = [], ContainerContract $container = null)
function sage($abstract = null, $parameters = [], Container $container = null)
{
$container = $container ?: Container::getInstance();
if (!$abstract) {
Expand Down Expand Up @@ -77,6 +75,42 @@ function asset_path($asset)
return sage('assets')->getUri($asset);
}

/**
* @param string|string[] $templates Possible template files
* @return array
*/
function filter_templates($templates)
{
return collect($templates)
->map(function ($template) {
return preg_replace('#\.(blade\.)?php$#', '', ltrim($template));
})
->flatMap(function ($template) {
$paths = apply_filters('sage/filter_templates/paths', ['views', 'resources/views']);
return collect($paths)
->flatMap(function ($path) use ($template) {
return [
"{$path}/{$template}.blade.php",
"{$path}/{$template}.php",
"{$template}.blade.php",
"{$template}.php",
];
});
})
->filter()
->unique()
->all();
}

/**
* @param string|string[] $templates Relative path to possible template files
* @return string Location of the template
*/
function locate_template($templates)
{
return \locate_template(filter_templates($templates));
}

/**
* Determine whether to show the sidebar
* @return bool
Expand Down
41 changes: 0 additions & 41 deletions app/lib/Sage/Assets/JsonManifest.php

This file was deleted.

31 changes: 0 additions & 31 deletions app/lib/Sage/Assets/ManifestInterface.php

This file was deleted.

8 changes: 0 additions & 8 deletions app/lib/Sage/Config.php

This file was deleted.

10 changes: 0 additions & 10 deletions app/lib/Sage/Container.php

This file was deleted.

Loading