Skip to content

Commit

Permalink
change basedir behavior, update document
Browse files Browse the repository at this point in the history
  • Loading branch information
Zordius Chen committed Jul 20, 2014
1 parent ee755a9 commit e8779db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,17 @@ Default is to compile the template as PHP, which can be run as fast as possible
Partial Support
---------------

LightnCandy supports partial when compile time. When `compile()`, LightnCandy will search template file in current directory by default. You can define more then one template directory with `basedir` option. Default template file name is `*.tmpl`, you can change or add more template file extensions with `fileext` option.
LightnCandy supports partial when compile time. You can provide partials by `partials` option when `compile()`:

```
LightnCandy::compile($template, Array(
'partials' => Array(
'name' => 'template: {{name}}',
),
));
```

You can also provide partials by files. When `compile()`, LightnCandy will search template files from `basedir` in the option if you provided one or more. Default template file name is `*.tmpl`, you can change or add more template file extensions with `fileext` option.

for example:
```php
Expand Down
11 changes: 2 additions & 9 deletions src/lightncandy.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,9 @@ protected static function buildCXFileext($options) {
*
* @return array base directories
*
* @expect Array(getcwd()) when input Array()
* @expect Array(getcwd()) when input Array('basedir' => 0)
* @expect Array(getcwd()) when input Array('basedir' => '')
* @expect Array(getcwd()) when input Array('basedir' => Array())
* @expect Array() when input Array()
* @expect Array() when input Array('basedir' => Array())
* @expect Array('src') when input Array('basedir' => Array('src'))
* @expect Array(getcwd()) when input Array('basedir' => Array('dir_not_found'))
* @expect Array('src') when input Array('basedir' => Array('src', 'dir_not_found'))
* @expect Array('src', 'tests') when input Array('basedir' => Array('src', 'tests'))
*/
Expand All @@ -580,10 +577,6 @@ protected static function buildCXBasedir($options) {
}
}

if (count($ret) === 0) {
$ret[] = getcwd();
}

return $ret;
}

Expand Down
13 changes: 2 additions & 11 deletions tests/LightnCandyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,15 @@ public function testOn_buildCXFileext() {
public function testOn_buildCXBasedir() {
$method = new ReflectionMethod('LightnCandy', 'buildCXBasedir');
$method->setAccessible(true);
$this->assertEquals(Array(getcwd()), $method->invoke(null,
$this->assertEquals(Array(), $method->invoke(null,
Array()
));
$this->assertEquals(Array(getcwd()), $method->invoke(null,
Array('basedir' => 0)
));
$this->assertEquals(Array(getcwd()), $method->invoke(null,
Array('basedir' => '')
));
$this->assertEquals(Array(getcwd()), $method->invoke(null,
$this->assertEquals(Array(), $method->invoke(null,
Array('basedir' => Array())
));
$this->assertEquals(Array('src'), $method->invoke(null,
Array('basedir' => Array('src'))
));
$this->assertEquals(Array(getcwd()), $method->invoke(null,
Array('basedir' => Array('dir_not_found'))
));
$this->assertEquals(Array('src'), $method->invoke(null,
Array('basedir' => Array('src', 'dir_not_found'))
));
Expand Down

0 comments on commit e8779db

Please sign in to comment.