Git Product home page Git Product logo

groovy-template-grails-asset-pipeline's Introduction

Groovy Template Grails Asset Pipeline Plugin

This plugin lets you use Groovy expressions in your Javascript and CSS asset files and participates in the Grails Asset Pipeline Plugin pre-compilation.

This lets you get access to config and environment variables during the pre-compilation process so that you can easily serve up static files with content that is crafted for that application.

You get the grailsApplication and config objects injected into the binding for when expressions are evaluated:

ex:

Confg.groovy

...
grails.serverURL = "https://mycompany.com/"
...

application.js-gtpl:

//= require_self

var serverURL = "${config.grails.serverURL}";

creates application.js:

//= require_self

var serverURL = "https://mycompany.com/";

You can also execute more complicated expressions inside <% ... %> blocks, see the jasmine tests for more examples.

NB: be sure to make sure when you build your war file that you're using the right environment to get the correct values out of Config.groovy.

Currently, there is support for javascript files (with the extension .js-gtpl) and CSS files (with the extension .css-gtpl).

Some scenarios that this plugin enables:

  • extracting the base path for urls out of config, so you can refer to asset paths in JS/CSS at /your-app/<filepath> in dev but at just /<filepath> in test/prod environments.
  • creating a javascript array to hold your enum values for drop-downs and radio buttons
  • putting a timestamp/version/git hash in a comment in your assets so you can easily tell when they were built

All of these things are possible without this plugin by doing a callback to the server, or within a script block inside your GSP files, but those are slower, clunkier solutions.

groovy-template-grails-asset-pipeline's People

Contributors

tednaleid avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.