shenie / google_ajax_libraries_api forked from rpheath/google_ajax_libraries_api
- Source
- Commits
- Network (3)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Thu Jun 26 10:57:59 -0700 2008 | |
| |
README.textile | ||
| |
Rakefile | Thu Jun 26 10:57:59 -0700 2008 | |
| |
init.rb | Thu Jun 26 10:57:59 -0700 2008 | |
| |
lib/ | ||
| |
spec/ | ||
| |
uninstall.rb | Thu Jun 26 10:57:59 -0700 2008 |
Google Ajax Libraries API (for Rails)
The AJAX Libraries API is a content distribution network and loading architecture for the most popular open source JavaScript libraries. (See http://code.google.com/apis/ajaxlibs/ for more details)
This is nothing more than a Rails plugin that provides a convenient interface for these libraries.
Usage
There are a couple of ways to get access to your library of choice. At this point, there are five supported libraries: jquery, prototype, scriptaculous, mootools, and dojo. This plugin supports them all. To include a library, you can use the convenience helpers in the head of your layout:
<%= google_mootools -%>
<%= google_jquery :version => '1.2.3' -%>
<%= google_prototype :uncompressed => true -%>
<%= google_dojo :version => '1.1.1', :uncompressed => true -%>
You get the idea. By default, the version will be the highest version supported. For instance, jQuery has two supported versions right now: 1.2.3 and 1.2.6. If you want to use 1.2.6, just use <%= google_jquery -%>.
If you need/want to load a few libraries at once, use the google_javascripts() helper, like so:
<%= google_javascripts :prototype, :scriptaculous, :jquery -%>
<%= google_javascripts :prototype, :scriptaculous, :jquery, :uncompressed => true -%>
If you want to use local javascript libraries instead of google libraries when you are not in production mode then add the fallback option, like so:
<%= google_jquery :version => '1.2.3', :fallback => 'jquery-1.2.3.min.js' -%>
It will still use google libraries when not in production mode if :fallback option is not provided.
You can also pass options to the underlying javascript_include_tag method by using the fallback_opts option, like so:
<%= google_jqueryui :fallback => ['jquery-ui/ui.core.js', 'jquery-ui/effects.core.js'], :fallback_opts => { :cache => "jquery-ui" } -%>
Pretty straight-forward. I should note, though, if you’re specifying a few libraries at once, the :version option becomes irrelevant, as I’d have no clue which library you were specifying a version for. And if you pass the :uncompressed option, it will apply to all libraries that support an uncompressed version.
I’m sure the code could be improved upon, as I wrote this farely quickly because I started using it in a few of my projects. Feel free to suggest changes and/or “fork and improve”.
Keeping up-to-date
Google is usually on top of things. I’m sure they’ll be supporting more and more libraries as they come out (or become more popular). Fortunately, it’s easy to add a new library to this plugin. Just modify the code located in lib/google_ajax_libraries_api/constants.rb, mimicking the existing library format. (Note: adding a new library in constants.rb will dynamically create a google_newlib helper, so there’s nothing else that needs to be done!)
License
Copyright © 2008 Ryan Heath, released under the MIT license

