paloma 4.2.1 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +5 -5
  2. data/app/views/paloma/_hook.html.erb +10 -13
  3. data/lib/paloma/action_controller_extension.rb +4 -4
  4. data/lib/paloma/controller.rb +13 -4
  5. data/lib/paloma/test_helper.rb +7 -0
  6. data/vendor/assets/javascripts/paloma/base_controller.js +8 -0
  7. data/vendor/assets/javascripts/paloma/before_callback_performer.js +69 -0
  8. data/vendor/assets/javascripts/paloma/controller_builder.js +36 -0
  9. data/vendor/assets/javascripts/paloma/controller_class_factory.js +62 -0
  10. data/vendor/assets/javascripts/paloma/engine.js +59 -53
  11. data/vendor/assets/javascripts/paloma/index.js +5 -4
  12. data/vendor/assets/javascripts/paloma/init.js +5 -10
  13. data/vendor/assets/javascripts/paloma/paloma.js +20 -21
  14. metadata +18 -88
  15. data/.gitignore +0 -5
  16. data/Changelog.md +0 -42
  17. data/DEVELOPMENT.md +0 -15
  18. data/Gemfile +0 -2
  19. data/License +0 -22
  20. data/README.md +0 -353
  21. data/TODO.md +0 -1
  22. data/paloma.gemspec +0 -22
  23. data/test_app/.gitignore +0 -15
  24. data/test_app/.rspec +0 -1
  25. data/test_app/Gemfile +0 -5
  26. data/test_app/README.rdoc +0 -261
  27. data/test_app/Rakefile +0 -11
  28. data/test_app/app/assets/images/rails.png +0 -0
  29. data/test_app/app/assets/javascripts/admin/bar.js +0 -2
  30. data/test_app/app/assets/javascripts/application.js +0 -68
  31. data/test_app/app/assets/stylesheets/admin/bar.css +0 -4
  32. data/test_app/app/assets/stylesheets/application.css +0 -13
  33. data/test_app/app/assets/stylesheets/foo.css +0 -4
  34. data/test_app/app/assets/stylesheets/main.css +0 -4
  35. data/test_app/app/assets/stylesheets/multiple_names.css +0 -4
  36. data/test_app/app/controllers/admin/foos_controller.rb +0 -29
  37. data/test_app/app/controllers/application_controller.rb +0 -3
  38. data/test_app/app/controllers/main_controller.rb +0 -111
  39. data/test_app/app/helpers/admin/bar_helper.rb +0 -2
  40. data/test_app/app/helpers/application_helper.rb +0 -2
  41. data/test_app/app/helpers/foo_helper.rb +0 -2
  42. data/test_app/app/helpers/main_helper.rb +0 -2
  43. data/test_app/app/helpers/multiple_names_helper.rb +0 -2
  44. data/test_app/app/mailers/.gitkeep +0 -0
  45. data/test_app/app/models/.gitkeep +0 -0
  46. data/test_app/app/views/layouts/application.html.erb +0 -40
  47. data/test_app/app/views/main/ajax.html.erb +0 -2
  48. data/test_app/config.ru +0 -4
  49. data/test_app/config/application.rb +0 -69
  50. data/test_app/config/boot.rb +0 -6
  51. data/test_app/config/environment.rb +0 -5
  52. data/test_app/config/environments/development.rb +0 -37
  53. data/test_app/config/environments/production.rb +0 -67
  54. data/test_app/config/environments/test.rb +0 -37
  55. data/test_app/config/initializers/backtrace_silencers.rb +0 -7
  56. data/test_app/config/initializers/inflections.rb +0 -15
  57. data/test_app/config/initializers/mime_types.rb +0 -5
  58. data/test_app/config/initializers/secret_token.rb +0 -7
  59. data/test_app/config/initializers/session_store.rb +0 -8
  60. data/test_app/config/initializers/wrap_parameters.rb +0 -14
  61. data/test_app/config/locales/en.yml +0 -5
  62. data/test_app/config/routes.rb +0 -28
  63. data/test_app/db/seeds.rb +0 -7
  64. data/test_app/doc/README_FOR_APP +0 -2
  65. data/test_app/lib/assets/.gitkeep +0 -0
  66. data/test_app/lib/tasks/.gitkeep +0 -0
  67. data/test_app/log/.gitkeep +0 -0
  68. data/test_app/public/404.html +0 -26
  69. data/test_app/public/422.html +0 -26
  70. data/test_app/public/500.html +0 -25
  71. data/test_app/public/favicon.ico +0 -0
  72. data/test_app/public/robots.txt +0 -5
  73. data/test_app/script/rails +0 -6
  74. data/test_app/spec/integration/advanced_spec.rb +0 -64
  75. data/test_app/spec/integration/basic_spec.rb +0 -195
  76. data/test_app/spec/javascripts/controller_factory_spec.js +0 -48
  77. data/test_app/spec/javascripts/router_spec.js +0 -52
  78. data/test_app/spec/javascripts/support/jasmine.yml +0 -20
  79. data/test_app/spec/spec_helper.rb +0 -37
  80. data/test_app/spec/units/controller_spec.rb +0 -109
  81. data/test_app/spec/units/utilities_spec.rb +0 -114
  82. data/test_app/test/fixtures/.gitkeep +0 -0
  83. data/test_app/test/functional/.gitkeep +0 -0
  84. data/test_app/test/integration/.gitkeep +0 -0
  85. data/test_app/test/performance/browsing_test.rb +0 -12
  86. data/test_app/test/test_helper.rb +0 -13
  87. data/test_app/test/unit/.gitkeep +0 -0
  88. data/test_app/vendor/assets/javascripts/.gitkeep +0 -0
  89. data/test_app/vendor/assets/stylesheets/.gitkeep +0 -0
  90. data/test_app/vendor/plugins/.gitkeep +0 -0
  91. data/vendor/assets/javascripts/paloma/controller.js +0 -10
  92. data/vendor/assets/javascripts/paloma/controller_factory.js +0 -55
  93. data/vendor/assets/javascripts/paloma/router.js +0 -23
