2017 © Pedro Peláez
 

symfony-bundle twig-modify-bundle

Twig Minifier just you like.

image

phpmob/twig-modify-bundle

Twig Minifier just you like.

  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 8 % Grown

The README.md

TwigModifyBundle

TwigModify is a twig tag that can modifies everythink you want eg. cssmin, jsmin and more., (*1)

Installing

Installing via composer is recommended., (*2)

"require": {
  "phpmob/twig-modify-bundle": "~2.0"
}

Enabling

And then enable bundle in AppKernel.php, (*3)

public function registerBundles()
{
    $bundles = [
        ...
        new \PhpMob\TwigModifyBundle\PhpMobTwigModifyBundle(),
    ];
}

Usage

In order to modify your twig is simple just wrap {% modify modifier %}...{% modify %} like this:, (*4)

{% modify jsmin %}
    <script type="text/javascript">
        $(function() {
                ....
        });
    </script>
{% endmodify %}

That was it!, (*5)

Build-in Modifiers

There are supported modifiers in this bundle., (*6)

JSMin

A wrapped modifier for \JShrink\Minifier::minify, Thanks tedivm/jshrink, (*7)

{% modify jsmin %}
    <script type="text/javascript">
        $(function() {
                ....
        });
    </script>
{% endmodify %}

CSSMin

A wrapped modifier for \tubalmartin\CssMin\Minifier::minify, Thanks tubalmartin/cssmin, (*8)

{% modify cssmin %}
    <style type="text/css">
        body {
            color: red;
        }
    </style>
{% endmodify %}

HtmlPurify

A wrapped modifier for \HTMLPurifier::purify, Thanks ezyang/htmlpurifier, (*9)

{% modify htmlpurify %}
    <SCRIPT »
    SRC=http://ha.ckers.org/xss. »
    js></SCRIPT>
{% endmodify %}

AntiXss

A wrapped modifier for \voku\helper\AntiXSS, Thanks voku/anti-xss, (*10)

{% modify antixss %}
    {{ harm_string|raw }}
{% endmodify %}

Cache

TwigModifyBundle use local cache folder by default, however you can use any cache that implemented \Symfony\Component\Cache\Adapter\AdapterInterface interface and then change the confiuration for your cache service:, (*11)

phpmob_twig_modify:
    cache_adapter: "my_cache_adapter_service_id"

You can also use symfony framework-bundle cache adapter., (*12)

phpmob_twig_modify:
    cache_adapter: "cache.app"

Don't fogot enable DoctrineCacheBundle in your AppKernel.php - See https://symfony.com/doc/current/bundles/DoctrineCacheBundle/index.html, (*13)

Your own modifiers

You can add/override modifiers by easy configuration:, (*14)

phpmob_twig_modify:
    modifiers:
        xss: # a modifier name
            enabled: true # default true, toggle enable/disable this modifier.
            class: \PhpMob\TwigModifyBundle\Modifier\HTMLPurify # static class or any service
            method: purify # service method that's allowed to accept `[$content, (array) $options]
            options: # are array options you want to past into your modifier method - `\PhpMob\TwigModifyBundle\Modifier\HTMLPurify::purify` in this case.
                Cache.SerializerPath: "%kernel.cache_dir%/htmlpurify"

After that you already to use your new modifier., (*15)

 {% modify xss %}
     <SCRIPT »
     SRC=http://ha.ckers.org/xss. »
     js></SCRIPT>
 {% endmodify %}
 ```

## Configuration
Configuration reference:

```yaml
phpmob_twig_modify:
    # cache adapter serivce implemented `\Symfony\Component\Cache\Adapter\AdapterInterface` interface.
    cache_adapter: "my_cache_service_id"
    # application wide toggle enable/disable all modifiers
    enabled: true
    # custom/override modifiers (same key of modifier will override other previous defined)
    modifiers:
        name:
            class: ModifierClassOrService
            method: ModifierMethod
            options: ArrayOfSecondModifierMethod
            enabled: ToggleDisableEnable

Thanks

- https://github.com/nibsirahsieu/SalvaJshrinkBundle to nice demonstration.
- https://github.com/Exercise/HTMLPurifierBundle to nice demonstration.
- https://github.com/ezyang/htmlpurifier
- https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port
- https://github.com/tedious/JShrink
- https://github.com/voku/anti-xss

License

MIT, (*16)

The Versions

23/12 2017

1.1.3

1.1.3.0 http://github.com/phpmob/twig-modify-bundle

Twig Minifier just you like.

  Sources   Download

MIT

The Requires

 

The Development Requires

css javascript html minifier cssmin jsmin xss htmlpurify

23/12 2017

1.1.2

1.1.2.0 http://github.com/phpmob/twig-modify-bundle

Twig Minifier just you like.

  Sources   Download

MIT

The Requires

 

The Development Requires

css javascript html minifier cssmin jsmin xss htmlpurify

25/08 2017

1.1.1

1.1.1.0 http://github.com/phpmob/twig-modify-bundle

Twig Minifier just you like.

  Sources   Download

MIT

The Requires

 

The Development Requires

css javascript html minifier cssmin jsmin xss htmlpurify

23/08 2017

1.1.0

1.1.0.0 http://github.com/phpmob/twig-modify-bundle

Twig Minifier just you like.

  Sources   Download

MIT

The Requires

 

The Development Requires

css javascript html minifier cssmin jsmin xss htmlpurify

23/08 2017

1.0.0

1.0.0.0 http://github.com/phpmob/twig-modify-bundle

Twig Minifier just you like.

  Sources   Download

MIT

The Requires

 

The Development Requires

css javascript html minifier cssmin jsmin xss htmlpurify