paloma 4.2.0 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b10b31f63c970076c4afe47277ce5f90a3c6fccd
4
- data.tar.gz: 0f63a749171a49ed7b88c4bedc9f66b559a5bdf7
3
+ metadata.gz: c6d90c6346ffaca96320b8924a984d7b4a09d26b
4
+ data.tar.gz: d77644a771b84cfbb6e55ded22be99a7a930ac90
5
5
  SHA512:
6
- metadata.gz: df5a36190acab372138dab88ed9e41a864c8f05e460a5be02e905f06f675d89b4b303ba3ca28ee9ddf4738f8937ad8286f855312cb2338e8a4f287db17eef786
7
- data.tar.gz: cfc151c6dbc4afc174dd6e5b4288476094bbb762a311c24744a008868c447a51d6e11a653058a5105862b3a7d76522ade0eb7e05399092955edd473da27e5a2c
6
+ metadata.gz: ebc6f8eafd2f25d3983ee8c253be793da6e2736deebe61fa887a28e9d71250b677f00d74d571f51bed4ddd9af72ebe1aad9c4d4fa97071c0a6572569ff7d5a22
7
+ data.tar.gz: 67753deb514e0615089d462cf86130ea85c29b1b23074b3940f7a165d7b3ba38395dc048702c1ebbad7b1cb72305cd800efdbb9579ee0144cd34bb952d202056
@@ -1,3 +1,7 @@
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
+
1
5
  ## 4.2.0
2
6
  * https://github.com/kbparagua/paloma/pull/75 - Explicitly insert hook in view.
3
7
 
@@ -55,6 +55,20 @@ module Paloma
55
55
  # Can call a different Controller or execute a different action, and
56
56
  # pass parameters.
57
57
  #
58
+ # NOTE:
59
+ # Calling this more than once in a single action will not clear
60
+ # the previous config from the previous call.
61
+ #
62
+ # Example:
63
+ # def new
64
+ # js 'MyController#new'
65
+ # js :edit
66
+ # js :x => 1, :y => 2
67
+ #
68
+ # # Paloma will execute JS for
69
+ # # MyController#edit and will pass the parameters :x => 1, :y => 2
70
+ # end
71
+ #
58
72
  # Usage:
59
73
  #
60
74
  # js 'Controller', {params}
@@ -64,6 +78,8 @@ module Paloma
64
78
  # js '#action', {params}
65
79
  # js :action, {params}
66
80
  # js :param_1 => 1, :param_2 => 2
81
+ # js true
82
+ # js false
67
83
  #
68
84
  #
69
85
  def js path_or_options, params = {}
@@ -80,8 +96,8 @@ module Paloma
80
96
  #
81
97
  if path_or_options.is_a? String
82
98
  route = ::Paloma::Utilities.interpret_route path_or_options
83
- self.paloma.resource = route[:resource] unless route[:resource].blank?
84
- self.paloma.action = route[:action] unless route[:action].blank?
99
+ self.paloma.resource = route[:resource] if route[:resource].present?
100
+ self.paloma.action = route[:action] if route[:action].present?
85
101
 
86
102
  # :action
87
103
  elsif path_or_options.is_a? Symbol
@@ -91,7 +107,12 @@ module Paloma
91
107
  elsif path_or_options.is_a? Hash
92
108
  self.paloma.params.merge! path_or_options || {}
93
109
 
110
+ elsif path_or_options != true
111
+ raise "Paloma: Invalid argument (#{path_or_options}) for js method"
94
112
  end
113
+
114
+ self.paloma.resource ||= self.default_resource
115
+ self.paloma.action ||= self.default_action
95
116
  end
96
117
 
97
118
 
@@ -101,8 +122,8 @@ module Paloma
101
122
  # Keeps track of what Rails controller/action is executed.
102
123
  #
103
124
  def track_paloma_request
104
- self.paloma.resource ||= ::Paloma::Utilities.get_resource controller_path
105
- self.paloma.action ||= self.action_name
125
+ self.paloma.resource ||= self.default_resource
126
+ self.paloma.action ||= self.default_action
106
127
  end
107
128
 
108
129
 
@@ -113,7 +134,7 @@ module Paloma
113
134
  # will execute the tracked Paloma requests.
114
135
  #
115
136
  def insert_paloma_hook
116
- return true if self.paloma.has_no_request?
137
+ return nil if self.paloma.has_no_request?
117
138
 
