1.3
A PHP package that attempts to mimic some of the unique qualities of slimrb.
Right now, I only have access to a linux box. This should have no problem working on MacOS or any BSD variants. Windows support is unknown as I haven't tested on that platform.
We use a Recursive Descent Parser to process the view's language grammar and then generate a PHP file from this intermediate syntax. Parsing only occurs once unless the file has been modified.
Code that utilizes this library must set config values using the Config class
<?php
require 'vendor/autoload.php';
/** These two lines are required */
\slenderize\Config::set('view_dir','/path/to/view_dir/');
\slenderize\Config::set('cache_dir','/path/to/cache_dir/');
Use the \slenderize\Page object to serve a page to the user
$page = new \slenderize\Page('my_view'); /* Open and parse /path/to/view_dir/my_view */
$page->view(); /* Will echo out the html generated */
/* Or you if you like code golf: */
new \slenderize\Page('my_view')->view();
All exceptions that are thrown by the \slenderize namespace inherit from \Exception, so you can simply catch \Exception
try {
$page = new \slenderize\Page('my_view');
}catch(\Exception $e){
/** handle exception here */
}
Indentation is required to open and close tags.
html
body
div|This is a div
p|this is a paragraph
The above code will generate the following html:
<html><body><div>This is a div<p>this is a paragraph</p></div></body></html>
The generated html is devoid of tab formatting to minimize memory footprint.
Literal strings start with the pipe character.
html
body
div|This is a literal string
Embedding variables is very similar to most webdev frameworks
html
body
{{$my_attributes}}
div|This is a div
The HTML that is generated by the above code snippet is dependant largely on what is in the variable $my_attributes.
Embedding static variables is just like in PHP
html
body
{{\My\Class::$my_static_var}}
div|This is a div
Objects can be passed to the Page and, while inside the view, an instance method can be called on that object.
html
body
{{$my_object->my_function()}}
div|This is a div
NOTE: Currently, there is no way to pass anything to functions.
Static calls are just like in PHP
html
body
{{\Foo\Bar\MyNamespace::my_function()}}
div|This is a div
NOTE: Currently, there is no way to pass anything to functions.
- Calling static methods
- Embedding static variables
- Embedding function calls into the view
- Variables that are objects and support for accessing properties
- Supporting array subscripting of variables
- simple if/else/elseif statements
- looping constructs