#template #notebook #jsonnet #fiberplane #data #snippets

fiberplane-templates

通过编程生成Fiberplane笔记本以实现可重复的工作流程

14个版本

1.0.0-beta.152024年3月27日
1.0.0-beta.132024年2月29日
1.0.0-beta.72023年11月30日
1.0.0-beta.32023年6月12日
1.0.0-beta.12023年2月14日

#98 in 模板引擎


用于 fiberplane

MIT/Apache

500KB
12K SLoC

Fiberplane Templates

通过编程生成Fiberplane笔记本以实现可重复的工作流程

概述

Fiberplane Templates使用Jsonnet数据模板语言构建。

本crate包括

  • Fiberplane Jsonnet库,包含创建笔记本的函数(API文档
  • Rust库,用于将模板扩展为笔记本以及将现有笔记本转换为模板

快速入门

Fiberplane CLI是推荐与Templates交互的方式(参阅文档或运行fp help templates)。

模板结构

大多数Fiberplane Templates导出一个接受一些参数并使用Fiberplane Jsonnet库提供的辅助函数创建笔记本的Jsonnet函数。

local fp = import 'fiberplane.libsonnet';
local c = fp.cell;
local fmt = fp.format;

// Parameters are named and can have default values
function(incidentName='API Outage')
  fp.notebook
    .new('Incident Response for: ' + incidentName)
    .setTimeRangeRelative(minutes=60)
    .addCells([
      // The library exposes helper functions for creating every cell type
      c.h1('Heading'),
      c.text(
        // There are also helper functions for formatting text
        fmt.bold('Hello World!')
      )
    ])

有关更详细的使用场景特定的模板,请参阅templates仓库

片段

片段是更小的Jsonnet代码块,用于生成可重用的笔记本单元数组,而不是整个笔记本。

local fp = import 'fiberplane.libsonnet';
local c = fp.cell;
local fmt = fp.format;

fp.snippet([
  c.h2('I am a snippet'),
  c.code('Here is some code'),
])

示例模板

示例模板,用于各种用例,如事件响应、根本原因分析等。

模板API文档

请参阅生成的API文档

开发

VS Code

如果您想使用VS Code编辑Jsonnet文件,可以使用Jsonnet NG扩展。

您应该在 VS Code 的 settings.json 文件中添加以下内容,以便在编辑模板文件时不会显示错误。这包括 Fiberplane Jsonnet 库和模板扩展函数通常提供的外部变量。

{
  "jsonnet.libPaths": ["path/to/fiberplane/templates/"]
}

运行测试

要运行测试(包括示例),请执行以下命令

cargo test --lib --examples

生成文档

Jsonnet 库 API 文档是通过使用 JSDoc 注释在 fiberplane.libsonnet 中生成的,使用 jsdoc-to-markdown

要(重新)生成文档,您可以使用以下 Docker 命令

docker run --rm -v $PWD:$PWD node:17 npx -y jsdoc-to-markdown -c $PWD/jsdoc.json $PWD/fiberplane.libsonnet > docs/template_api.md

或者,您可以直接使用 Node.js,使用以下命令

npx -y jsdoc-to-markdown -c jsdoc.json fiberplane.libsonnet > docs/template_api.md

依赖

~5–7.5MB
~165K SLoC