A Helper gem for both Rails and Sinatra for toggling between a local jquery.js file or the hosted script on Google's CDN based on your application environment, avoiding network dependency during development and bandwidth usage when your application goes live. It also supports the same behavior for a loading the jQuery UI script.
If you're using Bundler, just add the
jquery_tag to your Gemfile and run
bundle install. If not,
gem install jquery_tag and
require 'jquery_tag' inside your application code.
To download the latest jQuery script to your application just run
jquery_tag command inside your Terminal and the script will be downloaded to
Inside your views, you can just call the
<%= jquery_tag %>
It accepts a some configuration options by using the following symbols:
:version # Overrides the script version on the CDN URL. Defaults do '1.7.0' :file # Path for the local script. Defaults do 'jquery.js' :ui # Loads jQuery UI. Accepts a true value for loading a 'jquery-ui.js' file or a String for the local path.
Any other arguments will be passed along to the
To use the
jquery_tag on your Sinatra applications, just include the
JqueryTag::SinatraHelper on your application
require 'jquery_tag' # if your not using Bundler. class Application < Sinatra::Base helpers do include JqueryTag::SinatraHelper end end
Just call the
jquery_tag helper inside your views or layouts, as in the example above. Your local scripts should be located inside a