1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00
page-specific javascript for Rails done right
Find a file
2012-12-18 18:39:33 +08:00
app/views/paloma Basic structure 2012-12-17 16:38:52 +08:00
lib starting with tests 2012-12-18 18:39:33 +08:00
spec starting with tests 2012-12-18 18:39:33 +08:00
.gitignore updated .gitignore. working sample_app 2012-12-18 12:26:30 +08:00
Gemfile creating test app 2012-12-17 18:50:23 +08:00
Gemfile.lock starting with tests 2012-12-18 18:39:33 +08:00
paloma.gemspec starting with tests 2012-12-18 18:39:33 +08:00
Rakefile creating test app 2012-12-17 18:50:23 +08:00
README.md Update README.md 2012-12-18 17:47:24 +08:00

paloma

Javascript Callback Manager for Rails 3

Install

Add the following line to the Gemfile:

gem 'paloma'

Usage

On the first run of either of the two commands mentioned below, the callbacks folder will be generated in app/assets/javascripts/. Inside the callbacks folder, index.js will also be created.

The following are the commands which can be executed in the terminal to generate files needed for the callbacks:

rails g paloma:add <controller_name>

Execute the command above to generate a folder, named as <controller_name> which will be the container of all the callbacks that will be used within that controller. Inside this folder, callbacks.js will also be generated.

rails g paloma:add <controller_name>/<action_name>

This command allows the user to create the file <action_name>.js under the <controller_name> folder.

Generated Files

###index.js Contains code for requiring all callbacks of all folders and is automatically updated when new folders and callback.js files are created

# app/assets/javascripts/callbacks/index.js

window.Paloma = {callbacks:{}};
//= require ./<controller_name>/callbacks

###callbacks.js Contains code for requiring all callbacks under the same folder <controller_name>

# app/assets/javascripts/callbacks/<controller_name>/callbacks.js

//= require_tree .

###<action_name>.js Actual code to be executed when callback is called

# app/assets/javascripts/callbacks/<controller_name>/<action_name>.js

Paloma.callbacks['<controller_name>/<action_name>'] = function(params){
    ...
    //put your code here
    ...
};