2.0+
Compiler Engine
Spoova's compiler engine have been updated for more functionalities. In the previous versions only two compiler functions were used to compile template files which are the "compile" and "view()" functions. The limitation of the "compile" function is that it cannot be used more than once within a window call. Both of these methods have been redefined and while the "compile" returns a string previously, the new update now returns an object of the Compiler class. This makes it easier to extend its functionalities and also makes it possible to run the compiler functions more than once. With the new updates and added functionalities to version 2.0, template compilers now become easier to use.

Compile string argument (2.0+)

The compiler function now uses strings as rex file paths starting from version 2.0 upwards

namespace spoova/mi/windows/Routes;

use Window;
use spoova/mi/core/classes/Ajax;

class Home extends Window { 

    function __construct() {

        $Ajax = new Ajax;
        $myArray = [1,2,3];

        self::load('home', fn() => compile('user.home') );

    }

}
    
In the example above, the compiler function "compile" above will render its string argument as a rex template file into the supplied storage file name "home". Hence, the file "core/storage/home.php" will be the storage file name while "windows/Rex/user/home.rex.php" is the template file itself. However, if a string argument is not supplied, the self::load() method will assume that the file name "home" (i.e windows/Rex/home.rex.php) supplied is the intended rex template file. file.


Compile Similarities (2.0 <)

The former behaviour of compile function with array arguments still remains the same

namespace windows/Routes;

class Home { 

    function __construct() {

        self::load('sample_file', fn() => compile(['name'=>'foo']));

    }

}
    
In the example above, the compile function will still be able to pass variables to the template file because array are used as variable containers.


Compile Improvements

Previously, the compiler function does not exist as a stand-alone function. It needs to be used within the Res::load() or a window's "self::load()" method. The new updates now ensures that the compile() function can exist as a stand alone.

namespace spoova/mi/windows/Routes;

use Window;

class Home extends Window{ 

    function __construct() {

       echo compile('sample', ['name'=> 'foo']);

    }

}
    
In the example above, the compile function will render the "windows/Rex/sample.rex.php" file and the content will be printed to the page. The compile function returns a compiler object and without printing the content, the file will not be fully rendered. However, because the compiler is now an object, it makes it possible to manage our template files before finally being displayed as a view. For example, we can fetch our raw page and do some other things to them before finally rendering the page.


Compiler Class

Since the compile function returns a Compiler object, it is only natural that we discuss the Compiler class itself. Compiler class introduced in spoova 2.0 version, is the template engine class that helps to render the rex template files in a structured form providing some form of flexibility in the way template files are managed and rendered. The following code lines reveals how to render a rex template from the compiler class:

namespace spoova/mi/windows/Routes;

use Window;
use spoova/mi/core/classes/Compiler;

class Home extends Window { 

    function __construct() {

       $args = ['name' => 'foo'];

       $Compiler = new Compiler('sample', $args);
      
       $Compiler->compile(); //compile and print page

    }

}
    
In the example above, the compile function will render the "windows/Rex/sample.rex.php" file and the content will be printed to the page. The supplied variables will also be passed to the template file while the compile() method will compile the entire file and render the content on the webpage. There are also other activities we can perform with this class. For more details about the compiler class, visit here.


Template Rendering
A major change has been made to directive comments. Previously, when a comment @()@ is used, it is usually resolved as a single "at" sign @. So a template directive @(domurl())@ will be resolved as @domurl(). The scope of this comment has been expanded which calls for remodification as it is not only used for directives anymore. Contrary to the previous behaviour the new behaviour will return its direct content. This means that an additional "at" sign will no longer be added by default. Hence, @(domurl())@ for example, will now return domurl() while @(@domurl())@ will now return @domurl(). The following samples reflect the new behaviour:

Comment (sample)Response
@(domurl())@domurl()
@(@domurl())@@domurl()
@({{}})@{{}}