自定义 Grails 3 脚本中渲染模板的工件目录

Artifact directory for rendering template in custom Grails 3 script

在 Grails 3.2.3 文档中,将这段代码显示为自定义脚本的示例:

def scriptName = args[0]
def model = model(scriptName)
def overwrite = flag('force') ? true : false

render  template: template('artifacts/Script.groovy'),
    destination: file("src/main/scripts/${model.lowerCaseName}.groovy"),
    model: model,
    overwrite: overwrite

grails-app 或 src 层次结构中的工件目录在哪里?

对于您引用的示例,artifacts 目录位于配置文件的 jar 文件中。

(相关出处是:https://github.com/grails-profiles/base/tree/master/templates

一般来说,任何具有模板目录的配置文件或插件都可以在配置文件或插件的 jar 中找到。

但是您的项目可以覆盖配置文件或插件中的任何内容。对于根植于 src/main/templates.

项目中的不同类型的模板,您遵循相同的模式

例如,如果你说

grails install-templates

将创建一个目录 src/main/templates/scaffolding,其中包含脚手架插件应用的模板的副本,您可以编辑该模板以自定义脚手架视图、生成的控制器等的渲染方式。

对于脚本模板,路径是 artifacts 而不是 scaffolding,所以如果您有脚本模板或域 class 模板,您比默认模板更喜欢,您会放入

src/main/templates/artifacts