core.vars
core.vars 提供了和 vars 有关的接口
WIP:至少需要 v1.3.11 以上版本才可使用,仍在开发中
render(template_file: str, use: [str], save_to: str?, extra: dict = {}) -> str
利用 vars 渲染模板,返回渲染结果
参数:template_file
模板文件名,支持绝对路径或相对于运行目录的相对路径
参数:use
使用 vars 的限定,必须存在,如不使用任何 vars(即完全使用 extra)请传递 []
参数:extra
除了 vars 之外使用的其他变量,会遵循 vars 导入原则进行覆盖原有的 vars
vars 导入原则 的文档还在撰写中,简单说就是 例如存在着已有的 vars {"k1": {"a": 1, "b": 2}}
如果 extra = {"k1": {"a": 3}} ,则结果为 {"k1": {"a": 3}},即完全覆盖 如果 extra = {"k1.a": 3} ,则结果为 {"k1": {"a": 3, "b": 2}},即部分设定
参数:save_to
除了返回渲染结果,还将渲染结果保存到文件中,传递文件名绝对路径或相对于运行目录的相对路径