Skip to content

Commit

Permalink
Initiate a "Hooks and filters" section in documentation.
Browse files Browse the repository at this point in the history
Add explaination about before_render and before_exit
  • Loading branch information
Fabrice Luraine committed Oct 15, 2010
1 parent b987095 commit 2318fd2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
42 changes: 41 additions & 1 deletion README.mkd
Expand Up @@ -372,7 +372,12 @@ Output is temporized so that it can easily handle large files.

[TODO] `content_for($name); endcontent();`

## Before and after request ##
## Hooks and filters ##

Limonade allow the user to define some functions to enhance the Limonade behaviour with its own needs.

Some of those, like the `before` hook and the `after` filter are commonly used, and others are only for an advanced usage that might require a good comprehension of Limonade internals.


### Before ###

Expand Down Expand Up @@ -409,6 +414,29 @@ An `after` output filter is also available. It's executed after each request and

The current executed route is also available for `after` function.

### Before render ###

You can define a `before_render` function that will filter your view before rendering it.

function before_render($content_or_func, $layout, $locals, $view_path)
{
#
# The first three parameters are the same as those passed to the
# `render` function:
#
# - `$content_or_func`: the view string
# - `$layout`: current layout path
# - `$locals`: variables passed directly to the `render` function
#
# Last parameter, `$view_path` is by default
# `file_path(option('views_dir'), $content_or_func);`
#
# Transform $content_or_func, $layout, $locals or $view_path.
# Then return there new values
return array($content_or_func, $layout, $locals, $view_path);
}

### Autorender ###

You can define your own `autorender` function to make automatic rendering depending on current matching route. It will be executed if your controller returns a null output.
Expand All @@ -431,6 +459,18 @@ You can define your own `autorender` function to make automatic rendering depen

In this example, when url `/` is called, `hello()` is executed and then `autorender()` renders the matching `hello.html.php` view.

### Before exit ###

If you define a `before_exit`, it is called at the begining of the stop/exit process (`stop_and_exit` function called automatically at Limonade application termination).

function before_exit($exit)
{
# $exit is the same parameter as the one passed to `stop_and_exit`.
# If it's false, the exit process will not be executed,
# only the stop instructions
# by default it is true
}


## Configuration ##

Expand Down
6 changes: 1 addition & 5 deletions TODO
Expand Up @@ -6,8 +6,6 @@
### 0.5 ###

- complete CHANGES file
- explain controllers return output in README
- explain before_render() in README
- testing and documenting autorendering features
- write tests for partial()
- refactor partial()
Expand All @@ -25,15 +23,13 @@
- add a Getting Started section
- make the README hyper-simplified; acts as a resume, lits of features + and a table of content
- remove reference to html API: no time to maintain it and source code is enough. Maybe we can simply use a two-columns documentation generated with something like http://rtomayko.github.com/rocco/ ?
- in README, make a chapter about "callback controllers" after routes.
- in README, replace "controller functions" mentions with "callback controller"
- Add instructions about running tests
- adding contributors/thanks in AUTHORS


### 0.6 ###

- in README, add a section about hooks and user defined functions
- in README, complete the section about hooks and user defined functions
- add file controller feature
- a controller can be a file if controller callback string ending with '.php'
- this allow to push direcly the procedural code of the controller in a file, without declaring a controller function
Expand Down
2 changes: 1 addition & 1 deletion lib/limonade.php
Expand Up @@ -440,7 +440,7 @@ function autoload_controller($callback)
*/
function stop_and_exit($exit = true)
{
call_if_exists('before_exit');
call_if_exists('before_exit', $exit);
$flash_sweep = true;
$headers = headers_list();
foreach($headers as $header)
Expand Down
7 changes: 5 additions & 2 deletions lib/limonade/abstract.php
Expand Up @@ -134,16 +134,19 @@ function route_missing($request_method, $request_uri)
* Called before stoppping and exiting application.
*
* @abstract this function might be redefined by user
* @param boolean exit or not
* @return void
*/
function before_exit()
function before_exit($exit)
{

}

/**
* Rendering prefilter
* Rendering prefilter.
* Useful if you want to transform your views before rendering.
* The first three parameters are the same as those provided
* to the `render` function.
*
* @abstract this function might be redefined by user
* @param string $content_or_func a function, a file in current views dir or a string
Expand Down

0 comments on commit 2318fd2

Please sign in to comment.