Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Oct 11, 2017
1 parent 4dfdf3c commit 49c2d34
Show file tree
Hide file tree
Showing 2 changed files with 393 additions and 5 deletions.
86 changes: 81 additions & 5 deletions src/Phug/Phug.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ private static function getOptions(array $options = [])
/**
* Get options from extensions list and default options.
*
* @param array $extensions
* @param array $options
* @param array $extensions list of extensions instances of class names
* @param array $options optional default options to merge with
*
* @return array
*/
Expand Down Expand Up @@ -107,7 +107,10 @@ public static function getExtensionsOptions(array $extensions, array $options =
/**
* Set the engine class used to render templates.
*
* @param $rendererClassName
* @example Phug::setRendererClassName(\Tale\Pug\Renderer::class)
* @example Phug::setRendererClassName(\Pug\Pug::class)
*
* @param string $rendererClassName class name of the custom renderer engine
*/
public static function setRendererClassName($rendererClassName)
{
Expand All @@ -117,8 +120,10 @@ public static function setRendererClassName($rendererClassName)
/**
* Cleanup previously set options.
*
* @param $path
* @param $options
* @example Phug::removeOptions(['filters'], ['coffee' => null]])
*
* @param array $path option base path
* @param mixed $options options to remove
*/
public static function removeOptions($path, $options)
{
Expand Down Expand Up @@ -149,6 +154,8 @@ public static function reset()
/**
* Get a renderer with global options and argument options merged.
*
* @example Phug::getRenderer([])
*
* @param array $options
*
* @return Renderer
Expand All @@ -168,6 +175,8 @@ public static function getRenderer(array $options = [])
}

/**
* Return a rendered Pug template string.
*
* @param string $input pug source
* @param array $parameters variables values
* @param array $options custom options
Expand All @@ -180,6 +189,8 @@ public static function render($input, array $parameters = [], array $options = [
}

/**
* Return a rendered Pug file.
*
* @param string $path path to template
* @param array $parameters variables values
* @param array $options custom options
Expand All @@ -192,6 +203,8 @@ public static function renderFile($path, array $parameters = [], array $options
}

/**
* Display a rendered Pug template string. By default, it means HTML output to the buffer.
*
* @param string $input pug source
* @param array $parameters variables values
* @param array $options custom options
Expand All @@ -202,6 +215,8 @@ public static function display($input, array $parameters = [], array $options =
}

/**
* Display a rendered Pug file. By default, it means HTML output to the buffer.
*
* @param string $path path to template
* @param array $parameters variables values
* @param array $options custom options
Expand All @@ -212,6 +227,8 @@ public static function displayFile($path, array $parameters = [], array $options
}

/**
* Check if a filter is available globally.
*
* @param string $name
*
* @return bool
Expand All @@ -222,6 +239,8 @@ public static function hasFilter($name)
}

/**
* Get a global filter by name.
*
* @param string $name
*
* @return callable
Expand All @@ -232,8 +251,13 @@ public static function getFilter($name)
}

/**
* Set a filter to the Phug facade (will be available in the current renderer instance and next static calls).
* Throws an exception if the filter is not callable and do not have a parse method.
*
* @param string $name
* @param callable|string $filter
*
* @throws PhugException
*/
public static function setFilter($name, $filter)
{
Expand All @@ -256,8 +280,12 @@ class_exists($filter) ||
}

/**
* Add a filter. Throws an exception if the name is already taken.
*
* @param string $name
* @param callable|string $filter
*
* @throws PhugException
*/
public static function addFilter($name, $filter)
{
Expand All @@ -273,8 +301,12 @@ public static function addFilter($name, $filter)
}

/**
* Replace a filter. Throws an exception if the name is set.
*
* @param string $name
* @param callable|string $filter
*
* @throws PhugException
*/
public static function replaceFilter($name, $filter)
{
Expand All @@ -290,6 +322,8 @@ public static function replaceFilter($name, $filter)
}

/**
* Remove a filter from the Phug facade (remove from current renderer instance).
*
* @param string $name
*/
public static function removeFilter($name)
Expand All @@ -306,6 +340,8 @@ public static function removeFilter($name)
}

/**
* Get filters list added through the Phug facade.
*
* @return array
*/
public static function getFilters()
Expand All @@ -314,6 +350,8 @@ public static function getFilters()
}

/**
* Check if a keyword is available globally.
*
* @param string $name
*
* @return bool
Expand All @@ -324,6 +362,8 @@ public static function hasKeyword($name)
}

/**
* Get a global custom keyword by name.
*
* @param string $name
*
* @return callable
Expand All @@ -334,8 +374,13 @@ public static function getKeyword($name)
}

/**
* Set a keyword to the Phug facade (will be available in the current renderer instance and next static calls).
* Throws an exception if the keyword is not callable.
*
* @param string $name
* @param callable|string $keyword
*
* @throws PhugException
*/
public static function setKeyword($name, $keyword)
{
Expand All @@ -354,8 +399,12 @@ public static function setKeyword($name, $keyword)
}

/**
* Add a keyword. Throws an exception if the name is already taken.
*
* @param string $name
* @param callable|string $keyword
*
* @throws PhugException
*/
public static function addKeyword($name, $keyword)
{
Expand All @@ -371,8 +420,12 @@ public static function addKeyword($name, $keyword)
}

/**
* Replace a keyword. Throws an exception if the name is set.
*
* @param string $name
* @param callable|string $keyword
*
* @throws PhugException
*/
public static function replaceKeyword($name, $keyword)
{
Expand All @@ -388,6 +441,8 @@ public static function replaceKeyword($name, $keyword)
}

/**
* Remove a keyword from the Phug facade (remove from current renderer instance).
*
* @param string $name
*/
public static function removeKeyword($name)
Expand All @@ -404,6 +459,8 @@ public static function removeKeyword($name)
}

/**
* Get keywords list added through the Phug facade.
*
* @return array
*/
public static function getKeywords()
Expand All @@ -412,6 +469,8 @@ public static function getKeywords()
}

/**
* Check if an extension is available globally.
*
* @param string $extensionClassName
*
* @return bool
Expand All @@ -428,7 +487,12 @@ public static function hasExtension($extensionClassName)
}

/**
* Add an extension to the Phug facade (will be available in the current renderer instance and next static calls).
* Throws an exception if the extension is not a valid class name.
*
* @param string $extensionClassName
*
* @throws PhugException
*/
public static function addExtension($extensionClassName)
{
Expand All @@ -449,6 +513,8 @@ public static function addExtension($extensionClassName)
}

/**
* Remove an extension from the Phug facade (remove from current renderer instance).
*
* @param string $extensionClassName
*/
public static function removeExtension($extensionClassName)
Expand All @@ -470,13 +536,23 @@ public static function removeExtension($extensionClassName)
}

/**
* Get extensions list added through the Phug facade.
*
* @return array
*/
public static function getExtensions()
{
return self::$extensions;
}

/**
* All dynamic methods from the renderer can be called statically with Phug facade.
*
* @param $name
* @param $arguments
*
* @return mixed
*/
public static function __callStatic($name, $arguments)
{
return call_user_func_array([static::getRenderer(), $name], $arguments);
Expand Down
Loading

0 comments on commit 49c2d34

Please sign in to comment.