Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Guard::CoffeeScript automatically compiles your CoffeeScripts
Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib/guard
spec
.gitignore
Gemfile
Guardfile
LICENSE
README.rdoc
Rakefile
guard-coffeescript.gemspec

README.rdoc

Guard::CoffeeScript

Guard::CoffeeScript compiles you CoffeeScripts automatically when files are modified.

  • Tested on Ruby 1.8.7 & 1.9.2.

Install

Please be sure to have guard installed before continue.

Install the gem:

gem install guard-coffeescript

Add it to your Gemfile (inside test group):

gem 'guard-coffeescript'

Add guard definition to your Guardfile by running this command:

guard init coffeescript

CoffeeScript

Guard::CoffeeScript uses Ruby CoffeeScript to compile the CoffeeScripts. This enables the guard to compile the CoffeeScripts with node.js, JavaScript Core or V8

node.js

Please refer to the CoffeeScript documentation for more information about how to install the latest CoffeeScript version on node.js.

JavaScript Core

JavaScript Core is only available on Mac OS X. To use JavaScript Core you don't have to install anything, because JavaScript Core is packaged with Mac OS X.

V8

To use CoffeeScript on V8, simple add `therubyracer` to your Gemfile. The Ruby Racer acts as a bridge between Ruby and the V8 engine, that will be automatically installed by the Ruby Racer.

group :development do
  gem 'therubyracer'
end

Usage

Please read guard usage doc

Guardfile

CoffeeScript guard can be adapated to all kind of projects. Please read guard doc for more info about Guardfile DSL.

Standard ruby gems

guard 'coffeescript' do
  watch(%r{coffeescripts/.+\.coffee})
end

Rails app

guard 'coffeescript', :output => 'public/javascripts/compiled' do
  watch(%r{app/coffeescripts/.+\.coffee})
end

Options

There following options can be passed to the CoffeeSCript Guard:

:output => 'javascripts'            # Relative path to the output directory
:bare => true                       # Compile without the top-level function wrapper
:shallow => true                    # Do not create nested output directories

Nested directories

The guard detects by default nested directories and creates these within the output directory. The detection is based on the match of the watch regular expression:

A file

/app/coffeescripts/ui/buttons/toggle_button.coffee

that has been detected by the watch

watch(%r{app/coffeescripts/.+\.coffee})

with an output directory of

:output => 'public/javascripts/compiled'

will be compiled to

public/javascripts/compiled/ui/buttons/toggle_button.js

This behaviour can be switched off by passing the option `:shallow => true` to the guard, so that all JavaScripts will be compiled directly to the output directory.

Development

Pull requests are very welcome! Make sure your patches are well tested.

Authors

Michael Kessler

Acknowledgment

Many thanks to the Guard Team and all the authors of the numerous Guards

Something went wrong with that request. Please try again.