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: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Mustache for XP Framework ChangeLog

## ?.?.? / ????-??-??

## 9.0.0 / 2025-05-04

**Heads up:** Remove deprecated template loader infrastructure, see #8
(@thekid)
**Heads up:** Dropped support for PHP < 7.4, see xp-framework/rfc#343
(@thekid)
* Added PHP 8.5 to test matrix - @thekid
Expand Down
4 changes: 1 addition & 3 deletions src/main/php/com/github/mustache/Context.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ protected function helper($ptr, $segment) {
return $ptr;
} else if (is_object($ptr)) {
return method_exists($ptr, $segment)
? function($in, $ctx, $options) use($ptr, $segment) {
return $ptr->$segment($in, $ctx, $options);
}
? fn($in, $ctx, $options) => $ptr->$segment($in, $ctx, $options)
: null
;
} else {
Expand Down
24 changes: 10 additions & 14 deletions src/main/php/com/github/mustache/MustacheEngine.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace com\github\mustache;

use com\github\mustache\templates\{FromLoader, Source, Templates};
use com\github\mustache\templates\{Source, Templates};
use text\StringTokenizer;

/**
Expand All @@ -15,12 +15,12 @@
* ]);
* ```
*
* @test xp://com.github.mustache.unittest.EngineTest
* @test xp://com.github.mustache.unittest.RenderingTest
* @test xp://com.github.mustache.unittest.HelpersTest
* @test xp://com.github.mustache.unittest.SpecificationTest
* @see https://github.com/mustache/spec
* @see http://mustache.github.io/mustache.5.html
* @see https://github.com/mustache/spec
* @see http://mustache.github.io/mustache.5.html
* @test com.github.mustache.unittest.EngineTest
* @test com.github.mustache.unittest.RenderingTest
* @test com.github.mustache.unittest.HelpersTest
* @test com.github.mustache.unittest.SpecificationTest
*/
class MustacheEngine {
protected $templates, $parser;
Expand All @@ -37,15 +37,11 @@ public function __construct() {
/**
* Sets template loader to be used
*
* @param com.github.mustache.templates.Templates|com.github.mustache.TemplateLoader $l
* @param com.github.mustache.templates.Templates $l
* @return self this
*/
public function withTemplates($l) {
if ($l instanceof Templates) {
$this->templates= $l;
} else {
$this->templates= new FromLoader($l);
}
public function withTemplates(Templates $l) {
$this->templates= $l;
return $this;
}

Expand Down
20 changes: 0 additions & 20 deletions src/main/php/com/github/mustache/TemplateLoader.class.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/php/com/github/mustache/WithListing.class.php

This file was deleted.

47 changes: 0 additions & 47 deletions src/main/php/com/github/mustache/templates/FromLoader.class.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?php namespace com\github\mustache\templates;

use com\github\mustache\{TemplateLoader, WithListing};
use io\streams\MemoryInputStream;

/**
* Template loading
*
* @test xp://com.github.mustache.unittest.InMemoryTest
* @test xp://com.github.mustache.unittest.FileBasedTemplateLoaderTest
* @test xp://com.github.mustache.unittest.DeprecatedLoaderFunctionalityTest
* @test com.github.mustache.unittest.InMemoryTest
* @test com.github.mustache.unittest.FileBasedTemplateLoaderTest
*/
abstract class Templates implements TemplateLoader, WithListing {
abstract class Templates {

/**
* Load a template by a given name
Expand Down
48 changes: 0 additions & 48 deletions src/main/php/com/github/mustache/templates/Tokens.class.php

This file was deleted.

This file was deleted.

12 changes: 4 additions & 8 deletions src/test/php/com/github/mustache/unittest/EngineTest.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace com\github\mustache\unittest;

use com\github\mustache\{FilesIn, MustacheEngine, MustacheParser, NodeList, Template, TemplateLoader, TextNode, VariableNode};
use com\github\mustache\{FilesIn, InMemory, MustacheEngine, MustacheParser, NodeList, Template, TextNode, VariableNode};
use io\streams\{MemoryInputStream, MemoryOutputStream};
use test\{Assert, Test};

Expand Down Expand Up @@ -32,7 +32,7 @@ public function withHelpers_returns_engine() {
#[Test]
public function withHelper_returns_engine() {
$engine= new MustacheEngine();
$helper= function($text) { return '<b>'.$text.'</b>'; };
$helper= fn($text) => '<b>'.$text.'</b>';
Assert::equals($engine, $engine->withHelper('bold', $helper));
}

Expand All @@ -50,7 +50,7 @@ public function helpers_initially_empty() {

#[Test]
public function helpers_returns_aded_helper() {
$helper= function($text) { return '<b>'.$text.'</b>'; };
$helper= fn($text) => '<b>'.$text.'</b>';
$engine= (new MustacheEngine())->withHelper('bold', $helper);
Assert::equals(['bold' => $helper], $engine->helpers);
}
Expand All @@ -65,11 +65,7 @@ public function compile_template() {

#[Test]
public function load_template() {
$loader= newinstance(TemplateLoader::class, [], [
'load' => function($name) {
return new MemoryInputStream('Hello {{name}}');
}
]);
$loader= new InMemory(['test' => 'Hello {{name}}']);
Assert::equals(
new Template('test', new NodeList([new TextNode('Hello '), new VariableNode('name')])),
(new MustacheEngine())->withTemplates($loader)->load('test')
Expand Down
19 changes: 8 additions & 11 deletions src/test/php/com/github/mustache/unittest/HelpersTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use com\github\mustache\{MustacheEngine, VariableNode};
use test\{Assert, Test};
use util\Date;

class HelpersTest {

Expand All @@ -25,7 +26,7 @@ public function replace_single_variable() {
Assert::equals(
'Hello <b>World</b>',
$this->render('Hello {{#bold}}{{name}}{{/bold}}', ['name' => 'World'], [
'bold' => function($text) { return '<b>'.$text.'</b>'; }
'bold' => fn($text) => '<b>'.$text.'</b>'
])
);
}
Expand All @@ -35,7 +36,7 @@ public function replace_single_variable_with_node() {
Assert::equals(
'Hello World',
$this->render('Hello {{#var}}name{{/var}}', ['name' => 'World'], [
'var' => function($in) { return new VariableNode((string)$in); }
'var' => fn($in) => new VariableNode((string)$in)
])
);
}
Expand All @@ -46,8 +47,8 @@ public function dot_notation() {
'Hello world, this is BIG',
$this->render('Hello {{#case.lower}}World{{/case.lower}}, this is {{#case.upper}}big{{/case.upper}}', [], [
'case' => [
'lower' => function($text) { return strtolower($text); },
'upper' => function($text) { return strtoupper($text); }
'lower' => fn($text) => strtolower($text),
'upper' => fn($text) => strtoupper($text)
]
])
);
Expand All @@ -71,7 +72,7 @@ public function instance_method_as_helper() {
'My birthday @ 14.12.2013',
$this->render(
'My birthday @ {{#format.date}}{{date}}{{/format.date}}',
['date' => new \util\Date('14.12.2013 00:00:00')],
['date' => new Date('14.12.2013 00:00:00')],
['format' => new class() extends Value {
public function date($in, $context, $options) {
return $context->lookup($in->nodeAt(0)->name())->toString("d.m.Y");
Expand All @@ -86,9 +87,7 @@ public function log_section() {
Assert::equals(
'Hello [logged: info "Just a test"]',
$this->render('Hello {{#log info}}Just a test{{/log}}', [], [
'log' => function($in, $context, $options) {
return '[logged: '.$options[0].' "'.$in.'"]';
}
'log' => fn($in, $context, $options) => '[logged: '.$options[0].' "'.$in.'"]'
])
);
}
Expand All @@ -98,9 +97,7 @@ public function log_helper() {
Assert::equals(
'Hello [logged: info Just a test]',
$this->render('Hello {{log info "Just a test"}}', [], [
'log' => function($in, $context, $options) {
return '[logged: '.implode(' ', $options).']';
}
'log' => fn($in, $context, $options) => '[logged: '.implode(' ', $options).']'
])
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php namespace com\github\mustache\unittest;

use com\github\mustache\{MustacheParser, Node, NodeList};
use text\StringTokenizer;
use test\{Assert, Test, TestCase};
use text\StringTokenizer;

class ParserExtendingTest {

Expand Down
Loading
Loading