Browse code

moved the HTML extension to an external Composer package

Fabien Potencier authored on 08/08/2019 14:33:34
Showing 17 changed files
... ...
@@ -10,8 +10,11 @@ before_install:
10 10
 
11 11
 install:
12 12
     - travis_retry composer install
13
+    - (cd extra/html-extension && travis_retry composer install)
13 14
 
14
-script: ./vendor/bin/simple-phpunit
15
+script:
16
+    - ./vendor/bin/simple-phpunit
17
+    - (cd extra/html-extension && ./vendor/bin/simple-phpunit)
15 18
 
16 19
 jobs:
17 20
     fast_finish: true
... ...
@@ -1,7 +1,6 @@
1 1
 * 2.12.0 (2019-XX-XX)
2 2
 
3
- * added the "html_classes" function
4
- * added the "data_uri" filter
3
+ * added the HtmlExtension: "html_classes" function and "data_uri" filter
5 4
  * fixed cache when opcache is installed but disabled
6 5
  * fixed using macros in arrow functions
7 6
 
... ...
@@ -31,7 +31,6 @@
31 31
     "require-dev": {
32 32
         "symfony/phpunit-bridge": "^4.4@dev|^5.0",
33 33
         "symfony/debug": "^3.4|^4.2",
34
-        "symfony/mime": "^4.3",
35 34
         "psr/container": "^1.0"
36 35
     },
