Sinatra::JS

A Sinatra Extension that makes working with JS easy.

Installation

#  Add RubyGems.org (former Gemcutter) to your RubyGems sources 
$  gem sources -a http://rubygems.org

$  (sudo)? gem install sinatra-js

Dependencies

This Gem depends upon the following:

Runtime:

  • sinatra ( >= 1.0.a )
  • sinatra-tags ( >= 0.1.0 )
  • sinatra-outputbuffer ( >= 0.1.0 )
  • sinatra-basics ( >= 0.5.0 )

Optionals:

  • sinatra-settings (>= 0.1.1) # to view default settings in a browser display.
  • sinatra-logger (>= 0.1.0) # to capture error messages in the log file.

Development & Tests:

  • sinatra-tests (>= 0.1.6)
  • rspec (>= 1.3.0 )
  • rack-test (>= 0.5.3)
  • rspec_hpricot_matchers (>= 0.1.0)

Getting Started

To start using Sinatra::JS, just require and register the extension in your App...

require 'sinatra/js'

class YourApp < Sinatra::Base
register(Sinatra::JS)

<snip...>

end

You then get access to 6 useful helper methods:

js() / javascript()

This method serves two purposes:

a) Return a stylesheet tag with the path given.

js('jquery') # => 

<script src="/jquery.js" type="text/javascript" charset="utf-8"></script>

js('/js/jquery-tools.js') # => 

<script src="/js/jquery-tools.js" type="text/javascript" charset="utf-8"></script>

You can even pass an array of files to the method, which then outputs the