Grails - 从资源迁移到资产管道插件
Grails - migrating from the resources to the asset-pipeline plugin
我一直在尝试根据 Grails In Action 中的一章在我的 Grails 应用程序中安装 angularjs/restangular js 库。问题是本书中的代码使用了 resources 插件,在我使用的 Grails (2.4) 版本中,该插件已被 asset-pipeline 插件.
我已尝试使用 the official documentation 作为指南来实现本书代码,但所需的 javascript 未包含在我的 gsp 文件中。此外,我的 gsp 文件中对 <r:layoutResources/>
和 <r:require module="core"/>
的引用在 GGTS 编辑器中被突出显示为 "unknown tags"。
谁能告诉我从 resources 插件迁移到 asset-pipeline 哪里出错了?具体来说,我已将以下 js 库 复制到我的 web-app/js 文件夹中:
我想定义这些模块之间的依赖关系,所以我创建了以下 conf\ApplicationResources.groovy
:
modules = {
angularjs {
resource url:'js/angular-1.3.15.js', disposition: 'head'
}
restangular {
dependsOn 'angularjs'
resource url:'js/restangular-1.4.0.js'
}
lodashjs {
resource url:'js/lodash-3.6.0.js'
}
core {
dependsOn 'restangular, lodashjs'
resource url:'/js/custom.js'
}
}
并且views\layout\main.gsp
包含:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title><g:layoutTitle default="Grails"/></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="${assetPath(src: 'favicon.ico')}" type="image/x-icon">
<link rel="apple-touch-icon" href="${assetPath(src: 'apple-touch-icon.png')}">
<link rel="apple-touch-icon" sizes="114x114" href="${assetPath(src: 'apple-touch-icon-retina.png')}">
<asset:stylesheet src="application.css"/>
<asset:javascript src="application.js"/>
<g:layoutHead/>
<r:layoutResources/> <-- why is this highlighted as 'unknown'?
</head>
和views\post\singlepage.gsp
:
<head>
<title>Timeline for ${ user.userid }</title>
<meta name="layout" content="main"/>
<content tag="htmlAttrs">ng-app="testsparestang"</content>
<r:require module="core"/> <-- again, this is unknown!
</head>
如果您想使用资源插件,请评论您的 BuildConfig.groovy 文件中的资产管道插件代码。
如果你想使用 asset-pipeline,那么只需注释 BuildConfig.groovy 中的资源插件。
现在确保从布局中删除 标记,因为这仅适用于资源插件,资产管道不需要。
标签也来自资源插件。所以根据资产管道
改变它
我一直在尝试根据 Grails In Action 中的一章在我的 Grails 应用程序中安装 angularjs/restangular js 库。问题是本书中的代码使用了 resources 插件,在我使用的 Grails (2.4) 版本中,该插件已被 asset-pipeline 插件.
我已尝试使用 the official documentation 作为指南来实现本书代码,但所需的 javascript 未包含在我的 gsp 文件中。此外,我的 gsp 文件中对 <r:layoutResources/>
和 <r:require module="core"/>
的引用在 GGTS 编辑器中被突出显示为 "unknown tags"。
谁能告诉我从 resources 插件迁移到 asset-pipeline 哪里出错了?具体来说,我已将以下 js 库 复制到我的 web-app/js 文件夹中:
我想定义这些模块之间的依赖关系,所以我创建了以下 conf\ApplicationResources.groovy
:
modules = {
angularjs {
resource url:'js/angular-1.3.15.js', disposition: 'head'
}
restangular {
dependsOn 'angularjs'
resource url:'js/restangular-1.4.0.js'
}
lodashjs {
resource url:'js/lodash-3.6.0.js'
}
core {
dependsOn 'restangular, lodashjs'
resource url:'/js/custom.js'
}
}
并且views\layout\main.gsp
包含:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title><g:layoutTitle default="Grails"/></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="${assetPath(src: 'favicon.ico')}" type="image/x-icon">
<link rel="apple-touch-icon" href="${assetPath(src: 'apple-touch-icon.png')}">
<link rel="apple-touch-icon" sizes="114x114" href="${assetPath(src: 'apple-touch-icon-retina.png')}">
<asset:stylesheet src="application.css"/>
<asset:javascript src="application.js"/>
<g:layoutHead/>
<r:layoutResources/> <-- why is this highlighted as 'unknown'?
</head>
和views\post\singlepage.gsp
:
<head>
<title>Timeline for ${ user.userid }</title>
<meta name="layout" content="main"/>
<content tag="htmlAttrs">ng-app="testsparestang"</content>
<r:require module="core"/> <-- again, this is unknown!
</head>
如果您想使用资源插件,请评论您的 BuildConfig.groovy 文件中的资产管道插件代码。 如果你想使用 asset-pipeline,那么只需注释 BuildConfig.groovy 中的资源插件。 现在确保从布局中删除 标记,因为这仅适用于资源插件,资产管道不需要。 标签也来自资源插件。所以根据资产管道
改变它