Skip to content

Commit fabff11

Browse files
authored
Merge pull request #38 from magento-research/bug/trim-templates
Trim Partial Templates
2 parents 07abda4 + ce90a05 commit fabff11

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

src/Template/Mustache.php renamed to src/Template/Mustache/Engine.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
declare(strict_types=1);
88

9-
namespace Magento\Upward\Template;
9+
namespace Magento\Upward\Template\Mustache;
1010

11-
class Mustache implements TemplateInterface
11+
use Magento\Upward\Template\TemplateInterface;
12+
13+
class Engine implements TemplateInterface
1214
{
1315
/**
1416
* @var \Mustache_Engine
@@ -18,7 +20,7 @@ class Mustache implements TemplateInterface
1820
public function __construct(string $basePath)
1921
{
2022
$this->mustacheEngine = new \Mustache_Engine([
21-
'partials_loader' => new \Mustache_Loader_FilesystemLoader($basePath, ['extension' => 'mst']),
23+
'partials_loader' => new FileLoader($basePath, ['extension' => 'mst']),
2224
]);
2325
}
2426

src/Template/Mustache/FileLoader.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Upward\Template\Mustache;
10+
11+
class FileLoader extends \Mustache_Loader_FilesystemLoader
12+
{
13+
protected function loadFile($name)
14+
{
15+
return trim(parent::loadFile($name));
16+
}
17+
}

src/Template/TemplateFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Magento\Upward\Template;
1010

11+
use Magento\Upward\Template\Mustache\Engine as MustacheEngine;
12+
1113
class TemplateFactory
1214
{
1315
public const TEMPLATE_MUSTACHE = 'mustache';
@@ -16,7 +18,7 @@ class TemplateFactory
1618
* @var array map of template to renderer implementations
1719
*/
1820
private static $templateClasses = [
19-
self::TEMPLATE_MUSTACHE => Mustache::class,
21+
self::TEMPLATE_MUSTACHE => MustacheEngine::class,
2022
];
2123

2224
/**

test/Template/MustacheTest.php renamed to test/Template/Mustache/EngineTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66

77
declare(strict_types=1);
88

9-
namespace Magento\Upward\Test\Template;
9+
namespace Magento\Upward\Test\Template\Mustache;
1010

11-
use Magento\Upward\Template\Mustache;
11+
use Magento\Upward\Template\Mustache\Engine;
1212
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
1313
use PHPUnit\Framework\TestCase;
1414
use function BeBat\Verify\verify;
1515

16-
class MustacheTest extends TestCase
16+
class EngineTest extends TestCase
1717
{
1818
use MockeryPHPUnitIntegration;
1919

2020
public function testRender(): void
2121
{
22-
$mustacheEngine = new Mustache(__DIR__ . '/../_data');
22+
$mustacheEngine = new Engine(__DIR__ . '/../../_data');
2323
verify($mustacheEngine->render('{{> templates/template}}', ['variable' => 'custom variable']))
24-
->will()->contain('<h1>A Mustache Template with a custom variable</h1>');
24+
->will()->sameAs('<h1>A Mustache Template with a custom variable</h1>');
2525
}
2626
}

test/Template/TemplateFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Magento\Upward\Test\Template;
1010

11-
use Magento\Upward\Template\Mustache;
11+
use Magento\Upward\Template\Mustache\Engine;
1212
use Magento\Upward\Template\TemplateFactory;
1313
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
1414
use PHPUnit\Framework\TestCase;
@@ -20,7 +20,7 @@ class TemplateFactoryTest extends TestCase
2020

2121
public function testGetWithEngine(): void
2222
{
23-
verify(TemplateFactory::get(__DIR__, 'mustache'))->is()->instanceOf(Mustache::class);
23+
verify(TemplateFactory::get(__DIR__, 'mustache'))->is()->instanceOf(Engine::class);
2424
}
2525

2626
public function testGetWithInvalidEngine(): void
@@ -33,6 +33,6 @@ public function testGetWithInvalidEngine(): void
3333

3434
public function testGetWithoutEngine(): void
3535
{
36-
verify(TemplateFactory::get(__DIR__, null))->is()->instanceOf(Mustache::class);
36+
verify(TemplateFactory::get(__DIR__, null))->is()->instanceOf(Engine::class);
3737
}
3838
}

0 commit comments

Comments
 (0)