{"id":13686705,"url":"https://github.com/fibjs/fib-pug","last_synced_at":"2025-06-12T12:13:30.790Z","repository":{"id":57158520,"uuid":"206510004","full_name":"fibjs/fib-pug","owner":"fibjs","description":"pug run in fibjs","archived":false,"fork":false,"pushed_at":"2019-09-05T08:29:12.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-01T09:39:06.770Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fibjs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-05T08:10:00.000Z","updated_at":"2019-09-05T08:29:14.000Z","dependencies_parsed_at":"2022-09-07T21:01:27.902Z","dependency_job_id":null,"html_url":"https://github.com/fibjs/fib-pug","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fibjs/fib-pug","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibjs%2Ffib-pug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibjs%2Ffib-pug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibjs%2Ffib-pug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibjs%2Ffib-pug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fibjs","download_url":"https://codeload.github.com/fibjs/fib-pug/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibjs%2Ffib-pug/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259462578,"owners_count":22861514,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T15:00:38.230Z","updated_at":"2025-06-12T12:13:30.767Z","avatar_url":"https://github.com/fibjs.png","language":"JavaScript","funding_links":[],"categories":["Packages"],"sub_categories":["Template Engine"],"readme":"# fib-pug\n\n[![Build Status](https://travis-ci.org/fibjs/fib-pug.svg?branch=master)](https://travis-ci.org/fibjs/fib-pug)\n[![NPM version](https://img.shields.io/npm/v/fib-pug.svg)](https://www.npmjs.org/package/fib-pug)\n\n\n[pugjs]:https://github.com/pugjs/pug\n[semver]:https://www.npmjs.com/package/semver\n\n[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.\n\n## Usage\n```bash\nnpm i -S fib-pug\n```\n\n## I/O\nAs 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.\n\n## Mechanism\n```javascript\nconst vm = require('vm');\nconst sbox = new vm.SandBox({\n  fs: require('fs'),\n  path: require('path'),\n  http: require('http'),\n  https: require('http'),\n  assert: require('assert'),\n  url: require('url'),\n  os: require('os'),\n  util: require('util')\n});\n\n// one valid pug module\nconst pug = sbox.require('pug', __filename)\n```\n\nas code above, just provide property module for orignal `pug` module in nodejs, you can run pugjs in fibjs.\n\nBut I can't test all version of fibjs and pug, so I mark the tested version of fibjs and pug in `package.json`\u003cdel\u003eand would notice developer if version when running this module in DEBUG mode\u003c/del\u003e.\n\n## API\n\nI just support some API of [pugjs], but I belive it's enough for your project in most cases.\n\n- `compile`\n- `render`\n- `renderFile`\n\nview the parameters of this api in [pugjs]'s page.\n\n## Sample\n\n```javascript\n#!/usr/bin/env fibjs\n\nconst locals = {testVar: '测试变量'}\nconst rawText = 'div\\n\\t| #{testVar}'\n\ntry {\n  html = pug.compile(rawText, {pretty: true})(locals);\n} catch (e) {\n  html = ''\n  error = e.message\n}\n\nconsole.log(html) // '\u003cdiv\u003e测试变量\u003c/div\u003e'\n```\n\n## Specical Features\n\n### Filters\n[jstransformer-stylus]:https://www.npmjs.com/package/jstransformer-stylus\n[jstransformer-typescript]:https://www.npmjs.com/package/jstransformer-typescript\n\nIf you don't know about this feature, learn more about it [here](https://pugjs.org/language/filters.html)\n\n`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.\n\nSome `jstransformer-*`-like packages may be incompatible with fibjs, You can also customize filter as you like. View more sample usages for **filter** [here](/test/filters)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibjs%2Ffib-pug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffibjs%2Ffib-pug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibjs%2Ffib-pug/lists"}