sisoftrg / jade.php Goto Github PK
View Code? Open in Web Editor NEWThis project forked from hackaugusto/jade.php
Jade template engine ported to PHP 5.3
Home Page: https://github.com/visionmedia/jade
License: MIT License
This project forked from hackaugusto/jade.php
Jade template engine ported to PHP 5.3
Home Page: https://github.com/visionmedia/jade
License: MIT License
I couldn't track down the use of this bit of code:
if ($scope !== null && is_array($scope)) {
extract($scope);
}
inside render()
function. There are no include
s or require
s, so it's kinda leading to nowhere.
I tried this in a template:
- foreach($pages->visible() as $p):
And it was wrongly translated to:
<?php for(each($pages->visible() as $p)) { ?>
Hi!
First of all, thumbs up for the port to PHP! Works like a charm to use it on client and server. I have a little problem with html5 data-attributes tho:
div(data-module="#{mod}", class="#{module_classes}")
renders as
<div data-module=""something"" class="some classes here">
Please notice the double quotes around the data-module value.
The problem only happens with a variable + data- attributes.
div(data-module="something", class="#{module_classes}")
OK, constant works as expected
div(module="#{mod}", class="#{module_classes}")
OK, as expected, but of course creates invalid html.
It works perfectly with Jade client-side. Might there be a
Javascript + not ported or something?
Any help appreciated!
It's a good practice to use isset
when doing an if
on a variable that is in the view (since it might not be initialized at that time). since javascript doesn't trigger an error (at least not in strict mode) when doing an if
on an undefined, PHP, on the other hand, when E_ALL
is set (in development of course), it will trigger the notice. I don't know where to change this code, so that's the reason I'm opening the issue
Hi,
I'm using turnkey virtual machine (Debian + PHP 5.3):
http://www.turnkeylinux.org/lampstack
And some templates are compiling with errors. Here is result of test.php:
root@lamp jade/tests# php test.php
* rendering test 'attrs-data'
PHP Parse error: syntax error, unexpected '(' in /var/www/fakty_prod/application/vendor/sisoft/jade/tests/attrs-data.jade.php on line 2
-<foodata-user='{'name':'tobi'}'></foo><foodata-items='[1,2,3]'></foo><foodata-username='tobi'></foo>
+
* rendering test 'attrs.interpolation'
* rendering test 'attrs'
* rendering test 'attrs.js'
* rendering test 'attrs.unescaped'
-<scripttype='text/x-template'><divid='user-<%=user.id%>'><h1><%=user.title%></h1></div></script>
+<scripttype='text/x-template'><divid='user'id='user-<%=user.id%>'><h1><%=user.title%></h1></div></script>
* rendering test 'basic'
* rendering test 'blanks'
* rendering test 'block-expansion'
* rendering test 'block-expansion.shorthands'
* rendering test 'blockquote'
* rendering test 'case-blocks'
* rendering test 'case'
* rendering test 'classes-empty'
* rendering test 'classes'
* rendering test 'code.conditionals'
* rendering test 'code.escape'
* rendering test 'code.iteration'
PHP Parse error: syntax error, unexpected '(' in /var/www/fakty_prod/application/vendor/sisoft/jade/tests/code.iteration.jade.php on line 2
-<ul><liclass='item-0'>1</li><liclass='item-1'>2</li><liclass='item-2'>3</li></ul><ul><li>1</li><li>2</li><li>3</li></ul><ul><li>1:a</li><li>2:a</li><li>3:a</li><li>1:b</li><li>2:b</li><li>3:b</li><li>1:c</li><li>2:c</li><li>3:c</li></ul>
+
* rendering test 'code'
* rendering test 'comments.conditional'
* rendering test 'comments'
* rendering test 'deep-arrays'
* rendering test 'doctype.custom'
* rendering test 'doctype.default'
* rendering test 'doctype.keyword'
* rendering test 'each.else'
PHP Parse error: syntax error, unexpected '(' in /var/www/fakty_prod/application/vendor/sisoft/jade/tests/each.else.jade.php on line 2
-<ul><li>nousers!</li></ul><ul><li>tobi</li><li>loki</li></ul>
+
* rendering test 'escape-chars'
* rendering test 'filters.cdata'
PHP Parse error: syntax error, unexpected '(' in /var/www/fakty_prod/application/vendor/sisoft/jade/tests/filters.cdata.jade.php on line 2
-<fb:users><fb:userage='2'><![CDATA[tobi]]></fb:user></fb:users>
+
* rendering test 'html'
* rendering test 'html5'
* rendering test 'if-parentheses'
* rendering test 'include-extends-of-common-template'
* rendering test 'include-only-text-body'
* rendering test 'include-only-text'
* rendering test 'include-with-text-head'
* rendering test 'include-with-text'
-<html><head><scripttype='text/javascript'>alert('helloworld');</script><scriptsrc='/caustic.js'></script><scriptsrc='/app.js'></script></head></html>
+<html><head><scripttype='text/javascript'>alert('helloworld');</script></head><scriptsrc='/caustic.js'></script><scriptsrc='/app.js'></script></html>
* rendering test 'include.script'
* rendering test 'include.yield.nested'
-<html><head><title></title></head><body><h1>Page</h1><divid='content'><divid='content-wrapper'><p>somecontent</p><p>andsomemore</p></div></div><divid='footer'><stuff></stuff></div></body></html>
+<html><head><title></title></head><body><h1>Page</h1><divid='content'><divid='content-wrapper'></div></div><divid='footer'><stuff></stuff></div></body></html><p>somecontent</p><p>andsomemore</p>
* rendering test 'includes'
* rendering test 'inheritance.alert-dialog'
* rendering test 'inheritance.defaults'
* rendering test 'inheritance.extend.include'
* rendering test 'inheritance.extend'
* rendering test 'inheritance.extend.mixins'
-<html><head><title>MyApplication</title></head><body><h1>Themeaningoflife</h1><p>Foobarbaz!</p></body></html>
+<html><head><title>MyApplication</title></head><body><h1>Themeaningoflife</h1></body></html>
* rendering test 'inheritance.extend.whitespace'
* rendering test 'inheritance'
* rendering test 'interpolation.escape'
* rendering test 'mixin-hoist'
* rendering test 'mixin.attrs'
PHP Warning: Missing argument 2 for centered_mixin(), called in /var/www/fakty_prod/application/vendor/sisoft/jade/tests/mixin.attrs.jade.php on line 37 and defined in /var/www/fakty_prod/application/vendor/sisoft/jade/tests/mixin.attrs.jade.php on line 1
-<body><divid='First'class='centered'>HelloWorld</div><divid='Second'class='centered'><h1>Section1</h1><p>Someimportantcontent.</p></div><divid='Third'class='centered'><h1class='foobar'>Section2</h1><p>Evenmoreimportantcontent.</p><divclass='footer'><ahref='menu.html'>Back</a></div></div><divclass='stretch'><divclass='centered'><h1class='highlight'>Section3</h1><p>Lastcontent.</p><divclass='footer'><ahref='#'>Back</a></div></div></div><divclass='bottomfoobar'name='end'id='Last'data-attr='baz'><p>Somefinalwords.</p></div></body>
+<body><divid=''First''class='centered'></div><divid=''Second''class='centered'><h1class=''>Section1</h1></div><divid=''Third''class='centered'><h1class=''bar''>Section2</h1><divclass='footer'><ahref=''menu.html''>Back</a></div></div><divclass='stretch'><divid=''class='centered'><h1class=''highlight''>Section3</h1><divclass='footer'><ahref=''#''>Back</a></div></div></div><divattributes='attributes'class='bottom'></div></body>
* rendering test 'mixin.block-tag-behaviour'
-<html><body><sectionclass='article'><h1>Foo</h1><p>I'marticlefoo</p></section></body></html><html><body><sectionclass='article'><h1>Something</h1><p>I'mamuchlongertext-onlyarticle,butyoucanstillinlinehtmltagsinmeifyouwant.</p></section></body></html>
+<html><body><sectionclass='article'><h1>Foo</h1><p></p></section></body></html><html><body><sectionclass='article'><h1>Something</h1><p></p></section></body></html>
* rendering test 'mixin.blocks'
-<html><body><formmethod='GET'action='/search'><inputtype='hidden'name='_csrf'value='hey'/><inputtype='text'name='query'placeholder='Search'/><inputtype='submit'value='Search'/></form></body></html><html><body><formmethod='POST'action='/search'><inputtype='hidden'name='_csrf'value='hey'/><inputtype='text'name='query'placeholder='Search'/><inputtype='submit'value='Search'/></form></body></html><html><body><formmethod='POST'action='/search'><inputtype='hidden'name='_csrf'value='hey'/></form></body></html><divid='foo'><divid='bar'><p>one</p><p>two</p><p>three</p></div></div>
+<html><body><formmethod='GET'action='/search'><inputtype='hidden'name='_csrf'value='hey'/></form></body></html><html><body><formmethod='POST'action='/search'><inputtype='hidden'name='_csrf'value='hey'/></form></body></html><html><body><formmethod='POST'action='/search'><inputtype='hidden'name='_csrf'value='hey'/></form></body></html><divid='foo'><divid='bar'></div></div>
* rendering test 'mixin.merge'
-<body><pclass='barhello'>One</p><pclass='bazquuxhello'>Two</p><pclass='hello'>Three</p><pclass='barbazhello'>Four</p><pclass='bar'id='world'>One</p><pclass='bazquux'id='world'>Two</p><pid='world'>Three</p><pclass='barbaz'id='world'>Four</p><pclass='barhello'id='world'>One</p><pclass='bazquuxhello'id='world'>Two</p><pclass='hello'id='world'>Three</p><pclass='barbazhello'id='world'>Four</p><pclass='barhelloworld'>One</p><pclass='bazquuxhelloworld'>Two</p><pclass='helloworld'>Three</p><pclass='barbazhelloworld'>Four</p><pclass='barhello'>One</p><pclass='bazquuxhello'>Two</p><pclass='hello'>Three</p><pclass='barbazhello'>Four</p><pclass='barhelloworld'>One</p><pclass='bazquuxhelloworld'>Two</p><pclass='helloworld'>Three</p><pclass='barbazhelloworld'>Four</p><pclass='bar'>One</p><pclass='bazquux'>Two</p><p>Three</p><pclass='barbaz'>Four</p></body>
+<body><pattributes='attributes'class='bar'>One</p><pattributes='attributes'class='bazquux'>Two</p><pattributes='attributes'>Three</p><pattributes='attributes'class='barbaz'>Four</p><pattributes='attributes'class='bar'>One</p><pattributes='attributes'class='bazquux'>Two</p><pattributes='attributes'>Three</p><pattributes='attributes'class='barbaz'>Four</p><pattributes='attributes'class='bar'>One</p><pattributes='attributes'class='bazquux'>Two</p><pattributes='attributes'>Three</p><pattributes='attributes'class='barbaz'>Four</p><pattributes='attributes'class='bar'>One</p><pattributes='attributes'class='bazquux'>Two</p><pattributes='attributes'>Three</p><pattributes='attributes'class='barbaz'>Four</p><pattributes='attributes'class='bar'>One</p><pattributes='attributes'class='bazquux'>Two</p><pattributes='attributes'>Three</p><pattributes='attributes'class='barbaz'>Four</p><pattributes='attributes'class='bar'>One</p><pattributes='attributes'class='bazquux'>Two</p><pattributes='attributes'>Three</p><pattributes='attributes'class='barbaz'>Four</p><pattributes='attributes'class='bar'>One</p><pattributes='attributes'class='bazquux'>Two</p><pattributes='attributes'>Three</p><pattributes='attributes'class='barbaz'>Four</p></body>
* rendering test 'mixins'
* rendering test 'namespaces'
* rendering test 'nesting'
* rendering test 'quotes'
* rendering test 'scope'
PHP Parse error: syntax error, unexpected '(' in /var/www/fakty_prod/application/vendor/sisoft/jade/tests/scope.jade.php on line 18
-testtest2
+
* rendering test 'script.whitespace'
* rendering test 'scripts'
* rendering test 'scripts.non-js'
* rendering test 'source'
* rendering test 'styles'
* rendering test 'tag.interpolation'
-<p>value</p><pfoo='bar'>value</p><asomething='something'>here</a><ul><li><span><imgsrc='contact'class='icon'/>Contact</span></li><li><ahref='/contact'><imgclass='icon'/>Contact</a></li></ul>
+<tag>value</tag><tagfoo='bar'>value</tag><foo?'a':'li'something='something'>here</foo?'a':'li'><ul><li><spanattributes='attributes'><imgsrc='contact'class='icon'/></span></li><li><spanattributes='attributes'><imgsrc='/contact'class='icon'/></span></li></ul>
* rendering test 'tags.self-closing'
* rendering test 'template'
* rendering test 'text-block'
* rendering test 'text'
* rendering test 'utf8bom'
* rendering test 'utf8params'
* rendering test 'vars'
PHP Parse error: syntax error, unexpected '(' in /var/www/fakty_prod/application/vendor/sisoft/jade/tests/vars.jade.php on line 3
-<aid='bar'class='123'></a>
+
* rendering test 'yield-before-conditional-head'
* rendering test 'yield-before-conditional'
-<html><body><head><scriptsrc='/jquery.js'></script><scriptsrc='/caustic.js'></script><scriptsrc='/app.js'></script></head></body></html>
+<html><body><head><scriptsrc='/jquery.js'></script></head><scriptsrc='/caustic.js'></script><scriptsrc='/app.js'></script></body></html>
* rendering test 'yield-head'
* rendering test 'yield-title-head'
* rendering test 'yield-title'
-<html><body><head><title>MyTitle</title><scriptsrc='/jquery.js'></script><scriptsrc='/jquery.ui.js'></script></head></body></html>
+<html><body><head><title></title><scriptsrc='/jquery.js'></script><scriptsrc='/jquery.ui.js'></script></head>MyTitle</body></html>
* rendering test 'yield'
-<html><body><head><scriptsrc='/jquery.js'></script><scriptsrc='/caustic.js'></script><scriptsrc='/app.js'></script><scriptsrc='/jquery.ui.js'></script></head></body></html>
+<html><body><head><scriptsrc='/jquery.js'></script><scriptsrc='/jquery.ui.js'></script></head><scriptsrc='/caustic.js'></script><scriptsrc='/app.js'></script></body></html>
I am running into many problems with the automatic variable name substitution, and start to believe it's not a good idea to do this. For example, this code is causing issues:
open = pages->findOpen()
items = open ? open->children()->visible() : false
This gets wrongly translated to:
$__=$pages->findOpen();
$open = $__
$__=$open ? open->children()->visible() : false;
$items = $__
?>
As you can see, in the second statement, the second occurrence of open does not get replaced.
I have therefore created my own version of jade.php that removes this variable translation, and explicitly use the $-sign in the templates: https://github.com/lehni/jade.php
Don't you think this would make more sense for a PHP based Jade? I am wondering what the official take is on these kind of problems?
Hi :)
This line:
= Yii::app()->request->baseUrl
is translated in a wrong way:
<?php $__=$Yii::app();echo htmlspecialchars($__) ?>
This line:
- $baseUrl = Yii::app()->request->baseUrl
is translated in the right way:
<?php $baseUrl = Yii::app()->request->baseUrl ?>
No problem with this too:
- $app = Yii::app()
= $app->request->baseurl
I think the bug is due to the php scope resolution operator ::
I'm trying to pass a static function to a view, wrapping in an anonymous function before rendering to the file. The problem is that, the function becomes a variable (in my case $url
, and I was expecting it to be named url
(that behaves like Javascript Jade). I can call the $url('/')
stuff, but I'm avoiding using PHP in the views because I can later on, exchange the server stuff to node.js without hassle
This seems to be the most recent fork of jade.php Nice to see someone still working on it.
I couldn't figure out how to use the original jade.php nor am I able figure out this jade.php
How do I use it? (I know Jade from express.js) Could you give a quick example?
Thx!
Sam
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.