Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Simple helper for togglin' jQuery from Google's CDN/local app seamlessly on your Rails/Sinatra application.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
Octocat-spinner-32 jquery_tag.gemspec
README.markdown

Jquery_tag

Build Status

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.

To know more about the benefits of using a CDN for your common Javascript frameworks, check this Chris Coyier post at CSS-Tricks.

Installation

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 public/javascripts/jquery.js. You can check the available options running it with the -h flag.

Usage

Inside your views, you can just call the jquery_tag method.

<%= 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 javascript_include_tag helper, if inside a Rails application. The Sinatra Helper currently ignores any extra option.

Sinatra

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 ./public/javascripts/ folder (or whatever the Sinatra public path is configured on your application).

Something went wrong with that request. Please try again.