37 36
     "autoload": {
... ...
@@ -25,9 +25,15 @@ The ``data_uri`` filter generates a URL using the data scheme as defined in RFC
25 25
 .. note::
26 26
 
27 27
     The ``data_uri`` filter is part of the ``HtmlExtension`` which is not
28
-    enabled by default; you must add it explicitly on the Twig environment::
28
+    installed by default. Install it first:
29 29
 
30
-        use Twig\Extension\HtmlExtension;
30
+    .. code-block:: bash
31
+
32
+        $ composer req twig/html-extension
33
+
34
+     Then, add it on the Twig environment::
35
+
36
+        use Twig\Html\HtmlExtension;
31 37
 
32 38
         $twig = new \Twig\Environment(...);
33 39
         $twig->addExtension(new HtmlExtension());
... ...
@@ -18,9 +18,15 @@ names together:
18 18
 .. note::
19 19
 
20 20
     The ``html_classes`` function is part of the ``HtmlExtension`` which is not
21
-    enabled by default; you must add it explicitly on the Twig environment::
21
+    installed by default. Install it first:
22 22
 
23
-        use Twig\Extension\HtmlExtension;
23
+    .. code-block:: bash
24
+
25
+        $ composer req twig/html-extension
26
+
27
+     Then, add it on the Twig environment::
28
+
29
+        use Twig\Html\HtmlExtension;
24 30
 
25 31
         $twig = new \Twig\Environment(...);
26 32
         $twig->addExtension(new HtmlExtension());
27 33
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+vendor/
2
+composer.lock
3
+phpunit.xml
4
+.phpunit.result.cache
0 5
new file mode 100644
... ...
@@ -0,0 +1,19 @@
1
+Copyright (c) 2019 Fabien Potencier
2
+
3
+Permission is hereby granted, free of charge, to any person obtaining a copy
4
+of this software and associated documentation files (the "Software"), to deal
5
+in the Software without restriction, including without limitation the rights
6
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+copies of the Software, and to permit persons to whom the Software is furnished
8
+to do so, subject to the following conditions:
9
+
10
+The above copyright notice and this permission notice shall be included in all
11
+copies or substantial portions of the Software.
12
+
13
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+THE SOFTWARE.
0 20
new file mode 100644
... ...
@@ -0,0 +1,13 @@
1
+Twig HTML Extension
2
+===================
3
+
4
+This package is a Twig extension that provides the following:
5
+
6
+ * [`data_uri`][1] filter: generates a URL using the data scheme as defined in
7
+   RFC 2397;
8
+
9
+ * [`html_classes`][2] function: returns a string by conditionally joining class
10
+   names together.
11
+
12
+[1]: https://twig.symfony.com/doc/2.x/functions/html_classes.html
13
+[2]: https://twig.symfony.com/doc/2.x/filters/data_uri.html
0 14
new file mode 100644
... ...
@@ -0,0 +1,39 @@
1
+{
2
+    "name": "twig/html-extension",
3
+    "type": "library",
4
+    "description": "A Twig extension for HTML",
5
+    "keywords": ["twig", "html"],
6
+    "homepage": "https://twig.symfony.com",
7
+    "license": "MIT",
8
+    "authors": [
9
+        {
10
+            "name": "Fabien Potencier",
11
+            "email": "fabien@symfony.com",
12
+            "homepage": "http://fabien.potencier.org",
13
+            "role": "Lead Developer"
14
+        }
15
+    ],
16
+    "require": {
17
+        "php": "^7.1.3",
18
+        "twig/twig": "^2.4|^3.0"
19
+    },
20
+    "require-dev": {
21
+        "symfony/mime": "^4.3",
22
+        "symfony/phpunit-bridge": "^4.4@dev"
23
+    },
24
+    "autoload": {
25
+        "psr-4" : {
26
+            "Twig\\Html\\" : "src/"
27
+        }
28
+    },
29
+    "autoload-dev": {
30
+        "psr-4" : {
31
+            "Twig\\Html\\Tests\\" : "tests/"
32
+        }
33
+    },
34
+    "extra": {
35
+        "branch-alias": {
36
+            "dev-master": "2.12-dev"
37
+        }
38
+    }
39
+}
0 40
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+
3
+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
5
+         backupGlobals="false"
6
+         colors="true"
7
+         bootstrap="vendor/autoload.php"
8
+         failOnRisky="true"
9
+         failOnWarning="true"
10
+>
11
+    <php>
12
+        <ini name="error_reporting" value="-1" />
13
+    </php>
14
+
15
+    <testsuites>
16
+        <testsuite name="Twig HTML Extension Test Suite">
17
+            <directory>./tests/</directory>
18
+        </testsuite>
19
+    </testsuites>
20
+
21
+    <filter>
22
+        <whitelist>
23
+            <directory>./</directory>
24
+            <exclude>
25
+                <directory>./tests</directory>
26
+                <directory>./vendor</directory>
27
+            </exclude>
28
+        </whitelist>
29
+    </filter>
30
+</phpunit>
0 31
similarity index 98%
1 32
rename from src/Extension/HtmlExtension.php
2 33
rename to extra/html-extension/src/HtmlExtension.php
... ...
@@ -9,8 +9,9 @@
9 9
  * file that was distributed with this source code.
10 10
  */
11 11
 
12
-namespace Twig\Extension {
12
+namespace Twig\Html {
13 13
 use Symfony\Component\Mime\MimeTypes;
14
+use Twig\Extension\AbstractExtension;
14 15
 use Twig\TwigFilter;
15 16
 use Twig\TwigFunction;
16 17
 
17 18
similarity index 100%
18 19
rename from tests/Fixtures/filters/data_uri.test
19 20
rename to extra/html-extension/tests/Fixtures/data_uri.test
20 21
similarity index 100%
21 22
rename from tests/Fixtures/functions/html_classes.test
22 23
rename to extra/html-extension/tests/Fixtures/html_classes.test
23 24
similarity index 100%
24 25
rename from tests/Fixtures/functions/html_classes_with_unsupported_arg.test
25 26
rename to extra/html-extension/tests/Fixtures/html_classes_with_unsupported_arg.test
26 27
similarity index 100%
27 28
rename from tests/Fixtures/functions/html_classes_with_unsupported_key.test
28 29
rename to extra/html-extension/tests/Fixtures/html_classes_with_unsupported_key.test
29 30
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) Fabien Potencier
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+namespace Twig\Intl\Tests;
13
+
14
+use Twig\Html\HtmlExtension;
15
+use Twig\Test\IntegrationTestCase;
16
+
17
+class IntegrationTest extends IntegrationTestCase
18
+{
19
+    public function getExtensions()
20
+    {
21
+        return [
22
+            new HtmlExtension(),
23
+        ];
24
+    }
25
+
26
+    public function getFixturesDir()
27
+    {
28
+        return __DIR__.'/Fixtures/';
29
+    }
30
+}
... ...
@@ -13,7 +13,6 @@ namespace Twig\Tests;
13 13
 
14 14
 use Twig\Extension\AbstractExtension;
15 15
 use Twig\Extension\DebugExtension;
16
-use Twig\Extension\HtmlExtension;
17 16
 use Twig\Extension\SandboxExtension;
18 17
 use Twig\Extension\StringLoaderExtension;
19 18
 use Twig\Node\Expression\ConstantExpression;
... ...
@@ -44,7 +43,6 @@ class IntegrationTest extends IntegrationTestCase
44 43
             new SandboxExtension($policy, false),
45 44
             new StringLoaderExtension(),
46 45
             new TwigTestExtension(),
47
-            new HtmlExtension(),
48 46
         ];
49 47
     }
50 48