CoffeeScript

This project is not covered by Drupal’s security advisory policy.

For now I'd recommend using a preprocessor such as Atom or CodeKit until CoffeeScript PHP is made current.

CoffeeScript is a simple and elegant version of JavaScript.

This module provides CoffeeScript integration with Drupal, allowing you to write CoffeeScript code, which is automatically converted into JavaScript for use by the browser. CoffeeScript can also be used in combination with jQuery and some examples are below.

Usage

Add CoffeeScripts to your Drupal site by using one of the following:
<?php print drupal_add_js('script.coffee') ?> in your theme's html.tpl.php
scripts[] = script.coffee in your theme's .info file

Installation

Requires the Libraries and Prepro APIs.

  1. Download the CoffeeScript PHP library from GitHub.
  2. Place the extracted folder in your sites/all/libraries folder
  3. Download and enable this module

Examples

In CoffeeScript, the function keyword is replaced by the -> symbol, and indentation is used instead of curly braces.

A Drupal 7 jQuery before and after:

(function ($) {
  Drupal.behaviors.myCode = {
    attach: function (context, settings) {
      $('.button', context).click(function () {
        $(this).next('ul').toggle('show');
      });
    }
  };
})(jQuery);
$ = @jQuery

@Drupal.behaviors.myCode =
  attach: (context, settings) ->
    $(".button", context).click ->
      $(this).next("ul").toggle "show"

Project information

  • caution Seeking co-maintainer(s)
    Maintainers are looking for help reviewing issues.
  • caution Maintenance fixes only
    Considered feature-complete by its maintainers.
  • chart icon3 sites report using this module
  • Created by Maedi on , updated
  • shield alertThis project is not covered by the security advisory policy.
    Use at your own risk! It may have publicly disclosed vulnerabilities.

Releases