Created
July 2, 2012 22:20
-
-
Save ikkez/3036104 to your computer and use it in GitHub Desktop.
Jade Template Plugin Draft for F3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$app=require __DIR__.'/lib/base.php'; | |
$app->set('AUTOLOAD','inc/;inc/temp/'); | |
$app->set('CACHE',FALSE); | |
$app->set('DEBUG',3); | |
$app->set('EXTEND',TRUE); | |
$app->set('GUI','gui/'); | |
$app->set('PROXY',TRUE); | |
$app->set('TEMP','temp/'); | |
$app->route('GET /haml', | |
function() use($app) { | |
$app->set('headline','a very cool headline'); | |
$app->set('foo',array('one','two','three')); | |
echo TemplateExt::serve('test.jade'); | |
} | |
); | |
$app->run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
Template Extension for the PHP Fat-Free Framework | |
The contents of this file are subject to the terms of the GNU General | |
Public License Version 3.0. You may not use this file except in | |
compliance with the license. Any of the license terms and conditions | |
can be waived if you get permission from the copyright holder. | |
@package Template | |
@version 0.1.0 | |
**/ | |
require(__DIR__.'/ext/everzet-jade.php-e57fce6/autoload.php.dist'); | |
use Everzet\Jade\Jade; | |
use Everzet\Jade\Parser; | |
use Everzet\Jade\Lexer\Lexer; | |
use Everzet\Jade\Dumper\PHPDumper; | |
use Everzet\Jade\Visitor\AutotagsVisitor; | |
use Everzet\Jade\Filter\JavaScriptFilter; | |
use Everzet\Jade\Filter\CDATAFilter; | |
use Everzet\Jade\Filter\PHPFilter; | |
use Everzet\Jade\Filter\CSSFilter; | |
class TemplateExt extends Template { | |
//@{ Locale-specific error/exception messages | |
const | |
TEXT_Render='Template %s cannot be rendered'; | |
//@} | |
static function serve($file, $mime='text/html',$globals=TRUE,$syms=array()) { | |
// Parse jade template | |
// bootstrap jade | |
$dumper = new PHPDumper(); | |
$dumper->registerVisitor('tag', new AutotagsVisitor()); | |
$dumper->registerFilter('javascript', new JavaScriptFilter()); | |
$dumper->registerFilter('cdata', new CDATAFilter()); | |
$dumper->registerFilter('php', new PHPFilter()); | |
$dumper->registerFilter('style', new CSSFilter()); | |
// Initialize parser & Jade | |
$parser = new Parser(new Lexer()); | |
$jade = new Jade($parser, $dumper); | |
// resolve F3 Markup | |
$template = parent::serve($file,$mime,$globals,$syms); | |
// Parse a template (both string & file containers) | |
return $jade->render($template); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! 5 | |
head | |
title HAML like Template Test with jade.php | |
body | |
#header | |
h1 {{@headline}} | |
<repeat group="{{@foo}}" value="{{@val}}"> | |
p nice paragraph {{@val}} | |
</repeat> | |
p end |
Also, I wasn't aware of the short versions of thetags. That's interesting, though IDT f3:
is a huge deal to type and its good for clarity + readability, I think. Esp. if one is using arbitrary and custom XML tags that may clash with f3's.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ikkez u need to update your GFM above. there's a syntax error that hid a portion of it. but yes, when i can i will look into hacking the jade lib.