@@ -18,14 +18,9 @@ else {
18
18
  };
19
19
  }
20
20
 
21
- $(document).ready(function(){
22
- // Do not continue if Paloma not found.
23
- if (window['Paloma'] === undefined) {
24
- if (window['console'] !== undefined) {
25
- console.warn("Paloma not found. Require it in your application.js.");
26
- }
27
- return true;
28
- }
29
21
 
30
- Paloma.engine.start();
31
- });
22
+ if ( !window['Paloma'] ){
23
+ if ( !window['console'] ){
24
+ console.warn("Paloma not found. Require it in your application.js.");
25
+ }
26
+ }
@@ -1,30 +1,29 @@
1
1
  (function(Paloma){
2
2
 
3
- Paloma._router = new Paloma.Router('/');
4
- Paloma._controllerFactory = new Paloma.ControllerFactory(Paloma._router);
5
-
6
- //
7
- // Declare Paloma controllers using this method.
8
- // Will return a new constructor if the no controller with the passed name
9
- // is found, else it will just return the current constructor.
10
- //
11
- Paloma.controller = function(name){
12
- return Paloma._controllerFactory.get(name) ||
13
- Paloma._controllerFactory.make(name);
14
- };
15
-
16
-
17
- Paloma.engine = new Paloma.Engine({factory: Paloma._controllerFactory});
3
+ var classFactory = new Paloma.ControllerClassFactory(),
4
+ controllerBuilder = new Paloma.ControllerBuilder(classFactory),
5
+ engine = new Paloma.Engine(controllerBuilder)
18
6
 
7
+ Paloma._controllerClassFactory = classFactory;
8
+ Paloma._controllerBuilder = controllerBuilder
9
+ Paloma.engine = engine;
19
10
 
20
- Paloma.executeHook = function(){
21
- var $hook = $('.js-paloma-hook:first script:first');
11
+ Paloma.controller = function(name, prototype){
12
+ return classFactory.make(name, prototype);
13
+ };
22
14
 
23
- if ($hook.length == 0){ return; }
15
+ Paloma._executeHook = function(){
16
+ var hook = document.querySelector('.js-paloma-hook script');
17
+ if (hook) eval(hook.innerHTML);
18
+ };
24
19
 
25
- var hook = $hook.html();
26
- eval(hook);
20
+ Paloma.start = function(){
21
+ if ( !engine.hasRequest() ) this._executeHook();
22
+ if ( engine.hasRequest() ) engine.start();
27
23
  };
28
24
 
25
+ Paloma.isExecuted = function(){
26
+ return engine.lastRequest().executed;
27
+ };
29
28
 
30
- })(window.Paloma);
29
+ })(window.Paloma);
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paloma
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Paragua
8
+ - Gonçalo Morais
9
+ - Sam Jewell
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2015-09-01 00:00:00.000000000 Z
13
+ date: 2021-05-08 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: jquery-rails
@@ -17,7 +19,7 @@ dependencies:
17
19
  - - ">="
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
- type: :runtime
22
+ type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
@@ -30,14 +32,14 @@ dependencies:
30
32
  requirements:
