This repository has been archived by the owner on Mar 18, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d778960
Showing
14 changed files
with
1,265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.php] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
language: php | ||
sudo: false | ||
dist: trusty | ||
php: | ||
- 7.1 | ||
- 7.0 | ||
- 5.6 | ||
- nightly | ||
|
||
matrix: | ||
fast_finish: true | ||
allow_failures: | ||
- php: nightly | ||
|
||
cache: | ||
apt: true | ||
directories: | ||
- $HOME/.composer/cache | ||
- vendor | ||
|
||
before_install: | ||
- composer self-update | ||
|
||
install: | ||
- composer install -o --prefer-dist --no-interaction | ||
|
||
script: | ||
- composer test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Roots\Sage\Assets; | ||
|
||
/** | ||
* Class JsonManifest | ||
* @package Roots\Sage | ||
* @author QWp6t | ||
*/ | ||
class JsonManifest implements ManifestInterface | ||
{ | ||
/** @var array */ | ||
public $manifest; | ||
|
||
/** @var string */ | ||
public $dist; | ||
|
||
/** | ||
* JsonManifest constructor | ||
* | ||
* @param string $manifestPath Local filesystem path to JSON-encoded manifest | ||
* @param string $distUri Remote URI to assets root | ||
*/ | ||
public function __construct($manifestPath, $distUri) | ||
{ | ||
$this->manifest = file_exists($manifestPath) ? json_decode(file_get_contents($manifestPath), true) : []; | ||
$this->dist = $distUri; | ||
} | ||
|
||
/** @inheritdoc */ | ||
public function get($asset) | ||
{ | ||
return isset($this->manifest[$asset]) ? $this->manifest[$asset] : $asset; | ||
} | ||
|
||
/** @inheritdoc */ | ||
public function getUri($asset) | ||
{ | ||
return "{$this->dist}/{$this->get($asset)}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Roots\Sage\Assets; | ||
|
||
/** | ||
* Interface ManifestInterface | ||
* @package Roots\Sage | ||
* @author QWp6t | ||
*/ | ||
interface ManifestInterface | ||
{ | ||
/** | ||
* Get the cache-busted filename | ||
* | ||
* If the manifest does not have an entry for $asset, then return $asset | ||
* | ||
* @param string $asset The original name of the file before cache-busting | ||
* @return string | ||
*/ | ||
public function get($asset); | ||
|
||
/** | ||
* Get the cache-busted URI | ||
* | ||
* If the manifest does not have an entry for $asset, then return URI for $asset | ||
* | ||
* @param string $asset The original name of the file before cache-busting | ||
* @return string | ||
*/ | ||
public function getUri($asset); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Roots\Sage; | ||
|
||
class Config extends \Illuminate\Config\Repository | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Roots\Sage; | ||
|
||
use Illuminate\Container\Container as BaseContainer; | ||
|
||
class Container extends BaseContainer | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) Roots Team | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# [Sage](https://roots.io/sage/) | ||
[![Packagist](https://img.shields.io/packagist/vpre/roots/sage-lib.svg?style=flat-square)](https://packagist.org/packages/roots/sage) | ||
[![Build Status](https://img.shields.io/travis/roots/sage-lib.svg?style=flat-square)](https://travis-ci.org/roots/sage) | ||
|
||
Sage is a WordPress starter theme with a modern development workflow. | ||
|
||
Sage Repo: [https://github.com/roots/sage](https://github.com/roots/sage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
|
||
namespace Roots\Sage\Template; | ||
|
||
use Illuminate\Contracts\Container\Container as ContainerContract; | ||
use Illuminate\Contracts\View\Factory as FactoryContract; | ||
use Illuminate\View\Engines\CompilerEngine; | ||
use Illuminate\View\Engines\EngineInterface; | ||
use Illuminate\View\ViewFinderInterface; | ||
|
||
/** | ||
* Class BladeProvider | ||
* | ||
* @method bool exists(string $view) Determine if a given view exists. | ||
* @method mixed share(array|string $key, mixed $value = null) | ||
* @method array creator(array|string $views, \Closure|string $callback) | ||
* @method array composer(array|string $views, \Closure|string $callback) | ||
* @method \Illuminate\View\View file(string $file, array $data = [], array $mergeData = []) | ||
* @method \Illuminate\View\View make(string $file, array $data = [], array $mergeData = []) | ||
* @method \Illuminate\View\View addNamespace(string $namespace, string|array $hints) | ||
* @method \Illuminate\View\View replaceNamespace(string $namespace, string|array $hints) | ||
* @method \Illuminate\Contracts\Container\Container getContainer() | ||
*/ | ||
class Blade | ||
{ | ||
/** @var Factory */ | ||
protected $env; | ||
|
||
public function __construct(FactoryContract $env) | ||
{ | ||
$this->env = $env; | ||
} | ||
|
||
/** | ||
* Get the compiler | ||
* | ||
* @return \Illuminate\View\Compilers\BladeCompiler | ||
*/ | ||
public function compiler() | ||
{ | ||
static $engineResolver; | ||
if (!$engineResolver) { | ||
$engineResolver = $this->getContainer()->make('view.engine.resolver'); | ||
} | ||
return $engineResolver->resolve('blade')->getCompiler(); | ||
} | ||
|
||
/** | ||
* @param string $view | ||
* @param array $data | ||
* @param array $mergeData | ||
* @return string | ||
*/ | ||
public function render($view, $data = [], $mergeData = []) | ||
{ | ||
/** @var \Illuminate\Contracts\Filesystem\Filesystem $filesystem */ | ||
$filesystem = $this->getContainer()['files']; | ||
return $this->{$filesystem->exists($view) ? 'file' : 'make'}($view, $data, $mergeData)->render(); | ||
} | ||
|
||
/** | ||
* @param string $file | ||
* @param array $data | ||
* @param array $mergeData | ||
* @return string | ||
*/ | ||
public function compiledPath($file, $data = [], $mergeData = []) | ||
{ | ||
$rendered = $this->file($file, $data, $mergeData); | ||
/** @var EngineInterface $engine */ | ||
$engine = $rendered->getEngine(); | ||
|
||
if (!($engine instanceof CompilerEngine)) { | ||
// Using PhpEngine, so just return the file | ||
return $file; | ||
} | ||
|
||
$compiler = $engine->getCompiler(); | ||
$compiledPath = $compiler->getCompiledPath($rendered->getPath()); | ||
if ($compiler->isExpired($compiledPath)) { | ||
$compiler->compile($file); | ||
} | ||
return $compiledPath; | ||
} | ||
|
||
/** | ||
* @param string $file | ||
* @return string | ||
*/ | ||
public function normalizeViewPath($file) | ||
{ | ||
// Convert `\` to `/` | ||
$view = str_replace('\\', '/', $file); | ||
|
||
// Add namespace to path if necessary | ||
$view = $this->applyNamespaceToPath($view); | ||
|
||
// Remove unnecessary parts of the path | ||
$view = str_replace(array_merge( | ||
$this->getContainer()['config']['view.paths'], | ||
['.blade.php', '.php', '.css'] | ||
), '', $view); | ||
|
||
// Remove superfluous and leading slashes | ||
return ltrim(preg_replace('%//+%', '/', $view), '/'); | ||
} | ||
|
||
/** | ||
* Convert path to view namespace | ||
* | ||
* @param string $path | ||
* @return string | ||
*/ | ||
public function applyNamespaceToPath($path) | ||
{ | ||
/** @var ViewFinderInterface $finder */ | ||
$finder = $this->getContainer()['view.finder']; | ||
if (!method_exists($finder, 'getHints')) { | ||
return $path; | ||
} | ||
$delimiter = $finder::HINT_PATH_DELIMITER; | ||
$hints = $finder->getHints(); | ||
$view = array_reduce(array_keys($hints), function ($view, $namespace) use ($delimiter, $hints) { | ||
return str_replace($hints[$namespace], $namespace.$delimiter, $view); | ||
}, $path); | ||
return preg_replace("%{$delimiter}[\\/]*%", $delimiter, $view); | ||
} | ||
|
||
/** | ||
* Pass any method to the view Factory instance. | ||
* | ||
* @param string $method | ||
* @param array $params | ||
* @return mixed | ||
*/ | ||
public function __call($method, $params) | ||
{ | ||
return call_user_func_array([$this->env, $method], $params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Roots\Sage\Template; | ||
|
||
use Illuminate\Container\Container; | ||
use Illuminate\Contracts\Container\Container as ContainerContract; | ||
use Illuminate\Events\Dispatcher; | ||
use Illuminate\Filesystem\Filesystem; | ||
use Illuminate\View\ViewServiceProvider; | ||
|
||
/** | ||
* Class BladeProvider | ||
*/ | ||
class BladeProvider extends ViewServiceProvider | ||
{ | ||
/** | ||
* @param ContainerContract $container | ||
* @param array $config | ||
* @SuppressWarnings(PHPMD.StaticAccess) | ||
*/ | ||
public function __construct(ContainerContract $container = null, $config = []) | ||
{ | ||
/** @noinspection PhpParamsInspection */ | ||
parent::__construct($container ?: Container::getInstance()); | ||
|
||
$this->app->bindIf('config', function () use ($config) { | ||
return $config; | ||
}, true); | ||
} | ||
|
||
/** | ||
* Bind required instances for the service provider. | ||
*/ | ||
public function register() | ||
{ | ||
$this->registerFilesystem(); | ||
$this->registerEvents(); | ||
$this->registerEngineResolver(); | ||
$this->registerViewFinder(); | ||
$this->registerFactory(); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Register Filesystem | ||
*/ | ||
public function registerFilesystem() | ||
{ | ||
$this->app->bindIf('files', Filesystem::class, true); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Register the events dispatcher | ||
*/ | ||
public function registerEvents() | ||
{ | ||
$this->app->bindIf('events', Dispatcher::class, true); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Register the view finder implementation. | ||
*/ | ||
public function registerViewFinder() | ||
{ | ||
$this->app->bindIf('view.finder', function ($app) { | ||
$config = $this->app['config']; | ||
$paths = $config['view.paths']; | ||
$namespaces = $config['view.namespaces']; | ||
$finder = new FileViewFinder($app['files'], $paths); | ||
array_map([$finder, 'addNamespace'], array_keys($namespaces), $namespaces); | ||
return $finder; | ||
}, true); | ||
return $this; | ||
} | ||
} |
Oops, something went wrong.