Skip to content

Commit c1576a8

Browse files
Merge pull request #25 from wmde/#nofilter
Remove support for Vue 2 filters
2 parents de09024 + fd5a29c commit c1576a8

21 files changed

+103
-706
lines changed

README.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
# VueJS templating implementation in PHP
22

3-
Simple PHP implementation of the [Vue Template](https://vuejs.org/v2/guide/syntax.html) renderer.
3+
Simple PHP implementation of the [Vue Template](https://vuejs.org/guide/essentials/template-syntax.html) renderer.
44

55
The library has been created to be used for rendering templates
66
in the [Wikibase Lexeme extension](https://www.mediawiki.org/wiki/Extension:WikibaseLexeme).
77
It intentionally covers only a subset of Vue Template syntax that is used by the Wikibase
88
Lexeme extension. It is not going to cover all elements of Vue Template language.
99

10-
## Migration notes
11-
12-
For the purpose of migrating to Vue 3, very basic support for the method syntax was added as an alternative to filters.
13-
In order to keep the interface stable, method callbacks should also be provided as the third parameter when calling
14-
`Templating::render()`.
15-
1610
## Installation
1711

1812
The recommended way of installing the library is using [Composer](https://getcomposer.org),
1913
e.g. by adding the following line to the `require` section of the `composer.json` file:
2014

2115
```
22-
"wmde/php-vuejs-templating": "^1.1.0"
16+
"wmde/php-vuejs-templating": "^2.0.0"
2317
```
2418

2519
## Tests

package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
22
"name": "php-vuejs-templating",
3-
"dependencies": {},
43
"devDependencies": {
5-
"vue": "^2.3.4",
6-
"vue-server-renderer": "^2.3.4",
7-
"cheerio": "^0.22.0"
4+
"cheerio": "^0.22.0",
5+
"vue": "^3.2.41"
86
},
97
"scripts": {
108
"populate-fixtures": "node tests/integration/populate_fixtures_with_expected_results.js"

src/Component.php

+5-17
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,29 @@
1212
use Exception;
1313
use LibXMLError;
1414

15-
use WMDE\VueJsTemplating\FilterExpressionParsing\FilterParser;
1615
use WMDE\VueJsTemplating\JsParsing\BasicJsExpressionParser;
1716
use WMDE\VueJsTemplating\JsParsing\CachingExpressionParser;
1817
use WMDE\VueJsTemplating\JsParsing\JsExpressionParser;
1918

2019
class Component {
2120

22-
private $filterParser;
23-
2421
/**
2522
* @var string HTML
2623
*/
2724
private $template;
2825

29-
/**
30-
* @var callable[]
31-
*/
32-
private $filters = [];
33-
3426
/**
3527
* @var JsExpressionParser
3628
*/
3729
private $expressionParser;
3830

3931
/**
4032
* @param string $template HTML
41-
* @param callable[] $filters
33+
* @param callable[] $methods
4234
*/
43-
public function __construct( $template, array $filters ) {
35+
public function __construct( $template, array $methods ) {
4436
$this->template = $template;
45-
$this->filters = $filters;
46-
$this->expressionParser = new CachingExpressionParser( new BasicJsExpressionParser() );
47-
$this->filterParser = new FilterParser();
37+
$this->expressionParser = new CachingExpressionParser( new BasicJsExpressionParser( $methods ) );
4838
}
4939

5040
/**
@@ -161,8 +151,7 @@ private function replaceMustacheVariables( DOMNode $node, array $data ) {
161151
preg_match_all( $regex, $text, $matches );
162152

163153
foreach ( $matches['expression'] as $index => $expression ) {
164-
$value = $this->filterParser->parse( $expression )
165-
->toExpression( $this->expressionParser, $this->filters )
154+
$value = $this->expressionParser->parse( $expression )
166155
->evaluate( $data );
167156

168157
$text = str_replace( $matches[0][$index], $value, $text );
@@ -182,8 +171,7 @@ private function handleAttributeBinding( DOMElement $node, array $data ) {
182171
continue;
183172
}
184173

185-
$value = $this->filterParser->parse( $attribute->value )
186-
->toExpression( $this->expressionParser, $this->filters )
174+
$value = $this->expressionParser->parse( $attribute->value )
187175
->evaluate( $data );
188176

189177
$name = substr( $attribute->name, 1 );

src/FilterExpressionParsing/FilterCall.php

-43
This file was deleted.

src/FilterExpressionParsing/FilterParser.php

-192
This file was deleted.

0 commit comments

Comments
 (0)