31
33
  - - "~>"
32
34
  - !ruby/object:Gem::Version
33
- version: 3.2.0
35
+ version: '4.0'
34
36
  type: :development
35
37
  prerelease: false
36
38
  version_requirements: !ruby/object:Gem::Requirement
37
39
  requirements:
38
40
  - - "~>"
39
41
  - !ruby/object:Gem::Version
40
- version: 3.2.0
42
+ version: '4.0'
41
43
  - !ruby/object:Gem::Dependency
42
44
  name: rake
43
45
  requirement: !ruby/object:Gem::Requirement
@@ -137,101 +139,30 @@ dependencies:
137
139
  - !ruby/object:Gem::Version
138
140
  version: 2.1.0
139
141
  description: Page-specific javascript for Rails done right
140
- email: kb.paragua@gmail.com
142
+ email:
143
+ - kb.paragua@gmail.com
144
+ - gnclmorais@gmail.com
145
+ - sam.jewell@gmail.com
141
146
  executables: []
142
147
  extensions: []
143
148
  extra_rdoc_files: []
144
149
  files:
145
- - ".gitignore"
146
- - Changelog.md
147
- - DEVELOPMENT.md
148
- - Gemfile
149
- - License
150
- - README.md
151
- - TODO.md
152
150
  - app/views/paloma/_hook.html.erb
153
151
  - lib/paloma.rb
154
152
  - lib/paloma/action_controller_extension.rb
155
153
  - lib/paloma/controller.rb
156
154
  - lib/paloma/rails/engine.rb
155
+ - lib/paloma/test_helper.rb
157
156
  - lib/paloma/utilities.rb
