DevOps研发效能
媒体矩阵
开源中国APP
授权协议 MIT
操作系统 跨平台
软件类型 开源软件
所属分类 程序开发模板引擎
开源组织
地区 不详
投 递 者 不详
适用人群 未知
收录时间 2020-05-07

软件简介

Pug(原名 Jade,因商标问题改名)是一个强大、优雅、功能丰富的 Node.js 模板引擎。

Pug 的一般渲染过程很简单,pug.compile()会将 Pug 源码编译成 JavaScript 函数,该 JavaScript 函数将数据对象locals作为参数,调用该结果函数,将返回与数据一起呈现的 HTML 字符串。

可以重复使用已编译的函数,并使用不同的数据集调用该函数。

//- template.pug
p #{name}'s Pug source code!
const pug = require('pug');

// Compile the source code
const compiledFunction = pug.compileFile('template.pug');

// Render a set of data
console.log(compiledFunction({
  name: 'Timothy'
}));
// "<p>Timothy's Pug source code!</p>"

// Render another set of data
console.log(compiledFunction({
  name: 'Forbes'
}));
// "<p>Forbes's Pug source code!</p>"

Pug 还提供了pug.render()将编译和渲染结合在一起的一系列功能。但是,每次render调用时都会重新编译模板函数,这可能会影响性能。

const pug = require('pug');

// Compile template.pug, and render a set of data
console.log(pug.renderFile('template.pug', {
  name: 'Timothy'
}));
// "<p>Timothy's Pug source code!</p>"
展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击引领话题📣 发布并加入讨论🔥
发表了资讯
2020/05/28 07:49

Pug(Jade) 3.0.0 发布,优雅强大的 Node.js 模板引擎

Pug 3.0.0 发布了。Pug 原名 Jade,因商标问题而改名,它是一个强大、优雅、功能丰富的 Node.js 模板引擎。Pug 的一般渲染过程很简单,pug.compile()会将 Pug 源码编译成 JavaScript 函数,该 JavaScript 函数将数据对象locals作为参数,调用该结果函数,将返回与数据一起呈现的 HTML 字符串。可以重复使用已编译的函数,并使用不同的数据集调用该函数。 这是一个滚动更新版本,作者介绍将多个 Pug 相关的软件包合并到一个仓库之...

0
4
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
0 评论
1 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部