Taglib is not processing CSS refering external folder

78 Views Asked by At

On migrating from Grails 2.5 to Grails 3 it is recommended that not to use the resource plugin as post Grails 3 resource plugin is deprecated. As a alternative I used asset pipeline.Is there a recommended method of replacing resources plugin modules when moving to the asset-pipeline plugin? Custom tags are used in GSP files which are suppose to include the content from the CSS files. Currently I am creating empty .js or .css files that require the resources that were in the module, then replace CSS content referring to the empty file. If there is a better way to do this?

<html>
<head>
<g:layoutHead/>
<r:layoutResources />
<r:external uri="/css/mycss.css" type="css" />
<g:customStylesheetIncludes/>
</head>
<body>
<g:layoutBody/>
<r:layoutResources />
</body>
</html>

Which is going to be handled by the custom taglib :

class MyResourcesTagLib {

    def customStylesheetIncludes = { attrs ->
        def controller = attrs.controller ?: controllerName
        def action = attrs.action ?: actionName

        writeCssIfExists( out, "css/my-custom.css" )

        // Determine the current page
        writeCssIfExists( out, "css/views/$controller/${action}-custom.css" )
    }

    private resourceExists( resPath ) {
        return grailsApplication.parentContext.getResource( resPath ).file.exists()
    }

    private writeCssIfExists( writer, css ) {
        if (resourceExists(css)) {
            def baseUri = grailsAttributes.getApplicationUri(request)

            baseUri += (baseUri.endsWith('/') ? '' : '/')

            writer << r.external(uri: baseUri, type: 'css')
        }
    }
}

How can I handle the same using asset pipeline in Grails 3, any suggestions or lead is highly appreciated

1

There are 1 best solutions below

0
On

A possible workaround would to create a Gradle task which copies those assets in the external folder to the appropriate grails-app/assets folders