Giter Club home page Giter Club logo

grails-coffeescript-resources's Introduction

This is a grails plugin that enables the easy inclusion of CoffeeScript in your Grails web application. It requires the well established resources plugin.

Background

As the author, Jeremy Ashkenas, says himself "CoffeeScript is a little language that compiles to JavaScript". CoffeeScript is an attempt to make writing JavaScript easier, more elegant, and more efficient.

The standard CoffeeScript compiler runs on NodeJs. This plugin is basically a bridge (via Mozilla's Rhino engine) to a browser compatible version of the compiler released by Jeremy Ashkenas. It uses CoffeeScript version 1.2.0.

Usage

To add coffee script resources to your grails project

  • Install the plugin
  • Actually add your CoffeeScript files to your project. I placed mine adjacent to the js folder in cs.
  • Reference your CoffeeScript files in your ApplicationResources file (or where ever you are defining your resources).

Example

js {
  resource url: 'js/app.js'
}
coffee {
  resource url: 'cs/views.coffee'
  resource url: 'cs/models.coffee'
}

Files should be located:

- web-app
 - js
    - app/.js
 - cs
    - views.coffee
    - models.coffee

The above example will create a resource you can include in pages or have another resource depend on. The CoffeeScript files are converted to JavaScript, and included like any of your JavaScript files. The default disposition for your CoffeeScript follows the JavaScript default: "defer" - that is they will appear at the end of your page.

Bare mode

Compile the JavaScript without the top-level function safety wrapper (--bare option for compiler).

Add option into Config.groovy:

grails.plugins.coffeescript.bare=true

Problems

Every resource module is compressed to bundle. By default .coffee files are not added to any bundle. In order to have it in the bundle you must explicitly declare bundle attribute for the resource line or defaultBundle for the module.

  modules {
    example1 {
      defaultBundle 'example1'
      resource url: 'cs/test.coffee'
    }

    exmaple2 {
      resource url: 'cs/test.coffee', bundle: 'example1'
    }
  }

Plugin doesn't apply when you have enabled debug mode for resource plugin:

grails.resources.debug = true

It's because resource plugin disable processing, when debug is enabled, see resource plugin docs

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.