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
Karl Bryan Paragua 5e2db4b43b Update README.md
2012-12-19 15:28:29 +08:00
app/views/paloma callback tests 2012-12-19 14:59:38 +08:00
lib callback tests 2012-12-19 14:59:38 +08:00
spec callback tests 2012-12-19 14:59:38 +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-19 15:28:29 +08:00

Paloma

Paloma provides a sexy way to organize javascript files using Rails' asset pipeline. It adds the capability to execute specific javascript code after rendering the controller's response.

Install

Add the following line to the Gemfile:

gem 'paloma'

Setup

On setup, the paloma folder will be generated in app/assets/javascripts/. Inside this folder, paloma.js and index.js will also be created.

Execute the following command in the terminal:

rails g paloma:setup

Usage

Execute the following command 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>

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

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

Generated Files

###paloma.js Declaration of namespace used in all callbacks

# app/assets/javascripts/paloma/paloma.js

window.Paloma = {callbacks:{}};

###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/paloma/index.js

//= require ./paloma

//= require ./<controller_name>/callbacks

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

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

//= require_tree .

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

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

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