2012-12-19 02:28:10 -05:00
|
|
|
Paloma
|
2012-12-17 02:11:02 -05:00
|
|
|
======
|
2012-12-19 02:28:10 -05:00
|
|
|
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.
|
|
|
|
|
2012-12-19 02:56:52 -05:00
|
|
|
Advantages
|
|
|
|
-
|
|
|
|
* Javascript files are organized per controller just like app/views folder of Rails.
|
|
|
|
* Javascript file per controller's action.
|
|
|
|
* The ability to choose what specific javascript code to run on a specific action.
|
|
|
|
|
|
|
|
Quick Example
|
|
|
|
-
|
|
|
|
The javascript callback file `paloma/users/new.js`:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
Paloma.callbacks['users/new'] = function(params){
|
|
|
|
// This will only run after executing users/new action
|
|
|
|
alert('Hello New Sexy User');
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
The Rails controller `app/controllers/users_controller.rb`:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
def UsersController < ApplicationController
|
|
|
|
def new
|
|
|
|
@user = User.new
|
|
|
|
# No special function to call, the javascript callback will be executed automatically
|
|
|
|
end
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
That's it! Simply Sexy!
|
|
|
|
|
|
|
|
Minimum Requirements
|
|
|
|
-
|
|
|
|
* jQuery 1.7 or higher
|
|
|
|
* Rails 3.1 or higher
|
|
|
|
|
2012-12-18 04:47:24 -05:00
|
|
|
|
|
|
|
Install
|
2012-12-19 02:56:52 -05:00
|
|
|
-
|
|
|
|
Without bundler:
|
|
|
|
```
|
|
|
|
sudo gem install paloma
|
|
|
|
```
|
2012-12-18 23:16:11 -05:00
|
|
|
|
2012-12-19 02:56:52 -05:00
|
|
|
With bundler, add this to your Gemfile:
|
|
|
|
```
|
|
|
|
gem paloma
|
|
|
|
```
|
2012-12-18 23:16:11 -05:00
|
|
|
|
|
|
|
Setup
|
2012-12-19 03:20:52 -05:00
|
|
|
-
|
|
|
|
On setup, the `paloma` folder will be generated in `app/assets/javascripts/` containing its required files. Run:
|
|
|
|
```
|
|
|
|
rails g paloma:setup
|
|
|
|
```
|
2012-12-18 23:16:11 -05:00
|
|
|
|
2012-12-19 04:15:35 -05:00
|
|
|
Directory Structure
|
|
|
|
-
|
|
|
|
`paloma` folder contains the javascript callbacks.
|
|
|
|
|
|
|
|
* paloma
|
|
|
|
* [controllers]
|
|
|
|
* [action].js
|
|
|
|
* [other_action].js
|
|
|
|
* [other_controllers]
|
|
|
|
* [action].js
|
|
|
|
* [other_action].js
|
|
|
|
* [more_action].js
|
2012-12-18 04:47:24 -05:00
|
|
|
|
|
|
|
Usage
|
2012-12-19 04:15:35 -05:00
|
|
|
-
|
2012-12-19 05:01:25 -05:00
|
|
|
1. Generate a controller folder containing its required files:
|
|
|
|
```
|
|
|
|
rails g paloma:add [controllers]
|
|
|
|
```
|
|
|
|
**Example:**
|
|
|
|
```
|
|
|
|
rails g paloma:add users
|
|
|
|
```
|
|
|
|
|
|
|
|
**Generates:**
|
|
|
|
* /paloma
|
|
|
|
* /users
|
|
|
|
|
|
|
|
|
|
|
|
2. Generate a callback file for a controller's action:
|
|
|
|
```
|
|
|
|
rails g paloma:add [controllers]/[action]
|
|
|
|
```
|
|
|
|
**Example:**
|
|
|
|
```
|
|
|
|
rails g paloma:add users/new
|
|
|
|
```
|
|
|
|
|
|
|
|
**Generates:**
|
|
|
|
* /paloma
|
|
|
|
* /users
|
|
|
|
* new.js
|
|
|
|
|
2012-12-18 04:47:24 -05:00
|
|
|
|
2012-12-19 05:01:25 -05:00
|
|
|
**Note:** You can directly run `rails g paloma:add [controllers]/[action]` even the controller folder is not yet
|
|
|
|
existing on `paloma` folder. It will be created automatically.
|