paloma 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -75,6 +75,9 @@ Directory Structure
75
75
  * [action].js
76
76
  * [other_action].js
77
77
  * [more_action].js
78
+ * [namespace]
79
+ * [controllers]
80
+ * [action].js
78
81
 
79
82
  Generators
80
83
  -
@@ -94,11 +97,11 @@ rails g paloma:add [controllers]
94
97
 
95
98
  2. Generate a callback file for a controller's action:
96
99
  ```
97
- rails g paloma:add [controllers]/[action]
100
+ rails g paloma:add [controllers] [action]
98
101
  ```
99
102
  **Example:**
100
103
  ```
101
- rails g paloma:add users/new
104
+ rails g paloma:add users new
102
105
  ```
103
106
 
104
107
  **Generates:**
@@ -107,7 +110,40 @@ rails g paloma:add [controllers]/[action]
107
110
  * new.js
108
111
 
109
112
 
110
- **Note:** You can directly run `rails g paloma:add [controllers]/[action]` even the controller folder is not yet
113
+ 3. Generate multiple callback files:
114
+ ```
115
+ rails g paloma:add [controllers] [action_1] [action_2] ... [action_n]
116
+ ```
117
+ **Example:**
118
+ ```
119
+ rails g paloma:add users new create edit update
120
+ ```
121
+
122
+ **Generates:**
123
+ * /paloma
124
+ * /users
125
+ * new.js
126
+ * create.js
127
+ * edit.js
128
+ * update.js
129
+
130
+ 4. Generate namespaced controller and callbacks:
131
+ ```
132
+ rails g paloma:add [namespace]/[controllers] [action_1] [action_2] ... [action_n]
133
+ ```
134
+
135
+ **Example:**
136
+ ```
137
+ rails g paloma:add admin/users new
138
+ ```
139
+
140
+ **Generates:**
141
+ * /paloma
142
+ * /admin
143
+ * /users
144
+ * new.js
145
+
146
+ **Note:** You can directly run `rails g paloma:add [controllers] [action]` or `rails g paloma:add [namespace]/[controllers] [action]` even the controller folder is not yet
111
147
  existing on `paloma` folder. It will be created automatically.
112
148
 
113
149
 
@@ -154,6 +190,23 @@ You can manipulate callback behavior by using the `js_callback` command before t
154
190
 
155
191
  This will execute `clients/index` callback instead of `[controllers]/index`.
156
192
 
193
+
194
+ 4. Using other action's callback from a namespaced controller.
195
+
196
+ ```ruby
197
+ class UsersController < ApplicationController
198
+ def destroy
199
+ @user = User.find params[:id]
200
+ @user.destroy
201
+
202
+ js_callback :controller => 'admin/users', :action => :destroy
203
+ end
204
+ end
205
+ ```
206
+
207
+ This will execute `admin/users/destroy` callback instead of `users/destroy`.
208
+
209
+
157
210
  Passing Parameters
158
211
  -
159
212
  You can also pass parameters to the callback by passing a `:params` key to `js_callback`. The passed parameters
@@ -185,7 +238,7 @@ Callback helpers are inside Paloma objects in order to prevent conflicts from di
185
238
 
186
239
  1. Global
187
240
 
188
- Helper functions and variables can defined in `paloma/paloma.js` inside the `Paloma.g` object.
241
+ Helper functions and variables can be defined in `paloma/paloma.js` inside the `Paloma.g` object.
189
242
 
190
243
  **Example:**
191
244
  ```javascript
@@ -197,7 +250,23 @@ Callback helpers are inside Paloma objects in order to prevent conflicts from di
197
250
  helper_variable: 1000
198
251
  };
199
252
  ```
253
+
254
+ 3. Namespace's Scope
255
+
256
+ Helper functions and variables that is shared inside a namespace can be defined in `paloma/[namespace]/_local.js` inside
257
+ the `Paloma.[namespace]` object.
200
258
 
259
+ **Example:**
260
+ ```javascript
261
+ Paloma.admin = {
262
+ namespaced_helper: function(){
263
+ // do something sexy
264
+ },
265
+
266
+ helper_variable: 1
267
+ };
268
+ ```
269
+
201
270
  2. Controller's Scope
202
271
 
203
272
  Helper functions that you will only use for a certain controller can be defined in `paloma/[controllers]/_local.js` inside
@@ -20,10 +20,16 @@ module Paloma
20
20
  def update_callback
21
21
  add_to_callbacks @__callback__, @__js_params__
22
22
 
23
- response_body[0] += view_context.render(
23
+ paloma_txt = view_context.render(
24
24
  :partial => "paloma/callback_hook",
25
25
  :locals => {:callbacks => session[:callbacks]})
26
26
 
27
+ before_body_end_index = response_body[0].rindex('</body>')
28
+ before_body_end_content = response_body[0][0, before_body_end_index].html_safe
29
+ after_body_end_content = response_body[0][before_body_end_index..-1].html_safe
30
+
31
+ response_body[0] = before_body_end_content + paloma_txt + after_body_end_content
32
+
27
33
  response.body = response_body[0]
28
34
  clear_callbacks
29
35
  end
data/paloma.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'paloma'
3
- s.version = '1.2.0'
3
+ s.version = '1.2.1'
4
4
  s.summary = "a sexy way to organize javascript files using Rails` asset pipeline"
5
5
  s.description = "a sexy way to organize javascript files using Rails` asset pipeline"
6
6
  s.authors = ["Karl Paragua", "Bia Esmero"]
@@ -4,6 +4,7 @@ feature 'Callbacks' do
4
4
 
5
5
  it 'should execute articles/new callback', :js => true do
6
6
  visit new_article_path
7
+
7
8
  page.has_selector?('#from-articles-new-callback').should == true
8
9
  end
9
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paloma
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-19 00:00:00.000000000 Z
13
+ date: 2013-01-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jquery-rails