New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fib-pug

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fib-pug

pug run in fibjs

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

fib-pug

pugjs is one popular js template engine formerly known as "Jade". It's indentation-sensitive with high-performance. But at some point, it could only run in nodejs (some version of "Jade" can run in browser), because from that point pugjs support APIs such as renderFile which required I/O runtime.

I/O

As of fs module, luckily, fibjs has similar API with nodejs, we can run pugjs in fibjs, just do some magic hack with fibjs's sandbox module.

Mechanism

/**
 * 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 orignal pug module in nodejs, you can run pugjs in fibjs.

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 pugjs, but I belive it's enough for your project in most cases.

  • compile
  • render
  • renderFile

view the parameters of this api in pugjs's page.

Sample

#!/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>'

Keywords

FAQs

Package last updated on 29 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc