Skip to main content
Version: Next

custom template

Luban uses the scriban template engine to generate code, and also uses this template to generate custom text data files.

Template location in the source project

Due to modularization, generally each sub-project has an independent template directory, rather than being placed in one directory. The location is {proj}/Templates, for example Luban.Csharp/Templates. In order to reproduce these module files to the release directory when they are finally released, for each template file, you need to right-click -> properties, and set the copy option to Copy Always or Copy if newer.

Custom template search path after publishing

After publishing, all template files will be copied to the Templates directory of the output directory. If you need to customize the template, although you can directly modify the template file in the Templates directory, it will overwrite your own implementation every time you update Luban, which is not very convenient. You can use the command line parameter "--customTemplateDir ${templatir}" to specify the preferred search path.

Code Template Environment Variables

For languages such as cs that require enum, bean, table, and tables to generate different code files separately, a default mechanism is provided for generating templates for each type of object.

enum

variable namedescription
__ctxCurrent GenerationContext variable
__nameenum name
__namespaceNamespace of the enumeration
__top_moduleThe top-level namespace, namely target.TopModule
__namespace_with_top_moduleNamespace containing topModule
__full_name_with_top_modulecontains the full name of topModule
__enumcurrent enumeration definition object
__thissame as __enum
__code_stylecurrent code style

beans

variable namedescription
__ctxCurrent GenerationContext variable
__manager_nametarget.manager value
__manager_name_with_top_moduletarget.manager containing topModule
__namestructure name
__namespaceNamespace
__top_moduleThe top-level namespace, namely target.TopModule
__namespace_with_top_moduleNamespace containing topModule
__full_name_with_top_modulecontains the full name of topModule
__beancurrent bean definition object
__thissame as __bean
__code_stylecurrent code style

table

variable namedescription
__ctxCurrent GenerationContext variable
__manager_nametarget.manager value
__manager_name_with_top_moduletarget.manager containing topModule
__namestructure name
__namespaceNamespace
__top_moduleThe top-level namespace, namely target.TopModule
__namespace_with_top_moduleNamespace containing topModule
__full_name_with_top_modulecontains the full name of topModule
__tablecurrent table definition object
__thisSame as __table
__code_stylecurrent code style
__key_typekey type of table
__value_typeThe value type of the table

tables

variable namedescription
__ctxCurrent GenerationContext variable
__nametarget.manager value
__namespacetarget.topModule
__tableslist of currently exported tables
__thisSame as __table
__code_stylecurrent code style