Book Image

CoffeeScript Application Development

By : Ian Greenleaf Young
Book Image

CoffeeScript Application Development

By: Ian Greenleaf Young

Overview of this book

JavaScript is becoming one of the key languages in web development. It is now more important than ever across a growing list of platforms. CoffeeScript puts the fun back into JavaScript programming with elegant syntax and powerful features. CoffeeScript Application Development will give you an in-depth look at the CoffeeScript language, all while building a working web application. Along the way, you'll see all the great features CoffeeScript has to offer, and learn how to use them to deal with real problems like sprawling codebases, incomplete data, and asynchronous web requests. Through the course of this book you will learn the CoffeeScript syntax and see it demonstrated with simple examples. As you go, you'll put your new skills into practice by building a web application, piece by piece. You'll start with standard language features such as loops, functions, and string manipulation. Then, we'll delve into advanced features like classes and inheritance. Learn advanced idioms to deal with common occurrences like external web requests, and hone your technique for development tasks like debugging and refactoring. CoffeeScript Application Development will teach you not only how to write CoffeeScript, but also how to build solid applications that run smoothly and are a pleasure to maintain.
Table of Contents (19 chapters)
CoffeeScript Application Development
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Index

CoffeeScript support in the editor


Let's add support for CoffeeScript to your favorite text editor. This step is optional, but I heartily recommend it. At a minimum, these plugins will provide syntax highlighting for CoffeeScript files, which I find very helpful. In addition, most plugins integrate with the editor to allow you to run or compile CoffeeScript snippets without leaving the editor. You don't need these features, but you may find them convenient.

Tip

We'll discuss CoffeeScript support in some of the most popular editors, but there are plugins available for many more. A full list is available on the CoffeeScript wiki at https://github.com/jashkenas/coffee-script/wiki/Text-editor-plugins/.

Follow the instructions to install CoffeeScript in your editor of choice. After installing, restart your editor and try it out by opening setup.coffee. You will see some simple syntax highlighting on the code we just wrote to indicate that the plugin is working correctly.

Support in TextMate

Jeremy Ashkenas, the creator of CoffeeScript, has written a TextMate bundle that provides syntax highlighting, snippets, and inline compilation. Visit the project homepage at https://github.com/jashkenas/coffee-script-tmbundle and follow the installation instructions.

Support in Sublime Text 2

Sublime Text users have several choices available for CoffeeScript support.

One option is to use parts of the TextMate bundle. To use this, create a CoffeeScript directory in Sublime Text's plugin directory (on OS X, this is found at ~/Library/Application Support/Sublime Text 2). Then, download the bundle, extract Syntaxes/CoffeeScript.tmLanguage and Preferences/CoffeeScript.tmPreferences and place these files in the new directory. To simplify the process, you can download these two files directly using the following URLs:

The other option is to use the native Sublime Text plugin for CoffeeScript. This offers more features and is built specifically for Sublime Text. Visit the project homepage at http://xavura.github.io/CoffeeScript-Sublime-Plugin/ and follow the installation instructions.

Support in Vim

A Vim script is available that provides syntax highlighting as well as a :CoffeeCompile command to compile CoffeeScript on the fly. Visit the project homepage at https://github.com/kchmck/vim-coffee-script/ and follow the installation instructions.

Tip

The official repository for this plugin may be abandoned by the original maintainer, and there are several annoying bugs that have gone unfixed. You may wish to install a patched version from one of the several active forks of the project instead, such as https://github.com/CITguy/vim-coffee-script/. Follow the provided installation instructions, but be sure to download files from GitHub and not vim.org. Substitute the fork you are using whenever the instructions specify kchmck/vim-coffee-script.

Support in Emacs

There is an Emacs Major Mode named coffee-mode that provides syntax highlighting, menu support, and on-the-fly compiling. Install it from the Emacs package archive, or visit the project homepage at https://github.com/defunkt/coffee-mode for more information.