Skip to content

template

walon edited this page Dec 3, 2021 · 6 revisions

介绍

luban使用scriban 模板引擎来生成代码,也使用这个模板来生成自定义的文本型数据文件。

模板文件在 Luban.Servers/Templates目录下。

自定义模板搜索路径

尽管可以直接修改Luban.Server/Templates目录下的模板文件,但每次更新Luban.Server会覆盖自己的实现,不是很方便。 Luban.Server支持模板搜索路径, Luban.Server命令行参数" -t, --templaate_search_path path" 用于指定优先搜索路径。

模块缓存机制

为了优化性能,Luban.Server在运行时加载模板文件后,会保留模板缓存。在调试模板时,缓存机制导致不会重新加载模板文件,需要频繁重启,不太方便。可以通过参数 "--disable_cache" 禁用缓存。

代码模板

TODO 。 自定义代码模板示例暂时请参见 CustomTemplates。 生成脚本示例参见 脚本目录 下的 gen_template_xxxx.bat 文件。

数据模板

当生成参数 --gen_types中包含 data_template时,为自定义数据模板模式,需要配合 --template_name <template_name> 来指定模板名(注意,模板名不要包含.tpl后缀),在

例如 "--gen_types data_template --template_name lua" 则会从搜索路径查找 config/data/lua.tpl 文件。

示例模板文件在 CustomTemplates/data 下。

自定义数据模板文件输出的数据文件的后缀

luban会智能从 template_name 参数中猜测文件类型,默认给一个输出文件名。如果猜测失败,又没有指定 --data_file_extension 选项,则会报错。 像 lua2, lua,lua_test,my_lua_template 都会猜测为lua类型。

Clone this wiki locally