Skip to content

Instantly share code, notes, and snippets.

@ikkez
Created July 2, 2012 22:20
Show Gist options
  • Save ikkez/3036104 to your computer and use it in GitHub Desktop.
Save ikkez/3036104 to your computer and use it in GitHub Desktop.
Jade Template Plugin Draft for F3
<?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();
<?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);
}
}
!!! 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
@GHANONTEST
Copy link

@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.

@GHANONTEST
Copy link

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