From: Andrey Kutejko Date: Sun, 8 Feb 2015 10:16:24 +0000 (+0200) Subject: initial commit X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=3186be0e717b4f3bb59e96a7cd9a888efd0bf00f;p=ipf-twig.git initial commit --- 3186be0e717b4f3bb59e96a7cd9a888efd0bf00f diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4acdc48 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +/vendor + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..dca8d2c --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "andy128k/ipf-twig", + "authors": [ + { + "name": "Andrey Kutejko", + "email": "andy128k@gmail.com" + } + ], + "repositories": [ + { + "type": "composer", + "url": "http://packages.andy128k.net/php/" + } + ], + "autoload": { + "classmap" : ["src"] + }, + "require": { + "twig/twig": "~1" + }, + "suggest": { + "andy128k/ipf": "Web framework" + }, + "minimum-stability": "dev" +} + diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..54c32e3 --- /dev/null +++ b/composer.lock @@ -0,0 +1,75 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "789a2d96bafbb8d8ff7786cde5839e08", + "packages": [ + { + "name": "twig/twig", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "74a8bddec4e8fbea8b3f497bc7cc4bdf1a498330" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/74a8bddec4e8fbea8b3f497bc7cc4bdf1a498330", + "reference": "74a8bddec4e8fbea8b3f497bc7cc4bdf1a498330", + "shasum": "" + }, + "require": { + "php": ">=5.2.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.18-dev" + } + }, + "autoload": { + "psr-0": { + "Twig_": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + }, + { + "name": "Twig Team", + "homepage": "http://twig.sensiolabs.org/contributors", + "role": "Contributors" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "http://twig.sensiolabs.org", + "keywords": [ + "templating" + ], + "time": "2015-01-30 11:04:23" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/src/twig.php b/src/twig.php new file mode 100644 index 0000000..e0bf95b --- /dev/null +++ b/src/twig.php @@ -0,0 +1,49 @@ +loadTemplate($tplfile); + return $template->render($context); + } + + private static function createEnvironment() + { + $options = array( + 'cache' => IPF::get('tmp'), + ); + if (IPF::get('debug')) { + $options['debug'] = true; + $options['auto_reload'] = true; + } + + $twig = new Twig_Environment(self::createLoader(), $options); + + $twig->addFunction(new Twig_SimpleFunction('url', function() { + return IPF_Project_Template::urlTag(func_get_args()); + })); + $twig->addFunction(new Twig_SimpleFunction('params', function() { + return IPF_Project_Template::paramsTag(func_get_args()); + })); + + return $twig; + } + + private static function createLoader() + { + $loader = new Twig_Loader_Filesystem(array()); + foreach (IPF_Project_Template::templateDirs() as $dir) { + $loader->addPath($dir); + } + return $loader; + } +} +