Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding custom folder to asset pipeline in Grails

I have a Grails application. I have the js, css and image folder in the web-app and in the same folder I have a themes folder. I am planning to use the asset pipeline plugin. How should I use my themes folder? I have files with the same names in the core folders and the themes folder. Any help on this?

like image 325
Swaprks Avatar asked Dec 24 '22 15:12

Swaprks


1 Answers

Custom folders are supported in the asset pipeline. I will show you an example using Bootstrap.

We create a root level directory in the assets folder called themes, this is where we will store third party scripts. You can name this anything you like, E.G., lib, libraries, vendor, plugins.

assets/
    images/
    javascript/
        application.js
    stylesheets/
        application.css
    themes/
        bootstrap/
            js/
                bootstrap.js
                bootstrap.min.js
            css/
                bootstrap.css
                bootstrap.min.css

You can then access these files from the custom folder like so:

// application.js
//= require bootstrap/js/bootstrap.js

// application.css
/*= require bootstrap/css/bootstrap.css */

// In a gsp
<asset:javascript src="bootstrap/js/bootstrap.js"/>

The require directives ignore the first directory in the asset folder. This allows you to modularise and organise your assets nicely.

You might need to restart your grails application when adding a new top level asset directory.

like image 139
Lewis Norton Avatar answered Jan 03 '23 17:01

Lewis Norton