118
139
  hook = view_context.render(
119
140
  :partial => 'paloma/hook',
@@ -134,6 +155,16 @@ module Paloma
134
155
  @paloma ||= ::Paloma::Controller.new
135
156
  end
136
157
 
158
+
159
+ def default_resource
160
+ ::Paloma::Utilities.get_resource self.controller_path
161
+ end
162
+
163
+
164
+ def default_action
165
+ self.action_name
166
+ end
167
+
137
168
  end
138
169
 
139
170
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'paloma'
3
- s.version = '4.2.0'
3
+ s.version = '4.2.1'
4
4
  s.summary = "Provides an easy way to execute page-specific javascript for Rails."
5
5
  s.description = "Page-specific javascript for Rails done right"
6
6
  s.authors = ['Karl Paragua']
@@ -36,12 +36,13 @@ Main.prototype.index = function(){};
36
36
  Main.prototype.otherAction = function(){};
37
37
  Main.prototype.prevent = function(){};
38
38
  Main.prototype.basic_params = function(){};
39
+ Main.prototype.multiple_calls_1 = function(){};
39
40
 
40
41
 
41
42
  var OtherMain = Paloma.controller('OtherMain');
42
43
  OtherMain.prototype.show = function(){};
43
44
  OtherMain.prototype.otherAction = function(){};
44
-
45
+ OtherMain.prototype.multiple_calls_2 = function(){};
45
46
 
46
47
 
47
48
  var Foos = Paloma.controller('Admin/Foos');
@@ -27,6 +27,43 @@ class MainController < ApplicationController
27
27
  end
28
28
 
29
29
 
30
+ def multiple_calls_1
31
+ js false
32
+ js :x => 70
33
+ render :inline => 'Main#multiple_calls', :layout => 'application'
34
+ end
35
+
36
+
37
+ def multiple_calls_2
38
+ js false
39
+ js 'OtherMain'
40
+ render :inline => 'Main#multiple_calls_2', :layout => 'application'
41
+ end
42
+
43
+
44
+ def multiple_calls_3
45
+ js 'OtherMain'
46
+ js :show
47
+ render :inline => 'Main#multiple_calls_3', :layout => 'application'
48
+ end
49
+
50
+
51
+ def multiple_calls_4
52
+ js 'OtherMain#show'
53
+ js false
54
+ render :inline => 'Main#multiple_calls_4', :layout => 'application'
55
+ end
56
+
57
+
58
+ def multiple_calls_5
59
+ js false
60
+ js true
61
+ render :inline => 'Main#multiple_calls_5', :layout => 'application'
62
+ end
63
+
64
+
65
+
66
+
30
67
  # Stop paloma from execution
31
68
  def prevent
32
69
  js false
@@ -17,6 +17,11 @@
17
17
  <li><%= link_to 'Main#edit', edit_main_path(1) %></li>
18
18
  <li><%= link_to 'Main#prevent', prevent_main_index_path %></li>
19
19
  <li><%= link_to 'Main#basic_params', basic_params_main_index_path %></li>
20
+ <li><%= link_to 'Main#multiple_calls_1', multiple_calls_1_main_index_path %></li>
21
+ <li><%= link_to 'Main#multiple_calls_2', multiple_calls_2_main_index_path %></li>
22
+ <li><%= link_to 'Main#multiple_calls_3', multiple_calls_3_main_index_path %></li>
23
+ <li><%= link_to 'Main#multiple_calls_4', multiple_calls_4_main_index_path %></li>
24
+ <li><%= link_to 'Main#multiple_calls_5', multiple_calls_5_main_index_path %></li>
20
25
  <li><%= link_to 'Main#xml_response', xml_response_main_index_path %></li>
21
26
  <li><%= link_to 'Main#file_response', file_response_main_index_path %></li>
22
27
  <li><%= link_to 'Main#ajax', ajax_main_index_path, :id => 'js-ajax-link' %></li>
@@ -13,6 +13,11 @@ TestApp::Application.routes.draw do
13
13
  get :xml_response
14
14
  get :file_response
15
15
  get :ajax
16
+ get :multiple_calls_1
17
+ get :multiple_calls_2
18
+ get :multiple_calls_3
19
+ get :multiple_calls_4
20
+ get :multiple_calls_5
16
21
  end
17
22
  end
18
23
 
@@ -79,6 +79,71 @@ feature 'executing Paloma controller', :js => true do
79
79
 
80
80
 
81
81
 
82
+ #
83
+ #
84
+ # Multiple Calls
85
+ #
86
+ #
87
+
88
+ context 'false at first then pass a parameter' do
89
+ it 'executes default controller#action plus the parameter' do
90
+ visit multiple_calls_1_main_index_path
91
+
92
+ expect(
93
+ request['controller'] == 'Main' &&
94
+ request['action'] == 'multiple_calls_1' &&
95
+ request['params'] == {'x' => 70}
96
+ ).to be_truthy
97
+ end
98
+ end
99
+
100
+
101
+ context 'false at first then pass a controller string' do
102
+ it 'executes passed controller and default action' do
103
+ visit multiple_calls_2_main_index_path
104
+
105
+ expect(
106
+ request['controller'] == 'OtherMain' &&
107
+ request['action'] == 'multiple_calls_2'
108
+ ).to be_truthy
109
+ end
110
+ end
111
+
112
+
113
+ context 'controller at first then action' do
114
+ it 'executes the controller and action' do
115
+ visit multiple_calls_3_main_index_path
116
+
117
+ expect(
118
+ request['controller'] == 'OtherMain' &&
119
+ request['action'] == 'show'
120
+ ).to be_truthy
121
+ end
122
+ end
123
+
124
+
125
+ context 'controller#action at first then false' do
126
+ it 'does not execute any js' do
127
+ visit multiple_calls_4_main_index_path
128
+ expect(request).to be_nil
129
+ end
130
+ end
131
+
132
+
133
+ context 'false at first then true' do
134
+ it 'executes default controller#action' do
135
+ visit multiple_calls_5_main_index_path
136
+
137
+ expect(
138
+ request['controller'] == 'Main' &&
139
+ request['action'] == 'multiple_calls_5'
140
+ ).to be_truthy
141
+ end
142
+ end
143
+
144
+
145
+
146
+
82
147
  #
83
148
  #
84
149
  # Prevent Paloma
@@ -106,4 +106,4 @@ describe Paloma::Controller do
106
106
  end
107
107
  end
108
108
 
109
- end
109
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paloma
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Paragua
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-01 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jquery-rails