Giter Site home page Giter Site logo

lapluviosilla / google_ajax_libraries_api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rpheath/google_ajax_libraries_api

2.0 1.0 0.0 201 KB

Rails plugin: implements Google's Content Delivery Network for all javascript libraries currently supported by their library API.

Home Page: http://rpheath.com/posts/375-google-ajax-libraries-api

License: MIT License

Ruby 100.00%

google_ajax_libraries_api's Introduction

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 -%>

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”.

Got Internet?

In the rare event that your internet connection has gone missing (it happens, believe it or not), you can specify to load the file from your local javascripts folder by passing the :local option.

<%= google_jquery :local => true %>

This would just look for ‘jquery.js’ in your public/javascripts folder. In the event that you don’t have a local copy, well, I guess you won’t be doing any javascript :-)

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

google_ajax_libraries_api's People

Contributors

handcrafted avatar lapluviosilla avatar mjonuschat avatar rpheath avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.