mitsuhiko / jinja2-htmlcompress

Compresses HTML in Jinja2 streams
Other
129 stars 27 forks source link

Compresses javascript when it is %included%. #7

Open senyai opened 11 years ago

senyai commented 11 years ago

Like this:

<script type="text/javascript">
    {% include "script.js" %}
</script>
untitaker commented 11 years ago

I think that is out of the scope of this extension.

senyai commented 11 years ago

Example:


import jinja2, jinja2.loaders
from jinja2htmlcompress import HTMLCompress

TEMPLATE = """
<html>
    <title>Hello, world!</title>
    <script type="text/javascript">{% include "js.js" %}</script>
</html>
"""

JS = """
// sure, you will see the alert
alert("hello :)");
"""

loader = jinja2.loaders.DictLoader({'js.js': JS})

env = jinja2.Environment(
    extensions=[HTMLCompress],
    loader=loader,
)
print env.from_string(TEMPLATE).render().encode('utf-8')