The modifier module for Jade template engine.
This project has created by rewriting the 'jade-php'project, to
- change the API.
- support new feature I personally require.
Install the module with: npm install phpjade
var jade = require('jade');
var phpjade = require('phpjade');
phpjade.init(jade); // apply modifier.
...
// just use jade.
var fn = jade.compileFile(filepath, options);
var phptext = fn(locals);Attach this modifier to Jade template engine.
Remove this modifier from Jade template engine.
Set this option to true to support 'nameless' attributes.
var jade = require('jade');
var phpjade = require('phpjade');
phpjade.init(jade);
var fn = jade.compileFile(filepath, { usestrip:true });Called just after compiler found php portion of text.
Used for remove cumbersome typing from php code.
var jade = require('jade');
require('phpjade').init(jade);
var fn = jade.compileFile(filepath, {
prefunction: function(input, options) {
return input.replace(/###/, "'mythemename'");
}
});html
body
div!=_e('hello php world!', ###)
<html>
<body>
<div><?php echo _e('hello php world!', 'mythemename'); ?></div>
</body>
</html>
The following syntax sample is formatted as if pretty print option is set.
tag(attr=php_function())
<tag attr="<?php echo htmlspecialchars(php_function(), ENT_QUOTES, 'UTF-8'); ?>"></tag>tag(attr!=php_function())
<tag attr="<?php echo php_function(); ?>"></tag>tag(attr!=-php_function())
<tag attr="<?php php_function(); ?>"></tag>
tag(__=php_function())
<tag <?php php_function(); ?> ></tag>tag(__=php_function(), ___=php_function2())
<tag <?php php_function(); ?> <?php php_function2(); ?> ></tag>tag
- php_code
<tag><?php php_code ;?></tag>:php
/* some php codes comes here */
call_php_function();
html
<?php
/* some php codes comes here */
call_php_function();
?>
<html>
</html>
div(op!=php_func('abc', "def")+"ghijk")
<div op="<?php echo php_func('abc', "def"); ?>ghijk"></div>
div(myattr!=$test['abc'])
may be mis-converted. if so, use whitespace like:
div(myattr!= $test['abc'] )
This doesn't work.
div(myattr!= $var1 . 'test')
This does not work.
:php
function testfunction() {
Please modify like:
:php
/* some comment */
function testfunction() {
html
body
- testfunc();
div(__=some_php_function())
| test
- foreach ($this->list as $list):
li!= $list
- endforeach
<html>
<body>
<?php testfunc(); ?>
<div <?php some_php_function(); ?> >test</div>
<?php foreach ($this->list as $list): ?>
<li><?php echo $list; ?></li>
<?php endforeach; ?>
</body>
</html>- passing prefunction and data
var jade = require('jade');
var phpjade = require('phpjade');
phpjade.init(jade);
var fn = jade.compileFile(filepath,
{
usestrip: true,
pretty: true,
prefunction: function(input/*, options*/) {
return input.replace(/\$\$+/, "#{data.domain}");
},
}
);
var php = fn({data: { domain: "mytextdomain" } });- Jade source
:php
/**
* @package WordPress
* @subpackage $$
*/
html
body
div!=_e('This is my opinion', '$$')
div=_test("$$")
div
- _test("$$")
div(op=_test("$$"))
div(op!=_test("$$"))
div(op=$test)
div(op!=$test)
div(op="#{data.domain}")
div(op="$$")
div(op!=php_func('abc', "def", "ghi" + '$$')+"ghijk")
- produced php
<?php
/**
* @package WordPress
* @subpackage mytextdomain
*/
?>
<html>
<body>
<div>
<?php echo _e('This is my opinion', 'mytextdomain'); ?></div>
<div>
<?php echo htmlspecialchars(_test("mytextdomain"), ENT_QUOTES, 'UTF-8'); ?></div>
<div>
<?php _test("mytextdomain"); ?>
</div>
<div op="<?php echo htmlspecialchars(_test("mytextdomain"), ENT_QUOTES, 'UTF-8'); ?>"></div>
<div op="<?php echo _test("mytextdomain"); ?>"></div>
<div op="<?php echo htmlspecialchars($test, ENT_QUOTES, 'UTF-8'); ?>"></div>
<div op="<?php echo $test; ?>"></div>
<div op="mytextdomain"></div>
<div op="mytextdomain"></div>
<div op="<?php echo php_func('abc', "def", "ghi" + 'mytextdomain'); ?>ghijk"> </div>
</body>
</html>
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
- 1.4.2 Jan 04 2016 Array access expression in attribute part has supported. Version information about Jade that this add-on can work with has updated.
- 1.4.1 Jul 30 2015
Added permissive version check. - 1.4.0 Jun 04 2015
Added support for more complex attributes. - 1.3.1 Jun 02 2015
Fixed the bug "In the php filter block, the 'prefunction' couldn't be called". - 1.3.0 Jun 02 2015
capability of calling 'prefunction' has added. - 1.2.0 May 28 2015
- 1.1.1 May 25 2015
- 1.1.0 May 21 2015
- 1.0.0 May 20 2015
Copyright (c) 2015 Hiroyoshi Kurohara
Licensed under the MIT license.
- grunt-jade-mod
Grunt task module for Jade with modifier support, phpjade can be used with this module. - jade-mod-cli
Jade cli with modifier support, phpjade can be used with this. - wptt
WordPress Theme Template, using phpjade.