PHP Class Tale\Jade\Renderer

ファイルを表示 Open project: talesoft/tale-jade Class Usage Examples

Public Methods

Method Description
__construct ( array $options = null, Compiler $compiler = null, Parser $parser = null, Lexer $lexer = null ) Creates a new Tale Jade Renderer instance to render Jade files.
addFilter ( string $name, callable $callback ) Adds a new filter to the compiler.
addPath ( string $path ) Adds a path to the compiler to search files in.
compile ( string $input, string | null $path = null ) : mixed | string Compiles a Jade-string to PHTML.
compileFile ( string $path ) : mixed | string Compiles a file to PHTML.
getAdapter ( ) : AdapterBase Returns the adapter that actually renders the files.
getCompiler ( ) : Compiler Return the compiler instance used in this renderer instance.
getLexer ( ) : Lexer Returns the lexer used in this renderer instance.
getParser ( ) : Parser Returns the parser instance used in this renderer instance.
render ( string $file, array $args = null ) : string Renders a jade-file to a markup-string directly.

Method Details

__construct() public method

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 adapter_options: The option-array that gets passed to the adapter compiler: The compiler-options that get passed to the compiler parser_options: The parser-options that get passed to the parser lexer_options: 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
public __construct ( array $options = null, Compiler $compiler = null, Parser $parser = null, Lexer $lexer = null )
$options array the options to pass to the renderer
$compiler Compiler the compiler to use inside the renderer
$parser Parser the parser to use inside the compiler
$lexer Lexer the lexer to use inside the parser

addFilter() public method

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
public addFilter ( string $name, callable $callback )
$name string
$callback callable

addPath() public method

This is just a proxy for the addPath-method of the Compiler
public addPath ( string $path )
$path string the path to add

compile() public method

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 variables 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.
public compile ( string $input, string | null $path = null ) : mixed | string
$input string the jade input string
$path string | null the path for relative includes
return mixed | string A PHTML string containing HTML and PHP

compileFile() public method

The given path will automatically passed as compile()'s $path argument The path should always be relative to the paths-option paths
public compileFile ( string $path ) : mixed | string
$path string The path to the jade file
return mixed | string the compiled PHTML

getAdapter() public method

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
public getAdapter ( ) : AdapterBase
return Tale\Jade\Renderer\AdapterBase

getCompiler() public method

Return the compiler instance used in this renderer instance.
public getCompiler ( ) : Compiler
return Compiler

getLexer() public method

Returns the lexer used in this renderer instance.
public getLexer ( ) : Lexer
return Lexer

getParser() public method

Returns the parser instance used in this renderer instance.
public getParser ( ) : Parser
return Parser

render() public method

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 couldn'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
public render ( string $file, array $args = null ) : string
$file string the relative path to the file to render
$args array an array of variables to pass to the Jade-file
return string The renderered markup