r3c / deval

Deferred Evaluation Templates

Home Page:http://deval.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deval: Deferred Evaluation Templates

Build Status license

Overview

Deval is a PHP template engine with support for partial evaluation at compilation to enable early error detection, optimize generated code and improve execution performance.

While most PHP template engines follow a “load variables and render” workflow Deval introduces an intermediate pre-compilation injection step to specify variables that you know won’t change on every rendering. By doing so, Deval will pre-evaluate your template and generate specialized code where all these invariants have been evaluated.

This sample template:

{{ $ locale(language, "users.list") }}
{{ for user in users }}
    - {{ $ user.login }}
{{ empty }}
    {{ $ locale(language, "no.users") }}
{{ end }}

Will compile a PHP snippet similar to this one after injecting a locale function and a language variable:

Registered user:
<?php $_counter = 0; foreach ($users as $user) { ?>
    - <?php echo $user->login; ?>
<?php ++$_counter; } if ($_counter === 0) { ?>
    No users registered.
<?php } ?>

As you can see all statements depending on variables locale and language have been evaluated in generated code, as their value was known at compile time. Other variables have been left untouched and Deval expects you to specify their value when rendering the template (and will raise an error if you don’t).

Instructions

Download latest release from GitHub.

Full documentation is available on Read the Docs.

Resource

  • Contact: v.github.com+deval [at] mirari [dot] fr
  • License: license.md

About

Deferred Evaluation Templates

http://deval.readthedocs.io/

License:MIT License


Languages

Language:PHP 92.1%Language:PEG.js 7.2%Language:JavaScript 0.4%Language:Shell 0.3%