jonathangeiger / kohana-twig Goto Github PK
View Code? Open in Web Editor NEWA Kohana 3.0 module for integrating Twig
A Kohana 3.0 module for integrating Twig
The class in:
classes/kohana/twig/trans/tokenparser.php
is named Twig_TokenParser_Trans
It should be Kohana_Twig_Trans_TokenParser
Twig inside kohana is much slower due to the way kohana finds files (when it autoloads classes or whatever).
I tested Twig standalone in the document root and it is very fast. Inside kohana it takes as much time to render a small template as the whole framework itself takes to render the same thing with views with php in them + alittle more (and this is after the template has been cached !). I first thought it wasnt caching properly, but no, that wasnt it, its the file loading.
I was ready to give up twig in favor of mustache which is lightning fast (again with some tweaks, from the original kostache)
But after some more testing I found the problem (and the solutions)
Itried 2 variants:
Now twig autoloader is no longer needed (in init.php).
This halved the time it took for loading files. (I tested it, for ex, the time it took from passing execution from ... = new Twig_lexer; to the constructor inside Lexer.php)
I Changed the profiler call inside kohana::find_file to print also the file name it loads, then printed the profiling view at the bottom of index.php
<div id="kohana-profiler">
<?php echo View::factory('profiler/stats') ?>
</div>
Now I only did this for cached templates, when twig rebuilds them there are probably more.
In any case, here is what I added to /modules/twig/classes/twig.php:
If you DID move the Twig folder from inside vendor into classes/twig (notice small t in twig) use this:
<?php defined('SYSPATH') or die('No direct script access.');
$folder = realpath(dirname(__FILE__).'/twig');
If you did NOT move the Twig folder from inside vendor into classes use this:
<?php defined('SYSPATH') or die('No direct script access.');
$folder = realpath(dirname(__FILE__).'/../vendor/Twig/lib/Twig');
Then underneath:
require_once "$folder/LexerInterface.php" ;
require_once "$folder/ParserInterface.php" ;
require_once "$folder/CompilerInterface.php" ;
require_once "$folder/LoaderInterface.php" ;
require_once "$folder/ExtensionInterface.php" ;
require_once "$folder/TemplateInterface.php" ;
require_once "$folder/NodeInterface.php" ;
require_once "$folder/Extension.php" ;
require_once "$folder/Extension/Core.php" ;
require_once "$folder/Template.php" ;
require_once "$folder/Node.php" ;
require_once "$folder/Node/Expression.php" ;
require_once "$folder/Node/Expression/GetAttr.php" ;
require_once "$folder/Lexer.php" ;
require_once "$folder/Parser.php" ;
require_once "$folder/Compiler.php" ;
require_once "$folder/Environment.php" ;
class Twig extends Kohana_Twig {}
Route::get() doesn't work for me, would URL::site() be better? Maybe I'm not using it correctly?
I'm on K03.
mostly it was easy, but I was briefly hung up because I didn't know to put the latest Twig in vendors/
ErrorException [ Recoverable Error ]: Argument 1 passed to Twig_NodeTraverser::traverse() must implement interface Twig_NodeInterface, instance of Twig_Token given, called in /var/www/nolimits/public/modules/twig/vendor/Twig/lib/Twig/NodeTraverser.php on line 73 and defined
Need to find the solution, just leaving a note for myself and anyone else. Will update at a later date.
Hey,
I'm trying to figure out the Kohana + Twig extensions you've created, mostly reading code. We could make a README file, I'd be happy to help
This makes it near impossible to cleanly extend/adapt the functionality of the module.
For example modify the output of the tags and helpers or to rename the helpers.
Cheers,
Aron
Hello !
Thanks a lot for your library !
I've a small question.
It would be great to use Kohana::find_file to find templates instead of looking directly into /application/views (to use the hierarchical structure of Kohana).
I wasn't able to modify it by myself, maybe you've a better view to the code to make it :-)
Thanks for your help !
I'm on KO3.
Asset class is missing? Maybe use HTML instead?
In the __toSting
method of Twig.php
try
{
return $this->render();
}
catch (Exception $e)
{
// Display the exception message
Kohana::exception_handler($e);
return '';
}
A stacktrace is always shown, which is probably not appropriate for production environments. I'm working on a patch.
We have error when use another Loader for twig, when try parse string
Text text
In result we have:
Text <img src="http://example.com/image
Cose Kohana_Twig class find extension in the first param in the factory. FIx this:
Remove code:
if ($extension = pathinfo($file, PATHINFO_EXTENSION))
{
$this->set_extension($extension);
}
From function Kohana_Twig::set_filename . I don't know why we must use this code(search extension in input data), cose this is loader functional, and extension declared in config file.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.