windows/Rex
directory and they are usually rendered using compiler functions which can be compile()
or view()
functions. Rex files makes it easier to load and modify pages without having to write multiple codes. In spoova, there are
three types of template files. These files are : .css
extension while php and javascript assumes the .php
and .js
extensions respectively.
Rex files are mostly identified by the .rex
extension name which comes before the real extension name.
This means that whilst a php rex file uses a .rex.php
extension, the css files uses .rex.css
and javascript
files uses .rex.js
extension name. This naming pattern makes it easier to identify the rex files and the type of
code language each contains.
compile()
or view()
functions. When a compiler function is used, it take a first argument which defines
the path of a php rex file within the windows/Rex
directory. For example: namespace windows\Routes; use window; class Home extends Window { function __construct(){ self::load('index', fn() => compile() ); } }
load()
method will look for the index.rex.php
file within the
windows/Rex
directory. If such file exists, then the compiler function compile()
will
compile the rex template file.
#style:header .header{ background-color: red; } #style; #style:footer .footer{ width: 100%; } #style;
style()
directive. Only the css style names declared within the directive will be pulled into the php rex file.
. For example, assuming the css file above is located within the windows/Rex/Css
directory, then to import the css file above,
a php rex file will contain the following code:
style('css.index:header');
somefile.rex.php
is compiled, the compiler will extract css styles
from windows/Rex/css/index.rex.css
. Only the styles within the header section will be extracted.
The compiled data will resemble the code below:
<style rel="css.index"> .header{ background-color: red; } </style>
rel
attribute helps to reveal the path of the css file as it can become difficult to locate stylesheet
files when working on large projects. The path shown in the rel
attribute is usually a path within the
windows/Rex
directory. In certain situations we can import multiple styles from a single css file. This
can be done by first defining the file path, then each style section is extracted by their unique names. The unique names
in this case will be separated by columns. For example, the code below is an example of multiple style extraction from a single css
file. Both the footer
and header
styles will be imported as the compiled data.
style('css.index:header:footer');
script()
. In js rex files, scripts are also divided into sections with each section having its own unique name.
An example below shows the format of a js rex file #script:header window.onload = function() { alert('loaded'); } #script;
"windows/Rex/js/"
directory, then we can import the file as shown below:
script('js.index:header')
windows/Rex/js/index.rex.php
. The data compiled from the file above will be as below:
<script> window.onload = function() { alert('loaded'); } <script>