Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails 3 - Add font resource folder

I can't find where I can tell grails to include a font folder with some font-face (font-awesome). In past version, it would be include in the config.groovy file, but it don't seems like it have one in the version 3. Where can I put this configuration to tell grails to take count of this folder when generating my views?

Thank you

like image 298
Emmurd Avatar asked Dec 20 '22 01:12

Emmurd


2 Answers

I am assuming you are used to using the resources plugin and not the asset pipeline which is what Grails 3 uses by default. From the upgrade guide:

Step 7 - Migrate Static Assets not handled by Asset Pipeline If you have static assets in your web-app directory of your Grails 2.x application such as HTML files, TLDs etc. these need to be moved. For public assets such as static HTML pages and so on these should go in src/main/resources/public.

TLD descriptors and non public assets should go in src/main/resources/WEB-INF.

As noted earlier, src/main/webapp folder can also be used for this purpose but it is not recommended.

This means you will need to pass your static resources through the asset pipeline plugin, installed by default in Grails 3. What is the asset pipeline?

The Grails Asset-Pipeline is a plugin used for managing and processing static assets in Grails applications. Asset-Pipeline functions include processing and minification of both CSS and JavaScript files. It is also capable of being extended to compile custom static assets, such as CoffeeScript or LESS.

Create a folder in your project at the following location:

grails-app/assets/fonts

Read the documentation on linking to assets and plugins.

Plugins Plugins also can have the same "grails-app/assets" folder and their URL mapping is also the same. This means it can be more important to ensure unique naming / path mapping between plugins. This is also powerful in the sense that a plugin can add helper manifests to be used within your apps like jquery, bootstrap, font-awesome, and more.

These plugins also differ in the fact that the assets within their web-app directory also become available under a similar structure

If you follow those directions you should be able to require the font-awesome resource in your GSP pages. You will need to spend a little time learning the asset pipeline. There is another option, you could also use the font awesome plugin.

like image 138
Nathan Avatar answered Jan 07 '23 23:01

Nathan


For the asset pipeline to know about the grails-app/assets/fonts directory, add includes = ["fonts/*"] to build.gradle, like this:

assets {
    minifyJs = true
    minifyCss = true
    includes = ["fonts/*"]
}

At first my fonts were still not showing up until after I did a grails clean.

like image 22
tbird Avatar answered Jan 08 '23 01:01

tbird