\Tale\JadeRenderer

Allows easy rendering of Jade-files to markup.

The renderer provides utilities to quickly render jade files to HTML/XML-output or/and to files

Usage example:

use Tale\Jade\Renderer;

$renderer = new Renderer();

echo $renderer->render('index');
//Where "index" is a "index.jade" jade source file

Summary

Methods
Properties
Constants
__construct()
getOptions()
getCompiler()
getParser()
getLexer()
addPath()
addFilter()
getAdapter()
compile()
compileFile()
render()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$_options
$_compiler
$_parser
$_lexer
$_adapter
N/A

Properties

$_options

$_options : array

The options-array for the renderer instance.

Type

array

$_compiler

$_compiler : \Tale\Jade\Compiler

The compiler that is used in this renderer instance.

Type

\Tale\Jade\Compiler

$_parser

$_parser : \Tale\Jade\Parser

The parser that is used in this renderer instance.

Type

\Tale\Jade\Parser

$_lexer

$_lexer : \Tale\Jade\Lexer

The lexer that is used in this renderer instance.

Type

\Tale\Jade\Lexer

$_adapter

$_adapter : \Tale\Jade\Renderer\AdapterBase

The adapter that actually renders the files in a dynamic manner.

Type

\Tale\Jade\Renderer\AdapterBase

Methods

__construct()

__construct(array|null  $options = null, \Tale\Jade\Compiler|null  $compiler = null, \Tale\Jade\Parser|null  $parser = null, \Tale\Jade\Lexer|null  $lexer = null) 

Creates a new Tale Jade Renderer instance to render Jade files.

Use the ->render() method on the resulting object to render your jade files

Possible options are:

adapter: The name of the adapter to use, either a short-name for an internal adapter or a class-name for a custom adapter adapterOptions: The option-array that gets passed to the adapter compiler: The compiler-options that get passed to the compiler parserOptions: The parser-options that get passed to the parser lexerOptions: The lexer options that get passed to the lexer

pretty: Compile with indentations and newlines (default: false) paths: The paths the compiler should search the jade files in

Parameters

array|null $options

the options to pass to the renderer

\Tale\Jade\Compiler|null $compiler

the compiler to use inside the renderer

\Tale\Jade\Parser|null $parser

the parser to use inside the compiler

\Tale\Jade\Lexer|null $lexer

the lexer to use inside the parser

getOptions()

getOptions() : array

Returns the current option-array used in this renderer instance.

Returns

array

getCompiler()

getCompiler() : \Tale\Jade\Compiler

Return the compiler instance used in this renderer instance.

Returns

\Tale\Jade\Compiler

getParser()

getParser() : \Tale\Jade\Parser

Returns the parser instance used in this renderer instance.

Returns

\Tale\Jade\Parser

getLexer()

getLexer() : \Tale\Jade\Lexer

Returns the lexer used in this renderer instance.

Returns

\Tale\Jade\Lexer

addPath()

addPath(string  $path) : $this

Adds a path to the compiler to search files in.

This is just a proxy for the addPath-method of the Compiler

Parameters

string $path

the path to add

Returns

$this

addFilter()

addFilter(string  $name, callable  $callback) : $this

Adds a new filter to the compiler.

The filter can be called inside jade via the :-syntax

The signature of the callback should be (Node $node, $indent, $newLine) where $node is the filter node that was encountered (including its children) and $indent and $newLine are indentation and the new line character as a string respecting the compiler's 'pretty' option

This is just a proxy for the Compiler's addFilter method

Parameters

string $name
callable $callback

Returns

$this

getAdapter()

getAdapter() : \Tale\Jade\Renderer\AdapterBase

Returns the adapter that actually renders the files.

This is lazy, meaning that the adapter gets created and stored as soon as the method is called the first time. After that all calls will return the same adapter instance

Returns

\Tale\Jade\Renderer\AdapterBase

compile()

compile(string  $input, string|null  $path = null) : mixed|string

Compiles a Jade-string to PHTML.

The result can then be evaluated, the best method is a simple PHP include

Use ->render() to get this done for you

Before evaluating you should set a $__args variable that will be passed through mixins. It like a global scope.

If you give it a path, the directory of that path will be used for relative includes.

Parameters

string $input

the jade input string

string|null $path

the path for relative includes

Returns

mixed|string —

A PHTML string containing HTML and PHP

compileFile()

compileFile(string  $path) : mixed|string

Compiles a file to PHTML.

The given path will automatically passed as compile()'s $path argument

The path should always be relative to the paths-option paths

Parameters

string $path

The path to the jade file

Throws

\Exception

when the file wasnt found or the compilation, lexing or parsing failed

Returns

mixed|string —

the compiled PHTML

render()

render(string  $file, array|null  $args = null) : string

Renders a jade-file to a markup-string directly.

This is the essence of the Jade-renderer and is the shortest and easiest way to get Jade running in your project

Notice that if your file wasn't found, you need to pass relative paths.

The paths will be relative from the compiler:paths option or from get_include_path(), if no paths have been defined

Parameters

string $file

the relative path to the file to render

array|null $args

an array of variables to pass to the Jade-file

Returns

string —

The renderered markup