Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
JavaScript Ruby CoffeeScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
assets
public/assets
views
.gitignore
.rvmrc.example
Gemfile
Gemfile.lock
README.md
Rakefile
app.rb
config.ru

README.md

Quick 'n' Dirty

  • Painless CoffeeScript development inside of the familiar Sinatra platform.
  • Compile CoffeeScript automatically on browser refresh in development mode
  • Emulates Rails 3.1's asset pipeline
  • Automatically compiles and serves static javascript files in production mode.

Prerequisites:

Setup directory

git clone git@github.com:hjhart/exploring_backbone.git
cd exploring_backbone
cp .rvmrc.example .rvmrc

(optional) Open up your new .rvmrc file and change the gemset to the name of your project name (or whatever else you want it to be) Change the environment variable if you don't want to work with ruby-1.9.2.

source .rvmrc 

When prompted to trust the file, say yes. This will create the gemset and run bundler. This actually takes a while for therubyracer to install.

Where do my coffeescript files go?

All of your coffeescript files will go into the assets folder. When you want to link to them from a view, link to /assets/[filename].js

Where do my javascript files go?

Place static javascript files inside of public/assets. You can link to the static files the same way.

Example:

Place a coffescript file named utils.coffee inside of the assets directory. Place a static javascript file named backbone.js inside of your public/assets directory

Linking to them is consistent and is very simple:

<script src="/assets/utils.js" type="text/javascript"></script> # this compiles the coffeescript
<script src="/assets/backbone.js" type="text/javascript"></script> # this loads the static javascript

In development mode, /assets/utils.js will compile the coffeescript on every refresh. In production mode, it will server the compiled javascript file from public/assets (see notes below)

Start up the server in development

rackup

Start up the server in production

Production is as simple as running

rackup -E production. 

This will run the js:compile rake task and dump the compiled javascripts within the public/assets/ folder where they'll be fed as static resources.

Feedback:

Message me on twitter @hjhart, or, submit issues on github.

Counter

Something went wrong with that request. Please try again.