npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fib-pug

v0.0.3

Published

pug run in fibjs

Downloads

39

Readme

fib-pug

Build Status NPM version

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.

Usage

npm i -S fib-pug

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

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>'

Specical Features

Filters

If you don't know about this feature, learn more about it here

pug takes jstransformer-*-like packages(such as jstransformer-stylus) as default filter. That is, if you write :stylus in pug, it would try to find jstransformer-stylus in nodejs's common pattern.

Some jstransformer-*-like packages may be incompatible with fibjs, You can also customize filter as you like. View more sample usages for filter here