158
- - paloma.gemspec
159
- - test_app/.gitignore
160
- - test_app/.rspec
161
- - test_app/Gemfile
162
- - test_app/README.rdoc
163
- - test_app/Rakefile
164
- - test_app/app/assets/images/rails.png
165
- - test_app/app/assets/javascripts/admin/bar.js
166
- - test_app/app/assets/javascripts/application.js
167
- - test_app/app/assets/stylesheets/admin/bar.css
168
- - test_app/app/assets/stylesheets/application.css
169
- - test_app/app/assets/stylesheets/foo.css
170
- - test_app/app/assets/stylesheets/main.css
171
- - test_app/app/assets/stylesheets/multiple_names.css
172
- - test_app/app/controllers/admin/foos_controller.rb
173
- - test_app/app/controllers/application_controller.rb
174
- - test_app/app/controllers/main_controller.rb
175
- - test_app/app/helpers/admin/bar_helper.rb
176
- - test_app/app/helpers/application_helper.rb
177
- - test_app/app/helpers/foo_helper.rb
178
- - test_app/app/helpers/main_helper.rb
179
- - test_app/app/helpers/multiple_names_helper.rb
180
- - test_app/app/mailers/.gitkeep
181
- - test_app/app/models/.gitkeep
182
- - test_app/app/views/layouts/application.html.erb
183
- - test_app/app/views/main/ajax.html.erb
184
- - test_app/config.ru
185
- - test_app/config/application.rb
186
- - test_app/config/boot.rb
187
- - test_app/config/environment.rb
188
- - test_app/config/environments/development.rb
189
- - test_app/config/environments/production.rb
190
- - test_app/config/environments/test.rb
191
- - test_app/config/initializers/backtrace_silencers.rb
192
- - test_app/config/initializers/inflections.rb
193
- - test_app/config/initializers/mime_types.rb
194
- - test_app/config/initializers/secret_token.rb
195
- - test_app/config/initializers/session_store.rb
196
- - test_app/config/initializers/wrap_parameters.rb
197
- - test_app/config/locales/en.yml
198
- - test_app/config/routes.rb
199
- - test_app/db/seeds.rb
200
- - test_app/doc/README_FOR_APP
201
- - test_app/lib/assets/.gitkeep
202
- - test_app/lib/tasks/.gitkeep
203
- - test_app/log/.gitkeep
204
- - test_app/public/404.html
205
- - test_app/public/422.html
206
- - test_app/public/500.html
207
- - test_app/public/favicon.ico
208
- - test_app/public/robots.txt
209
- - test_app/script/rails
210
- - test_app/spec/integration/advanced_spec.rb
211
- - test_app/spec/integration/basic_spec.rb
212
- - test_app/spec/javascripts/controller_factory_spec.js
213
- - test_app/spec/javascripts/router_spec.js
214
- - test_app/spec/javascripts/support/jasmine.yml
215
- - test_app/spec/spec_helper.rb
216
- - test_app/spec/units/controller_spec.rb
217
- - test_app/spec/units/utilities_spec.rb
218
- - test_app/test/fixtures/.gitkeep
219
- - test_app/test/functional/.gitkeep
220
- - test_app/test/integration/.gitkeep
221
- - test_app/test/performance/browsing_test.rb
222
- - test_app/test/test_helper.rb
223
- - test_app/test/unit/.gitkeep
224
- - test_app/vendor/assets/javascripts/.gitkeep
225
- - test_app/vendor/assets/stylesheets/.gitkeep
226
- - test_app/vendor/plugins/.gitkeep
227
- - vendor/assets/javascripts/paloma/controller.js
228
- - vendor/assets/javascripts/paloma/controller_factory.js
157
+ - vendor/assets/javascripts/paloma/base_controller.js
158
+ - vendor/assets/javascripts/paloma/before_callback_performer.js
159
+ - vendor/assets/javascripts/paloma/controller_builder.js
160
+ - vendor/assets/javascripts/paloma/controller_class_factory.js
229
161
  - vendor/assets/javascripts/paloma/engine.js
230
162
  - vendor/assets/javascripts/paloma/index.js
231
163
  - vendor/assets/javascripts/paloma/init.js
232
164
  - vendor/assets/javascripts/paloma/paloma.js
233
- - vendor/assets/javascripts/paloma/router.js
234
- homepage: https://github.com/kbparagua/paloma
165
+ homepage: https://github.com/gnclmorais/paloma
235
166
  licenses:
236
167
  - MIT
237
168
  metadata: {}
@@ -250,8 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
181
  - !ruby/object:Gem::Version
251
182
  version: '0'
252
183
  requirements: []
253
- rubyforge_project:
254
- rubygems_version: 2.2.2
184
+ rubygems_version: 3.1.4
255
185
  signing_key:
256
186
  specification_version: 4
