mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-03 10:33:08 +03:00
fix phpcs and also add mustache.php copyright notice
This commit is contained in:
parent
ccaa5b1d21
commit
382938b82e
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
|
* This file is part of Handlebars-php
|
||||||
|
* Base on mustache-php https://github.com/bobthecow/mustache.php
|
||||||
|
*
|
||||||
* Handlebars Inline Template string Loader implementation.
|
* Handlebars Inline Template string Loader implementation.
|
||||||
*
|
*
|
||||||
* With the InlineLoader, templates can be defined at the end of any PHP source
|
* With the InlineLoader, templates can be defined at the end of any PHP source
|
||||||
@ -18,18 +21,40 @@
|
|||||||
* Goodbye, cruel {{ planet }}
|
* Goodbye, cruel {{ planet }}
|
||||||
*
|
*
|
||||||
* Templates are deliniated by lines containing only `@@ name`.
|
* Templates are deliniated by lines containing only `@@ name`.
|
||||||
|
*
|
||||||
|
* @category Xamin
|
||||||
|
* @package Handlebars
|
||||||
|
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||||
|
* @author Hiroyuki Toda <mai7star@gmail.com>
|
||||||
|
* @copyright 2010-2015 (c) Justin Hileman
|
||||||
|
* @copyright 2015 (c) fzerorubigd
|
||||||
|
* @license MIT <http://opensource.org/licenses/MIT>
|
||||||
|
* @version Release: @package_version@
|
||||||
|
* @link http://xamin.ir
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Handlebars\Loader;
|
namespace Handlebars\Loader;
|
||||||
|
|
||||||
use Handlebars\Loader;
|
use Handlebars\Loader;
|
||||||
use Handlebars\String;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The inline loader
|
||||||
|
*
|
||||||
|
* @category Xamin
|
||||||
|
* @package Handlebars
|
||||||
|
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||||
|
* @author Hiroyuki Toda <mai7star@gmail.com>
|
||||||
|
* @copyright 2010-2015 (c) Justin Hileman
|
||||||
|
* @copyright 2015 (c) fzerorubigd
|
||||||
|
* @license MIT <http://opensource.org/licenses/MIT>
|
||||||
|
* @version Release: @package_version@
|
||||||
|
* @link http://xamin.ir *
|
||||||
|
*/
|
||||||
class InlineLoader implements Loader
|
class InlineLoader implements Loader
|
||||||
{
|
{
|
||||||
protected $_fileName;
|
protected $fileName;
|
||||||
protected $_offset;
|
protected $offset;
|
||||||
protected $_templates;
|
protected $templates;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The InlineLoader requires a filename and offset to process templates.
|
* The InlineLoader requires a filename and offset to process templates.
|
||||||
@ -57,43 +82,45 @@ class InlineLoader implements Loader
|
|||||||
throw new \InvalidArgumentException('InlineLoader expects a valid file offset.');
|
throw new \InvalidArgumentException('InlineLoader expects a valid file offset.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_fileName = $fileName;
|
$this->fileName = $fileName;
|
||||||
$this->_offset = $offset;
|
$this->offset = $offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a Template by name.
|
* Load a Template by name.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name template name
|
||||||
*
|
*
|
||||||
* @return string Mustache Template source
|
* @return string Handlebars Template source
|
||||||
*/
|
*/
|
||||||
public function load($name)
|
public function load($name)
|
||||||
{
|
{
|
||||||
$this->loadTemplates();
|
$this->loadTemplates();
|
||||||
|
|
||||||
if (!array_key_exists($name, $this->_templates)) {
|
if (!array_key_exists($name, $this->templates)) {
|
||||||
throw new \InvalidArgumentException("Template {$name} not found.");
|
throw new \InvalidArgumentException("Template {$name} not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_templates[$name];
|
return $this->templates[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse and load templates from the end of a source file.
|
* Parse and load templates from the end of a source file.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function loadTemplates()
|
protected function loadTemplates()
|
||||||
{
|
{
|
||||||
if (!is_null($this->_templates)) {
|
if (!is_null($this->templates)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_templates = array();
|
$this->templates = array();
|
||||||
$data = file_get_contents($this->_fileName, false, null, $this->_offset);
|
$data = file_get_contents($this->fileName, false, null, $this->offset);
|
||||||
foreach (preg_split('/^@@(?= [\w\d\.]+$)/m', $data, -1) as $chunk) {
|
foreach (preg_split('/^@@(?= [\w\d\.]+$)/m', $data, -1) as $chunk) {
|
||||||
if (trim($chunk)) {
|
if (trim($chunk)) {
|
||||||
list($name, $content) = explode("\n", $chunk, 2);
|
list($name, $content) = explode("\n", $chunk, 2);
|
||||||
$this->_templates[trim($name)] = trim($content);
|
$this->templates[trim($name)] = trim($content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AutoloaderTest
|
* Class HandlebarsTest
|
||||||
*/
|
*/
|
||||||
class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -509,11 +509,14 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertFalse($helpers->has('test'));
|
$this->assertFalse($helpers->has('test'));
|
||||||
$this->assertFalse(isset($helpers->test));
|
$this->assertFalse(isset($helpers->test));
|
||||||
$this->assertTrue($helpers->isEmpty());
|
$this->assertTrue($helpers->isEmpty());
|
||||||
$helpers->add('test', function() {});
|
$helpers->add('test', function () {
|
||||||
|
});
|
||||||
$this->assertCount(0, array_diff(array_keys($helpers->getAll()), array('test')));
|
$this->assertCount(0, array_diff(array_keys($helpers->getAll()), array('test')));
|
||||||
$extraHelpers = new \Handlebars\Helpers();
|
$extraHelpers = new \Handlebars\Helpers();
|
||||||
$extraHelpers->add('test', function() {});
|
$extraHelpers->add('test', function () {
|
||||||
$extraHelpers->add('test2', function() {});
|
});
|
||||||
|
$extraHelpers->add('test2', function () {
|
||||||
|
});
|
||||||
$helpers->addHelpers($extraHelpers);
|
$helpers->addHelpers($extraHelpers);
|
||||||
$this->assertTrue($helpers->has('test2'));
|
$this->assertTrue($helpers->has('test2'));
|
||||||
$this->assertEquals($helpers->test, $extraHelpers->test);
|
$this->assertEquals($helpers->test, $extraHelpers->test);
|
||||||
@ -1174,7 +1177,8 @@ EOM;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function stringLiteralsInIfAndUnlessHelpersProvider() {
|
public function stringLiteralsInIfAndUnlessHelpersProvider()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
// IfHelper
|
// IfHelper
|
||||||
array('{{#if "truthyString"}}true{{else}}false{{/if}}', array(), "true"),
|
array('{{#if "truthyString"}}true{{else}}false{{/if}}', array(), "true"),
|
||||||
|
Loading…
Reference in New Issue
Block a user