-
Notifications
You must be signed in to change notification settings - Fork 0
Exemplar
Welcome to the Exemplar Engine, my (personal) gold standard for what a template engine should be!
I don't personally have a lot of time to edit this, so here's a quick getting started guide:
The quick rundown:
- PHP constants are requested
[!likeThis]
by default. - Variables set with setVariable() are requested
[@likeThis]
by default. - Files can be added to the template using
[#fileName.ext]
by default. - Finally, tables are called upon with
[*fileName.ext:variable/constant]
.
Tables are slightly more complicated than the other tags, as they are 2 pieces, split by a colon(by default.) The first half, *fileName.ext
, simply is a file path to a table file. This table file will have ^
tags, like below. These tags are replaced by an array value, either automatically incremented(^
alone), or a supplied array position(^position
.)
<th>[^]</th>
<th>[^position]</th>
The second half must either be a variable or a constant, otherwise the table does not work. The supplied constant/variable must also be a 2-dimensional array. Each first dimension of the array becomes the table's input. The second dimension of the array is the supplied inputs.
Chaining and piping, or just piping if you want a shorthand, refers to two different actions. Piping is to read a file and use it as input, while chaining is using a variable or constant as an input. You can very easy do it with tags by simply requesting a constant, variable, or file directly after the starting position.
[#@likeThis]
is requesting a file with the name stored within the variable likeThis
.
Similarly, [@!likeThis]
is requesting a variable, the name is stored within the constant likeThis
.
You can even chain them together, [@#!likeThis]
! That requests a variable, whose name is stored in a file, which is pointed to by the constant likeThis
!
Less a method, more of the constructor of the class. This takes the $file input, and opens it as a template!
This method will return you a string, where the entire file is put together. You can then output it as an echo.
This method dumps the constant and variable requests, and then executes an internally called varFile() to refill the two tables. You may be calling this a lot with piping!
This method allows you to fulfill a variable request. If safe insertion is on, then it needs to have been requested by the file prior. If you have multiple chained ones in a row, then you will probably need to call refreshRequests() at least a few times.
Returns the requested variable names!
Returns the requested constant names!
Returns the already set variable values!
This method will purge any variable values that have not been requested. Due to the nature of refreshRequests(), this is a bit dangerous to work.
For various reasons, these functions may change name at any time, and are not accessible to those outside of the class.
Called once, by the constructor. A simple setup for the requests lists, and executes varFile() once.
Cleans out duplicate files.
Either retrieves a constant, variable, or file contents and returns it. Used when resolving chains and pipes.
The interpreter which compiles files into strings which are then output by construct().
A mini-interpreter for table files.
Gets the file from first the relative to template, script, and finally absolute. Returns null if it gets nothing.
The interpreter which puts the requests in their respective lists.
I was a bit too hasty to celebrate the parsers working, so the following functions hold absolutely 0 purpose in their current state.
- garbage()
- preen()
Oops.