257
187
  summary: Provides an easy way to execute page-specific javascript for Rails.
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- Gemfile.lock
2
- *.gem
3
- /tmp/*
4
- /test_app/tmp/*
5
- /test_app/spec/tmp/*
data/Changelog.md DELETED
@@ -1,42 +0,0 @@
1
- ## 4.2.1
2
- * https://github.com/kbparagua/paloma/issues/79 - Rendering "true" string fixed.
3
- * Catch situations where `js` function is called more than once.
4
-
5
- ## 4.2.0
6
- * https://github.com/kbparagua/paloma/pull/75 - Explicitly insert hook in view.
7
-
8
- ## 4.1.2
9
- * https://github.com/kbparagua/paloma/issues/73 - Fix `js false` issue.
10
-
11
- ## 4.1.1
12
- * https://github.com/kbparagua/paloma/pull/57 - Fix Turbolinks Issues.
13
- * https://github.com/kbparagua/paloma/pull/55 - Fix issues when Paloma hook is not found.
14
-
15
- ## 4.1.0
16
- * Support for Turbolinks.
17
- * `Paloma.executeHook()` to manually run the hook from the DOM.
18
- * Paloma hook will be appended using all `render` calls, except for calls that has the following keys `[:json, :js, :xml, :file]`.
19
- * Restore `Paloma.engine.start()` to start processing queued request.
20
-
21
-
22
- ## 4.0.0
23
- * https://github.com/kbparagua/paloma/issues/26 - Paloma requests are not saved on `session`.
24
- * https://github.com/kbparagua/paloma/issues/26 - Chaining with redirect is removed.
25
- * Routing from javascript is removed.
26
- * Routing from Rails controller is added.
27
- * Ability to have a controller-wide setting.
28
- * https://github.com/kbparagua/paloma/issues/29 - Disable `console.log` and `console.warn` for non-development environments.
29
-
30
-
31
- ## 3.0.2
32
- * Bug Fix: Converting Rails controller name to singular form.
33
-
34
-
35
- ## 3.0.1
36
- * Bug Fix: Can't handle Rails controller with Multi-word name.
37
- * Bug Fix: Paloma Engine is halting when a warning is encountered.
38
- * Don't create Paloma request if rendering js, json, xml, or file.
39
-
40
-
41
- ## 3.0.0
42
- * Rewrite Initial Release
data/DEVELOPMENT.md DELETED
@@ -1,15 +0,0 @@
1
- # Development
2
-
3
- ## Testing
4
-
5
- 1. Go to `test_app`
6
- 1. Comment out `turbolinks.js` on `applciation.js`
7
- 1. Run `bundle exec rails s`.
8
- 1. Open your browser and visit [http://localhost:3000/specs](http://localhost:3000/specs).
9
- 1. Run `bundle exec rake spec:units`.
10
- 1. Run `bundle exec rake spec:integration`.
11
-
12
- ## TODO
13
-
14
- 1. Improve tests.
15
- 1. Testing for turbolinks.
data/Gemfile DELETED
@@ -1,2 +0,0 @@
1
- source "http://rubygems.org"
2
- gemspec
data/License DELETED
@@ -1,22 +0,0 @@
1
- (The MIT License)
2
-
3
- Copyright (c) 2012-2013 Karl Paragua, Bia Esmero
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- 'Software'), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,353 +0,0 @@
1
- **Important**
2
- - `master` branch contains the bleeding edge development code.
3
- - check `branches` or `tags` for the latest stable release or specific versions.
4
-
5
- # Paloma
6
-
7
- Page-specific javascript for Rails done right.
8
-
9
- ## Advantages
10
- * Choose what specific javascript code to run per page.
11
- * Easily make ruby variables available on your javascript files.
12
- * Can be written using vanilla javascript, coffeescript, and anything that compiles to js.
13
- * Easy to understand (*because it is patterned after Rails' controller module*).
14
-
15
- ## Quick Example
16
-
17
- Paloma controller.
18
-
19
- ```javascript
20
- var UsersController = Paloma.controller('Users');
21
-
22
- // Executes when Rails User#new is executed.
23
- UsersController.prototype.new = function(){
24
- alert('Hello Sexy User!' );
25
- };
26
- ```
27
-
28
- The Rails controller `app/controllers/users_controller.rb`:
29
-
30
- ```ruby
31
- def UsersController < ApplicationController
32
- def new
33
- # a Paloma request will automatically be created.
34
- @user = User.new
35
- end
36
- end
37
- ```
38
-
39
- That's it! Simply Sexy!
40
-
41
- ## Minimum Requirements
42
- * jQuery 1.7 or higher
43
- * Rails 3.1 or higher
44
-
45
-
46
- ## Install
47
-
48
- 1. Without bundler: `sudo gem install paloma`.
49
- 1. With bundler, add this to your Gemfile: `gem 'paloma'`
50
- 1. Require `paloma` in your `application.js`: `//= require paloma`
51
- 1. In your layouts insert Paloma hook.
52
-
53
- `application.html.erb`
54
- ```html
55
- <html>
56
- <head>
57
- </head>
58
-
59
- <body>
60
- <%= yield %>
61
- <%= insert_paloma_hook %>
62
- </body>
63
- </html>
64
- ```
65
-
66
- ## Controllers
67
-
68
- Controllers are just classes that handle requests made by Rails Controllers. Each Rails Controller's action will be mapped to a specific Paloma Controller's action.
69
-
70
-
71
- ### Creating a Controller
72
-
73
- A Controller constructor is created or accessed (if it already exists), using `Paloma.controller()` method.
74
-
75
- ```javascript
76
- var ArticlesController = Paloma.controller('Articles');
77
- ```
78
-
79
- It will return the constructor function of your controller.
80
-
81
- Note: Using `Paloma.controller` method, you can access the same controller constructor across different files.
82
-
83
-
84
- ### Handling Actions
85
-
86
- Every time a request to Paloma is made (A Rails Controller action is executed), an instance of a Paloma controller is created and the method responsible for the request will be invoked.
87
-
88
- ```javascript
89
- var ArticlesController = Paloma.controller('Articles');
90
-
91
- ArticlesController.prototype.new = function(){
92
- // Handle new articles
93
- };
94
-
95
- ArticlesController.prototype.edit = function(){
96
- // Handle edit articles
97
- };
98
- ```
99
-
100
-
101
- ## Advanced Usage
102
-
103
- You can manipulate what controller/action should Paloma execute by calling `js` method **before** rendering.
104
-
105
- 1. Changing controller
106
-
107
- ```ruby
108
- class UsersController < ApplicationController
109
- def new
110
- @user = User.new
111
- js 'Accounts' # will use Accounts controller instead of Users controller
112
- end
113
- end
114
- ```
115
-
116
- 2. Changing action
117
-
118
- You can use the symbol syntax:
119
- ```ruby
120
- def new
121
- @user = User.new
122
- js :register # will execute register method instead of new
123
- end
124
- ```
125
-
126
- Or the string syntax:
127
- ```ruby
128
- def new
129
- @user = User.new
130
- js '#register'
131
- end
132
- ```
133
-
134
- 3. Changing controller and action.
135
-
136
- ```ruby
137
- def new
138
- @user = User.new
139
- js 'Accounts#register' # will execute Accounts#register instead of Users#new
140
- end
141
- ```
142
-
143
- 4. Changing controller with namespace.
144
-
145
- Paloma supports namespaces using '/' as delimiter.
146
-
147
- ```ruby
148
- def new
149
- @user = User.new
150
- js `Admin/Accounts` # will use Admin/Accounts controller instead of Users controller
151
- end
152
- ```
153
-
154
- ```ruby
155
- def new
156
- @user = User.new
157
- js 'Admin/Accounts#register' # will execute Admin/Accounts#register instead of Users#new
158
- end
159
- ```
160
-
161
-
162
- ## Passing Parameters
163
-
164
- You can access the parameters on your Paloma Controller using `this.params` object.
165
-
166
-
167
- 1. Parameters only.
168
-
169
- `users_controller.rb`
170
- ```ruby
171
- def destroy
172
- user = User.find params[:id]
173
- user.destroy
174
-
175
- js :id => user.id
176
- end
177
- ```
178
-
179
- Paloma controller.
180
-
181
- ```javascript
182
- var UsersController = Paloma.controller('Users');
183
-
184
- UsersController.prototype.destroy = function(){
185
- alert('User ' + this.params['id'] + ' is deleted.');
186
- };
187
- ```
188
-
189
- 2. Path with parameters.
190
-
191
- ```ruby
192
- def destroy
193
- user = User.find params[:id]
194
- user.destroy
195
-
196
- js 'Accounts#delete', :id => user.id
197
- end
198
- ```
199
-
200
-
201
- ## Preventing Paloma Execution
202
-
203
- If you want to Paloma not to execute in a specific Rails Controller action you need to pass `false` as the Paloma parameter.
204
-
205
- ```ruby
206
- def edit
207
- @user = User.find params[:id]
208
- js false
209
- end
210
- ```
211
-
212
-
213
- ## Controller-wide setup
214
-
215
- You can call `js` outside Rails controller actions for global or controller-wide settings.
216
-
217
-
218
- **Example:**
219
-
220
- ```ruby
221
- class UsersController < ApplicationController
222
- js 'Accounts' # use Accounts controller instead of Users for all actions.
223
-
224
-
225
- def new
226
- @user = User.new
227
- end
228
-
229
- def show
230
- @user = User.find params[:id]
231
- end
232
- end
233
- ```
234
-
235
- Like `before_filter` you can also pass `only` and `except` options.
236
-
237
-
238
- ```ruby
239
- class UsersController < ApplicationController
240
-
241
- js 'Admin/Accounts', :except => :destroy # Use Admin/Accounts except for destroy method
242
-
243
- end
244
- ```
245
-
246
-
247
- **IMPORTANT NOTE:**
248
- If you are going to pass parameters for Controller-wide settings, put them inside a `:params` hash.
249
-
250
- ```ruby
251
- class UsersController < ApplicationController
252
- js 'Accounts', :params => {:x => 1, :y => 2, :z => 3}, :only => :show
253
- end
254
- ```
255
-
256
- ### Overriding Controller-wide setup
257
-
258
- If you want to override the controller-wide setup, just call `js` again inside a controller action. From there you can override the controller/action or pass additional parameters.
259
-
260
- ```ruby
261
- class UsersController < ApplicationController
262
-
263
- js 'Accounts', :params => {:x => 1}
264
-
265
-
266
- def new
267
- @user = User.new
268
- js :register, :y => 2 # will execute Accounts#register with params {:x => 1, :y => 2}
269
- end
270
- end
271
- ```
272
-
273
- ## Hook
274
-
275
- `insert_paloma_hook` is a helper method that you can use in your views to insert Paloma's HTML hook.
276
- Inside this HTML hook is where the magic happens. This is the reason why Paloma can magically know what Javascript controller/action to execute. To further understand how Paloma works, you can inspect the HTML hook, by checking the generated HTML (*inspect element*) and locate the `div` element that has the class `js-paloma-hook`.
277
-
278
- Ideally, you just need to call `insert_paloma_hook` in your layouts, since the layout will always be included in every rendered view. But if you are rendering a view without a layout, make sure to call `insert_paloma_hook` in that view.
279
-
280
-
281
- ## AJAX
282
-
283
- 1. Make sure that the AJAX response contains the html hook. (use `insert_paloma_hook`)
284
- 2. Execute the hook and start Paloma's engine on complete/success.
285
-
286
- ```js
287
- $.get('http://example.com', function(response){
288
- $('#result').html(response);
289
-
290
- // Execute Paloma hook and start the engine.
291
- Paloma.executeHook();
292
- Palama.engine.start();
293
- });
294
- ```
295
-
296
- ## Turbolinks Support
297
-
298
- As of version `4.1.0`, Paloma is compatible with Turbolinks without additional setup.
299
-
300
- ### Execute Paloma when user hits `Back` or `Forward` button.
301
-
302
- Paloma executes page-specific javascript by adding a `<script>` tag to the response body. Turbolinks, by default, executes any inline javascript in the response body when you visit a page, so the `<script>` tag appended by Paloma will automatically be executed. However, when Turbolinks restores a page from cache (*this happens when a user hits `Back` or `Forward` button in his browser*) any **inline javascript will not be executed** anymore. This is the intentional behavior of Turbolinks, and it is not a bug. If you want to execute Paloma again when Turbolinks restores a page, do something like this:
303
-
304
- ```js
305
- $(document).on('page:restore', function(){
306
- // Manually evaluates the appended script tag.
307
- Paloma.executeHook();
308
- });
309
- ```
310
-
311
- ### Turbolinks without `jquery.turbolinks` gem
312
-
313
- You need to manually run Paloma every page load if you are not using `jquery.turbolinks` gem.
314
-
315
- In your `application.js`
316
-
317
- ```js
318
- $(document).on('page:load', function(){
319
- Paloma.executeHook();
320
- Paloma.engine.start();
321
- });
322
- ```
323
-
324
-
325
- ## Gotchas
326
-
327
- * Make sure that the rendered view has the paloma hook (*use `insert_paloma_hook`*) for Paloma to execute.
328
-
329
- * It will cause conflicts if you have a controller and a module that has the same name.
330
-
331
- Example:
332
- ```js
333
- var AdminController = Paloma.controller('Admin');
334
-
335
- // This will override the AdminController and replace it
336
- // with a module named 'Admin'.
337
- var UsersController = Paloma.controller('Admin/Users');
338
- ```
339
-
340
- ## Where to put code?
341
-
342
- Again, Paloma is now flexible and doesn't force developers to follow specific directory structure.
343
- You have the freedom to create controllers anywhere in your application.
344
-
345
- Personally, I prefer having a javascript file for each controller.
346
-
347
-
348
- ## Contribute
349
-
350
- 1. Fork.
351
- 2. Do awesome things.
352
- 3. Submit Pull-Request to `master` branch.
353
- 4. Add short summary of changes on your PR.