Skip to content

Commit

Permalink
Merge branch 'temp-cache-system' into cache-system
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed May 11, 2017
2 parents de18d7a + 549a1e9 commit 0ae5fbf
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 227 deletions.
102 changes: 59 additions & 43 deletions src/PugBladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,64 @@
use Illuminate\Filesystem\Filesystem;
use Pug\Pug;

class PugBladeCompiler extends BladeCompiler implements CompilerInterface {

/**
* The MtHaml instance.
*
* @var Pug
*/
protected $pug;

/**
* Create a new compiler instance.
*
* @param Pug $pug
* @param \Illuminate\Filesystem\Filesystem $files
* @param string $cachePath
* @return void
*/
public function __construct(Pug $pug, Filesystem $files, $cachePath)
{
$this->pug = $pug;
parent::__construct($files, $cachePath);
}

/**
* Compile the view at the given path.
*
* @param string $path
* @return void
*/
public function compile($path) {
$this->footer = array();

if (is_null($this->cachePath)) return;

// First compile the Pug syntax
$contents = $this->pug->compile($this->files->get($path), $path);

// Then the Blade syntax
$contents = $this->compileString($contents);

// Save
$this->files->put($this->getCompiledPath($path), $contents);
}
class PugBladeCompiler extends BladeCompiler implements CompilerInterface
{
/**
* The MtHaml instance.
*
* @var Pug
*/
protected $pug;

/**
* Create a new compiler instance.
*
* @param Pug $pug
* @param \Illuminate\Filesystem\Filesystem $files
* @param string $cachePath
* @return void
*/
public function __construct(Pug $pug, Filesystem $files)
{
$this->pug = $pug;
$this->files = $files;
$this->cachePath = $pug->getOption('cache');
if (!is_string($this->cachePath)) {
$this->cachePath = $pug->getOption('defaultCache');
}
}

/**
* Determine if the view at the given path is expired.
*
* @param string $path
* @return bool
*/
public function isExpired($path)
{
return !$this->pug->getOption('cache') || parent::isExpired($path);
}

/**
* Compile the view at the given path.
*
* @param string $path
* @return void
*/
public function compile($path)
{
$this->footer = array();

if ($this->cachePath) {
// First compile the Pug syntax
$contents = $this->pug->compile($this->files->get($path), $path);

// Then the Blade syntax
$contents = $this->compileString($contents);

// Save
$this->files->put($this->getCompiledPath($path), $contents);
}
}

}
75 changes: 46 additions & 29 deletions src/PugCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,54 @@
use Illuminate\Filesystem\Filesystem;
use Pug\Pug;

class PugCompiler extends Compiler implements CompilerInterface {
class PugCompiler extends Compiler implements CompilerInterface
{
/**
* @var Pug
*/
protected $pug;

/**
* @var Pug
*/
protected $pug;
/**
* Create a new compiler instance.
*
* @param Pug $pug
* @param Illuminate\Filesystem\Filesystem $files
* @param string $cachePath
* @return void
*/
public function __construct(Pug $pug, Filesystem $files)
{
$this->pug = $pug;
$this->files = $files;
$this->cachePath = $pug->getOption('cache');
if (!is_string($this->cachePath)) {
$this->cachePath = $pug->getOption('defaultCache');
}
}

/**
* Create a new compiler instance.
*
* @param Pug $pug
* @param Illuminate\Filesystem\Filesystem $files
* @param string $cachePath
* @return void
*/
public function __construct(Pug $pug, Filesystem $files, $cachePath)
{
$this->pug = $pug;
parent::__construct($files, $cachePath);
}
/**
* Determine if the view at the given path is expired.
*
* @param string $path
* @return bool
*/
public function isExpired($path)
{
return !$this->pug->getOption('cache') || parent::isExpired($path);
}

/**
* Compile the view at the given path.
*
* @param string $path
* @return void
*/
public function compile($path) {
if (is_null($this->cachePath)) return;
$contents = $this->pug->compile($this->files->get($path), $path);
$this->files->put($this->getCompiledPath($path), $contents);
}
/**
* Compile the view at the given path.
*
* @param string $path
* @return void
*/
public function compile($path)
{
if ($this->cachePath) {
$contents = $this->pug->compile($this->files->get($path), $path);
$this->files->put($this->getCompiledPath($path), $contents);
}
}

}
Loading

0 comments on commit 0ae5fbf

Please sign in to comment.