Add STRIP option

This commit is contained in:
bzick
2014-05-08 12:56:37 +04:00
parent 83e02ebbe9
commit 45afbfabdf
12 changed files with 209 additions and 87 deletions

71
docs/start.md Normal file
View File

@@ -0,0 +1,71 @@
Basic usage
===========
## Install Fenom
### Composer
Add package Fenom in your require-list in `composer.json`:
```json
{
"require": {
"fenom/fenom": "2.*"
}
}
```
and update project's dependencies: `composer update`.
### Custom loader
Clone Fenom to any directory: `git clone https://github.com/bzick/fenom.git`. Recommended use latest tag.
Fenom use [psr-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md#autoloading-standard) autoloading standard. Therefore you can
* use `psr-0` format in your project loader for loading Fenom's classes
* or register Fenom's autoloader: ```php
Fenom::registerAutoload();
```
For loading itself.
Also you can use this autoloader for loading any library with `psr-0` file naming:
```php
Fenom::registerAutoload(PROJECT_DIR."/src");
```
## Setup Fenom
Create an object via factory method
```php
$fenom = Fenom::factory('/path/to/templates', '/path/to/compiled/template', $options);
```
Create an object via `new` operator
```php
$fenom = new Fenom(new Provider('/path/to/templates'));
$fenom->setCompileDir('/path/to/template/cache');
$fenom->setOptions($options);
```
* `/path/to/templates` — directory, where stores your templates.
* `/path/to/template/cache` — directory, where stores compiled templates in PHP files.
* `$options` - bit-mask or array of [Fenom settings](./docs/settings.md).
### Use Fenom
Output template
```php
$fenom->display("template/name.tpl", $vars);
```
Get the result of rendering the template
```php
$result = $fenom->fetch("template/name.tpl", $vars);
```
Create the pipeline of rendering into callback
```php
$fenom->pipe(
"template/sitemap.tpl",
$vars,
$callback = [new SplFileObject("/tmp/sitemap.xml", "w"), "fwrite"], // pipe to file /tmp/sitemap.xml
$chunk_size = 1e6 // chunk size for callback
);
```

View File

@@ -1,11 +1,61 @@
Syntax [RU]
===========
Syntax
======
Fenom implement [Smarty](http://www.smarty.net/) syntax with some improvements
Fenom implements [Smarty](http://www.smarty.net/) syntax with some improvements.
All Fenom tags enclosed in the delimiters `{` and `}`, for example `{var $five = 5}`.
If you wanna leave delimiters as is in the template use [special statements or tags](#ignoring-delimiters).
*Note*
Fenom implements [Smarty](http://www.smarty.net/) syntax but not implements Smarty tags, however, some tags very similar.
But not so bad, Fenom has the [extras](https://github.com/bzick/fenom-extra) that make Fenom like Smarty.
## Variable
### Use variables
Variables in Fenom can be either displayed directly or used as arguments for functions, attributes and modifiers,
inside conditional expressions, etc.
### Example variables
Next example uses simple variables `$user_id` ans `$user_name`
```smarty
<div class="user">Hello, <a href="/users/{$user_id}">{$user_name}</a>.</div>
```
Example outputs next HTML code:
```html
<div class="user">Hello, <a href="/users/17">Bzick</a>.</div>
```
Переменные могут быть массивом. В этом случае обращение по ключу происходит через опертор `.` или, как в PHP, через операторы `[` и `]`
```smarty
<div class="user">Hello, <a href="/users/{$user.id}">{$user.name}</a>.</div>
```
`{$user.id}` and `{$user['id']}` are same.
```smarty
<div class="user">Hello, <a href="/users/{$user->id}">{$user->name}</a>.</div>
```
```smarty
<div class="user">Hello, <a href="/users/{$user->getId()}">{$user->getName()}</a>.</div>
```
*Note*
Be careful, Fenom do not checks existence of the method before invoke.
To avoid the problem class of the object have to define method `__call`, which throws an exception etc.
Also you may disable invoke method in [settings](./docs/settings.md).
Multidimensional value support
```smarty
{$foo.bar.baz}
{$foo.$bar.$baz}
{$foo[4].baz}
{$foo[4].$baz}
{$foo.bar.baz[4]}
{$foo[ $bar.baz ]}
```
```smarty
{$foo}
@@ -25,7 +75,7 @@ Fenom implement [Smarty](http://www.smarty.net/) syntax with some improvements
### System variable
Unnamed system variable starts with `$.` and allow access to global variables and system info (fix doc):
Unnamed system variable starts with `$.` and allows access to global variables and system info (fix doc):
* `$.get` is `$_GET`.
* `$.post` is `$_POST`.
@@ -47,17 +97,6 @@ Unnamed system variable starts with `$.` and allow access to global variables an
{/if}
```
### Multidimensional value support
```smarty
{$foo.bar.baz}
{$foo.$bar.$baz}
{$foo[4].baz}
{$foo[4].$baz}
{$foo.bar.baz[4]}
{$foo[ $bar.baz ]}
```
### Math operations
```smarty

View File

@@ -1,38 +0,0 @@
Basic usage
===========
### Initialize Fenom
Creating an object via factory method
```php
$fenom = Fenom::factory('/path/to/templates', '/path/to/compiled/template', $options);
```
Creating an object via `new` operator
```php
$fenom = new Fenom(new Provider('/path/to/templates'));
$fenom->setCompileDir('/path/to/template/cache');
$fenom->setOptions($options);
```
### Rendering template
Output template
```php
$fenom->display("template/name.tpl", $vars);
```
Get the result of rendering the template
```php
$result = $fenom->fetch("template/name.tpl", $vars);
```
Create the pipeline of rendering into callback
```php
$fenom->pipe(
"template/sitemap.tpl",
$vars,
$callback = [new SplFileObject("/tmp/sitemap.xml", "w"), "fwrite"], // pipe to file /tmp/sitemap.xml
$chunk_size = 1e6 // chunk size for callback
);
```