gruntjs - 如何使用 Grunt 作为任务运行器在 pug 模板中导入带有数据对象的 JSON 文件?
问题描述
我有一个带有对象(字体字符的名称/代码)的 JSON 文件,我希望将它导入到 Pug 文件中,我正在使用 Grunt 作为任务运行器。
{
"brand": 61697,
"podcast-x": 61698,
"podcast": 61699,
"play": 61700,
"book": 61702,
"book-x": 61703,
"map": 61704,
"search": 61705,
"map-x": 61706,
"play-x": 61707,
"eye": 61708,
"eye-x": 61709
}
我希望在列表中显示每个字符,例如:
ul.list.list--inline
li.list__item
span.list__icon
i.i.i--brand
解决方案
首先将其添加到 grunt 任务中pug.js
module.exports = {
options: {
pretty: true,
data: {
require: require
}
}
};
现在只需将其包含在 pug 文件中:
block append variables
- const icons = require('../src/images/icons/.codepoints.json')
block content
ul.list.list--inline
each code, name in icons
unless name.endsWith('-x')
li.list__item
span.list__icon
i.i(class='i--' + name)
- let x = Object.keys(icons).includes(name + '-x');
if x
i.i(class='i--' + name + '-x')
在我的情况下,最终结果:
推荐阅读
- c++ - __FLT_MAX__ 和 __DBL_MAX__ 为 0?
- sql-server - T-SQL 如何对文本数据求和?
- mysql - 将一列从一个表移动到另一个mysql
- python - 将 tensorflow 冻结图转换为 pbtxt 文件失败
- coding-style - 如何让 clang-format 不将简单的枚举格式化为一行?
- ruby-on-rails - how to apply :session_limitable at a specific user ? (devise-security )
- python - 使用python 3将csv数据导入mysql数据库时出错
- javascript - 我可以在对话框中的画布内显示输赢游戏后的结果,而不是使用“警报”吗?
- excel - 将 Outlook 电子邮件数量、期限和受益人解析为 Excel
- c++ - 构造一个没有默认构造函数的空对象