Skip to content

Commit

Permalink
Pug php 3 compatibility (#32)
Browse files Browse the repository at this point in the history
* Pug-php 3 compatibility
  • Loading branch information
kylekatarnls authored Oct 7, 2017
1 parent 63998c8 commit e14a19d
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 25 deletions.
130 changes: 113 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,141 @@ git:
matrix:
include:
- php: 5.4
env: LARAVEL_VERSION='4.2.*'
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^2.7.1'
- php: 5.5
env: LARAVEL_VERSION='4.2.*'
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^2.7.1'
- php: 5.5
env: LARAVEL_VERSION='5.2.*'
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^3.0.0@beta'
- php: 5.5
env:
- LARAVEL_VERSION='5.2.*'
- PUG_VERSION='^2.7.1'
- php: 5.5
env:
- LARAVEL_VERSION='5.2.*'
- PUG_VERSION='^3.0.0@beta'
- php: 5.6
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^2.7.1'
- php: 5.6
env: LARAVEL_VERSION='4.2.*'
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^3.0.0@beta'
- php: 5.6
env: LARAVEL_VERSION='5.4.*'
env:
- LARAVEL_VERSION='5.4.*'
- PUG_VERSION='^2.7.1'
- php: 5.6
env:
- LARAVEL_VERSION='5.4.*'
- PUG_VERSION='^3.0.0@beta'
- php: 7.0
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^2.7.1'
- php: 7.0
env: LARAVEL_VERSION='4.2.*'
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^3.0.0@beta'
- php: 7.0
env: LARAVEL_VERSION='5.4.*'
env:
- LARAVEL_VERSION='5.4.*'
- PUG_VERSION='^2.7.1'
- php: 7.0
env: LARAVEL_VERSION='5.5.*'
env:
- LARAVEL_VERSION='5.4.*'
- PUG_VERSION='^3.0.0@beta'
- php: 7.0
env:
- LARAVEL_VERSION='5.5.*'
- PUG_VERSION='^2.7.1'
- php: 7.0
env:
- LARAVEL_VERSION='5.5.*'
- PUG_VERSION='^3.0.0@beta'
- php: 7.1
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^2.7.1'
- php: 7.1
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^3.0.0@beta'
- php: 7.1
env:
- LARAVEL_VERSION='5.4.*'
- PUG_VERSION='^2.7.1'
- php: 7.1
env: LARAVEL_VERSION='4.2.*'
env:
- LARAVEL_VERSION='5.4.*'
- PUG_VERSION='^3.0.0@beta'
- php: 7.1
env: LARAVEL_VERSION='5.4.*'
env:
- LARAVEL_VERSION='5.5.*'
- PUG_VERSION='^2.7.1'
- php: 7.1
env: LARAVEL_VERSION='5.5.*'
env:
- LARAVEL_VERSION='5.5.*'
- PUG_VERSION='^3.0.0@beta'
- php: 7.2
env: LARAVEL_VERSION='4.2.*'
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^2.7.1'
- php: 7.2
env: LARAVEL_VERSION='5.4.*'
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^3.0.0@beta'
- php: 7.2
env: LARAVEL_VERSION='5.5.*'
env:
- LARAVEL_VERSION='5.4.*'
- PUG_VERSION='^2.7.1'
- php: 7.2
env:
- LARAVEL_VERSION='5.4.*'
- PUG_VERSION='^3.0.0@beta'
- php: 7.2
env:
- LARAVEL_VERSION='5.5.*'
- PUG_VERSION='2.7.1'
- php: 7.2
env:
- LARAVEL_VERSION='5.5.*'
- PUG_VERSION='^3.0.0@beta'
- php: hhvm
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='2.7.1'
dist: trusty
sudo: required
- php: hhvm
env:
- LARAVEL_VERSION='4.2.*'
- PUG_VERSION='^3.0.0@beta'
dist: trusty
sudo: required
- php: hhvm
env: LARAVEL_VERSION='4.2.*'
env:
- LARAVEL_VERSION='5.4.*'
- PUG_VERSION='^2.7.1'
dist: trusty
sudo: required
- php: hhvm
env: LARAVEL_VERSION='5.4.*'
env:
- LARAVEL_VERSION='5.4.*'
- PUG_VERSION='^3.0.0@beta'
dist: trusty
sudo: required

install:
- travis_retry composer self-update
- if [ "LARAVEL_VERSION" != "" ]; then travis_retry php tests/setLaravelVersion.php $LARAVEL_VERSION; fi;
- if [ "LARAVEL_VERSION" != "" ]; then travis_retry php tests/setDependenciesVersions.php $LARAVEL_VERSION $PUG_VERSION; fi;
- travis_retry composer update --no-interaction --prefer-stable

script:
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
{
"name": "Robert Reinhard",
"email": "[email protected]"
},
{
"name": "Kyle Katarn",
"email": "[email protected]"
}
],
"autoload": {
Expand Down
23 changes: 20 additions & 3 deletions src/PugBladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,30 @@ class PugBladeCompiler extends BladeCompiler implements CompilerInterface
public function __construct(Pug $pug, Filesystem $files)
{
$this->pug = $pug;
$cachePath = $pug->getOption('cache');
$cachePath = $this->getOption('cache');
if (!is_string($cachePath)) {
$cachePath = $pug->getOption('defaultCache');
$cachePath = $this->getOption('defaultCache');
}
parent::__construct($files, $cachePath);
}

/**
* Get an option from pug engine or default value.
*
* @param string $name
* @param null $default
*
* @return mixed|null
*/
public function getOption($name, $default = null)
{
if (method_exists($this->pug, 'hasOption') && !$this->pug->hasOption($name)) {
return $default;
}

return $this->pug->getOption($name);
}

/**
* @param string $cachePath
*/
Expand All @@ -54,7 +71,7 @@ public function setCachePath($cachePath)
*/
public function isExpired($path)
{
return !$this->pug->getOption('cache') || parent::isExpired($path);
return !$this->getOption('cache') || parent::isExpired($path);
}

/**
Expand Down
23 changes: 20 additions & 3 deletions src/PugCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,30 @@ class PugCompiler extends Compiler implements CompilerInterface
public function __construct(Pug $pug, Filesystem $files)
{
$this->pug = $pug;
$cachePath = $pug->getOption('cache');
$cachePath = $this->getOption('cache');
if (!is_string($cachePath)) {
$cachePath = $pug->getOption('defaultCache');
$cachePath = $this->getOption('defaultCache');
}
parent::__construct($files, $cachePath);
}

/**
* Get an option from pug engine or default value.
*
* @param string $name
* @param null $default
*
* @return mixed|null
*/
public function getOption($name, $default = null)
{
if (method_exists($this->pug, 'hasOption') && !$this->pug->hasOption($name)) {
return $default;
}

return $this->pug->getOption($name);
}

/**
* @param string $cachePath
*/
Expand All @@ -51,7 +68,7 @@ public function setCachePath($cachePath)
*/
public function isExpired($path)
{
return !$this->pug->getOption('cache') || parent::isExpired($path);
return !$this->getOption('cache') || parent::isExpired($path);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
protected function setDefaultOption(Pug $pug, $name, $value)
{
if (method_exists($pug, 'hasOption') && !$pug->hasOption($name)) {
$pug->setCustomOption($name, call_user_func($value));

return;
}

try {
$pug->getOption($name);
} catch (\InvalidArgumentException $exception) {
Expand Down
4 changes: 4 additions & 0 deletions tests/PugBladeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function setPath($path)
class PugBladeCompilerTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers ::getOption
* @covers ::isExpired
* @covers ::__construct
*/
Expand Down Expand Up @@ -75,6 +76,7 @@ public function testIsExpired()
}

/**
* @covers ::getOption
* @covers ::compile
*/
public function testCompile()
Expand Down Expand Up @@ -102,6 +104,7 @@ public function testCompile()
}

/**
* @covers ::getOption
* @covers ::compile
*/
public function testGetAndSetPath()
Expand Down Expand Up @@ -147,6 +150,7 @@ public function testGetAndSetPath()
}

/**
* @covers ::getOption
* @covers ::setCachePath
*/
public function testSetCachePath()
Expand Down
1 change: 1 addition & 0 deletions tests/PugCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public function testGetAndSetPath()
}

/**
* @covers ::getOption
* @covers ::setCachePath
*/
public function testSetCachePath()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$version = implode(' ', array_slice($argv, 1));
list($laravelVersion, $pugVersion) = array_slice($argv, 1);

$composerFile = __DIR__ . '/../composer.json';
$composer = file_get_contents($composerFile);
Expand All @@ -9,11 +9,17 @@
foreach (array('illuminate/support', 'illuminate/view') as $package) {
$newContent = preg_replace(
'/"' . preg_quote($package, '/') . '"\s*:\s*"[^"]+"/',
'"' . $package . '": "' . $version . '"',
'"' . $package . '": "' . $laravelVersion . '"',
$newContent
);
}

$newContent = preg_replace(
'/' . preg_quote('"php": ">=5.4.0",') . '/',
'$0"pug-php/pug": "' . $pugVersion . '",',
$newContent
);

if ($newContent === $composer) {
echo 'illuminate/support and illuminate/view not found in ./composer.json';
exit(1);
Expand Down

0 comments on commit e14a19d

Please sign in to comment.