Awesome 社區模塊

fib-pug

pugjsrenderFile

I/O

As offssandbox

Mechanism

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/** * only test in fibjs 0.21 and pug@2.0.0-rc.4 * */ const vm = require('vm'); const sbox = new vm.SandBox({ fs: require('fs'), path: require('path'), http: require('http'), https: require('http'), assert: require('assert'), url: require('url'), os: require('os'), util: require('util') }); // one valid pug module const pug = sbox.require('pug', __filename)

as code above, just provide property module for orignalpug

But I can't test all version of fibjs and pug, so I mark the tested version of fibjs and pug in package.jsonand would notice developer if version when running this module in DEBUG mode.

API

I just support some API of

  • compile
  • render
  • renderFile

view the parameters of this api in

Sample

1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/env fibjs const locals = {testVar: '测试变量'} const rawText = 'div\n\t| #{testVar}' try { html = pug.compile(rawText, {pretty: true})(locals); } catch (e) { html = '' error = e.message } console.log(html) // '<div>测试变量</div>'