public
Description: Red writes like Ruby and runs like JavaScript.
Home | Edit | New

Tutorial: Red for Rails

The r is for Rails in red -r

To start turning your JavaScript {color: #C00}Red, navigate to the root directory of your Rails project and execute red -r.

This accomplishes two things:

  1. it builds the {color: #C00}Red plugin into vendor/plugins/red;
  2. it creates the public/javascripts/red folder.

vendor/plugins/red

Since the nuts and bolts of {color: #C00}Red hide in your gem folders, vendor/plugins/red contains only one tiny, powerful file: init.rb, which tells Rails that {color: #C00}Red is writing your JavaScript from now on.

public/javascripts/red

The public/javascripts/red folder is where you keep your .red application files. In development mode, every time you update a .red file and make a server request, {color: #C80404}Red generates a new .js file in public/javascripts. In production mode, each .js file is generated once and only once, upon the first request after server startup.

public/javascripts/red/lib

Using require statements in {color: #C80404}Red allows you to write your own libraries and access them dynamically. To load the Redshift DOM scripting library , add require 'redshift' to the top of your .red application file. To load a library located at public/javascripts/red/lib/my_library.red, add @require ‘lib/my_library’.

The Command-Line Executable red in Rails

When you work outside of a Rails project, creating filename.red and running red filename will create a file in the same directory called filename.js. The same command from within the root of your Rails project will convert the file public/javascripts/red/filename.red into public/javascripts/filename.js.

Last edited by jessesielaff, Fri Nov 07 15:01:23 -0800 2008
Home | Edit | New
Versions: