Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
name: PHP

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -29,7 +29,7 @@ jobs:

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-${{ matrix.setup }}-v2-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
setup: ['lowest', 'stable']

name: PHP ${{ matrix.php }} - ${{ matrix.setup }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -29,7 +29,7 @@ jobs:

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-${{ matrix.setup }}-v2-php-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@
"psr-4": {
"": "./src"
}
},
"config": {
"allow-plugins": {
"nodejs-php-fallback/nodejs-php-fallback": true
}
}
}
4 changes: 2 additions & 2 deletions src/Phug/Formatter/AbstractTwigFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ protected function replaceTwigTemplateBlocks($input, $wrap)
$hasBlocks = false;
$input = $this->restoreBlockSubstitutes($input, ' %%}%s{%% ', $hasBlocks);
if ($hasBlocks) {
$statement = preg_replace('/^([^\\{]+)\\{.*$/', '$1', $statement);
$statement = preg_replace('/^([^{]+)\{.*$/', '$1', $statement);
if (in_array($statement, $this->statements)) {
$input .= 'end'.preg_replace('/^else/', 'if', $statement);
$input .= 'end'.preg_replace('/^(?:elseif|else)/', 'if', $statement);
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/PugToTwigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,21 @@ public static function testFlagAttribute()
);
}

public function testElseIf()
{
$html = static::compile(implode("\n", [
'- if foo',
' div Condition one',
'- elseif bar',
' div Another condition',
]));

self::assertSame(
'{% if foo %}<div>Condition one</div>{% elseif bar %}<div>Another condition</div>{% endif %}',
$html
);
}

/**
* @covers \Phug\Formatter\Format\TwigXmlFormat::isSelfClosingTag
* @covers \Phug\Formatter\Format\TwigXmlFormat::isBlockTag
Expand Down Expand Up @@ -331,7 +346,9 @@ public static function testXmlDoctype()

/**
* @covers \Phug\Formatter\Format\TwigXmlFormat::isSelfClosingTag
*
* @expectedException \Phug\FormatterException
*
* @expectedExceptionMessage input is a self closing element: <input/> but contains nested content
*/
public static function testNestedInSelfClosing()
Expand All @@ -341,7 +358,9 @@ public static function testNestedInSelfClosing()

/**
* @covers \Phug\Formatter\Format\TwigXmlFormat::isSelfClosingTag
*
* @expectedException \Phug\FormatterException
*
* @expectedExceptionMessage input is a self closing element: <input/> but contains nested content
*/
public static function testMissingAssignment()
Expand Down