Skip to content

JavascriptComponents

nesquena edited this page Sep 13, 2010 · 4 revisions

This section covers the specifics of setting up an application using the sinatra_more generators and each javascript component.

jquery

To use jquery in your new project, simply invoke the generator:

sinatra_gen demo_app . -s jquery

Then you will need to require jquery in your template file or layout:

# app/views/layout.rb
#...
<head>
  # ...
   <%= javascript_include_tag 'jquery.min', 'application' %>
  # ...
</head>

Finally we can use jquery within our application:

# public/javascripts/application.js
$(document).ready(function() {
    // put all your jQuery goodness in here.
});

For more information on jquery, check out the jquery documentation

Prototype

To use prototype in your new project, simply invoke the generator:

sinatra_gen demo_app . -s prototype

Then you will need to require prototype in your template file or layout:

# app/views/layout.rb
#...
<head>
  # ...
   <%= javascript_include_tag 'prototype', 'lowpro', 'application' %>
  # ...
</head>

Finally we can use prototype within our application:

 # public/javascripts/application.js
document.observe('dom:loaded', function(ev) {
  // standard prototype here
});

Event.addBehavior({
  // lowpro behavior definitions here
});

For more information on prototype, check out the prototype documentation
For more information on lowpro, check out the lowpro blog (Lowpro really needs better docs!)

RightJS

To use rightjs in your new project, simply invoke the generator:

sinatra_gen demo_app . -s rightjs

To use rightjs in your new project, simply invoke the generator:

sinatra_gen demo_app . -s rightjs

Then you will need to require rightjs in your template file or layout:

# app/views/layout.rb
#...
<head>
  # ...
   <%= javascript_include_tag 'right-min', 'application' %>
  # ...
</head>

Finally we can use rightjs within our application:

# public/javascripts/application.js
document.onReady(function() {
  // put rightjs code here
});

For more information on rightjs, check out the RightJS documentation

Clone this wiki locally