unpoly-rails 0.33.0 → 0.34.0
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.
Potentially problematic release.
This version of unpoly-rails might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README_RAILS.md +3 -3
- data/dist/unpoly.js +382 -97
- data/dist/unpoly.min.js +3 -3
- data/lib/assets/javascripts/unpoly.coffee +1 -0
- data/lib/assets/javascripts/unpoly/browser.coffee +37 -18
- data/lib/assets/javascripts/unpoly/bus.coffee +5 -6
- data/lib/assets/javascripts/unpoly/dom.coffee +11 -5
- data/lib/assets/javascripts/unpoly/form.coffee +5 -6
- data/lib/assets/javascripts/unpoly/history.coffee +18 -10
- data/lib/assets/javascripts/unpoly/layout.coffee +40 -9
- data/lib/assets/javascripts/unpoly/protocol.coffee +235 -0
- data/lib/assets/javascripts/unpoly/proxy.coffee +3 -6
- data/lib/assets/javascripts/unpoly/syntax.coffee +2 -2
- data/lib/assets/javascripts/unpoly/util.coffee +0 -24
- data/lib/assets/stylesheets/unpoly/{flow.sass → dom.sass} +0 -0
- data/lib/unpoly/rails/request_method_cookie.rb +4 -4
- data/lib/unpoly/rails/version.rb +1 -1
- data/package.json +1 -1
- data/spec_app/Gemfile.lock +1 -1
- data/spec_app/spec/controllers/binding_test_controller_spec.rb +46 -0
- data/spec_app/spec/javascripts/up/layout_spec.js.coffee +30 -0
- metadata +4 -3
@@ -79,8 +79,6 @@ up.proxy = (($) ->
|
|
79
79
|
An array of uppercase HTTP method names. AJAX requests with one of these methods
|
80
80
|
will be converted into a `POST` request and carry their original method as a `_method`
|
81
81
|
parameter. This is to [prevent unexpected redirect behavior](https://makandracards.com/makandra/38347).
|
82
|
-
@param {String} [config.wrapMethodParam]
|
83
|
-
The name of the POST parameter when wrapping HTTP methods in a `POST` request.
|
84
82
|
@param {Array<String>} [config.safeMethods]
|
85
83
|
An array of uppercase HTTP method names that are considered idempotent.
|
86
84
|
The proxy cache will only cache idempotent requests and will clear the entire
|
@@ -94,7 +92,6 @@ up.proxy = (($) ->
|
|
94
92
|
cacheExpiry: 1000 * 60 * 5
|
95
93
|
maxRequests: 4
|
96
94
|
wrapMethods: ['PATCH', 'PUT', 'DELETE']
|
97
|
-
wrapMethodParam: '_method'
|
98
95
|
safeMethods: ['GET', 'OPTIONS', 'HEAD']
|
99
96
|
|
100
97
|
cacheKey = (request) ->
|
@@ -206,7 +203,7 @@ up.proxy = (($) ->
|
|
206
203
|
@param {String} [request.timeout]
|
207
204
|
A timeout in milliseconds for the request.
|
208
205
|
|
209
|
-
If [`up.proxy.config.maxRequests`](/up.proxy.config#maxRequests) is set, the timeout
|
206
|
+
If [`up.proxy.config.maxRequests`](/up.proxy.config#config.maxRequests) is set, the timeout
|
210
207
|
will not include the time spent waiting in the queue.
|
211
208
|
@return
|
212
209
|
A promise for the response that is API-compatible with the
|
@@ -410,10 +407,10 @@ up.proxy = (($) ->
|
|
410
407
|
request = u.copy(request)
|
411
408
|
|
412
409
|
request.headers ||= {}
|
413
|
-
request.headers[
|
410
|
+
request.headers[up.protocol.config.targetHeader] = request.target
|
414
411
|
|
415
412
|
if u.contains(config.wrapMethods, request.method)
|
416
|
-
request.data = u.appendRequestData(request.data, config.
|
413
|
+
request.data = u.appendRequestData(request.data, up.protocol.config.methodParam, request.method)
|
417
414
|
request.method = 'POST'
|
418
415
|
|
419
416
|
if u.isFormData(request.data)
|
@@ -375,8 +375,8 @@ up.syntax = (($) ->
|
|
375
375
|
###
|
376
376
|
|
377
377
|
###*
|
378
|
-
If an element
|
379
|
-
|
378
|
+
If an element with an `up-data` attribute enters the DOM,
|
379
|
+
Unpoly will parse the JSON and pass the resulting object to any matching
|
380
380
|
[`up.compiler()`](/up.compiler) handlers.
|
381
381
|
|
382
382
|
For instance, a container for a [Google Map](https://developers.google.com/maps/documentation/javascript/tutorial)
|
@@ -1172,27 +1172,6 @@ up.util = (($) ->
|
|
1172
1172
|
# castsToFalse = (object) ->
|
1173
1173
|
# String(object) == "false"
|
1174
1174
|
|
1175
|
-
###*
|
1176
|
-
@function up.util.locationFromXhr
|
1177
|
-
@internal
|
1178
|
-
###
|
1179
|
-
locationFromXhr = (xhr) ->
|
1180
|
-
xhr.getResponseHeader('X-Up-Location')
|
1181
|
-
|
1182
|
-
###*
|
1183
|
-
@function up.util.titleFromXhr
|
1184
|
-
@internal
|
1185
|
-
###
|
1186
|
-
titleFromXhr = (xhr) ->
|
1187
|
-
xhr.getResponseHeader('X-Up-Title')
|
1188
|
-
|
1189
|
-
###*
|
1190
|
-
@function up.util.methodFromXhr
|
1191
|
-
@internal
|
1192
|
-
###
|
1193
|
-
methodFromXhr = (xhr) ->
|
1194
|
-
xhr.getResponseHeader('X-Up-Method')
|
1195
|
-
|
1196
1175
|
###*
|
1197
1176
|
Returns a copy of the given object that only contains
|
1198
1177
|
the given properties.
|
@@ -2078,9 +2057,6 @@ up.util = (($) ->
|
|
2078
2057
|
contains: contains
|
2079
2058
|
toArray: toArray
|
2080
2059
|
castedAttr: castedAttr
|
2081
|
-
locationFromXhr: locationFromXhr
|
2082
|
-
titleFromXhr: titleFromXhr
|
2083
|
-
methodFromXhr: methodFromXhr
|
2084
2060
|
clientSize: clientSize
|
2085
2061
|
only: only
|
2086
2062
|
except: except
|
File without changes
|
@@ -13,7 +13,7 @@ module Unpoly
|
|
13
13
|
module Rails
|
14
14
|
module RequestMethod
|
15
15
|
|
16
|
-
COOKIE_NAME = '
|
16
|
+
COOKIE_NAME = '_up_method'
|
17
17
|
|
18
18
|
def self.included(base)
|
19
19
|
base.before_filter :set_up_request_method_cookie
|
@@ -22,10 +22,10 @@ module Unpoly
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def set_up_request_method_cookie
|
25
|
-
if request.get?
|
26
|
-
cookies.delete(COOKIE_NAME)
|
27
|
-
else
|
25
|
+
if !request.get? && !up?
|
28
26
|
cookies[COOKIE_NAME] = request.request_method
|
27
|
+
else
|
28
|
+
cookies.delete(COOKIE_NAME)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
data/lib/unpoly/rails/version.rb
CHANGED
data/package.json
CHANGED
data/spec_app/Gemfile.lock
CHANGED
@@ -144,4 +144,50 @@ describe BindingTestController do
|
|
144
144
|
|
145
145
|
end
|
146
146
|
|
147
|
+
describe 'request method cookie' do
|
148
|
+
|
149
|
+
describe 'if the request is both non-GET and not a fragment update' do
|
150
|
+
|
151
|
+
it 'echoes the request method in an _up_method cookie ' do
|
152
|
+
put :text
|
153
|
+
expect(response.cookies['_up_method']).to eq('PUT')
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
describe 'if the request is not a fragment update, but GET' do
|
159
|
+
|
160
|
+
it 'does not set the cookie' do
|
161
|
+
get :text
|
162
|
+
expect(response.cookies['_up_method']).to be_nil
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'deletes an existing cookie' do
|
166
|
+
request.cookies['_up_method'] = 'PUT'
|
167
|
+
get :text
|
168
|
+
expect(response.cookies['_up_method']).to be_nil
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
describe 'if the request is non-GET but a fragment update' do
|
174
|
+
|
175
|
+
it 'does not set the cookie' do
|
176
|
+
request.headers['X-Up-Target'] = '.target'
|
177
|
+
put :text
|
178
|
+
expect(response.cookies['_up_method']).to be_nil
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'deletes an existing cookie' do
|
182
|
+
request.cookies['_up_method'] = 'PUT'
|
183
|
+
request.headers['X-Up-Target'] = '.target'
|
184
|
+
put :text
|
185
|
+
expect(response.cookies['_up_method']).to be_nil
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
end
|
192
|
+
|
147
193
|
end
|
@@ -318,6 +318,36 @@ describe 'up.layout', ->
|
|
318
318
|
# Viewing 100 to 199
|
319
319
|
expect($viewport.scrollTop()).toBe(100)
|
320
320
|
|
321
|
+
describe 'revealHash', ->
|
322
|
+
|
323
|
+
it 'reveals an element with an ID matching the hash in the location', ->
|
324
|
+
revealSpy = up.layout.knife.mock('reveal')
|
325
|
+
$match = affix('div#hash')
|
326
|
+
location.hash = '#hash'
|
327
|
+
up.layout.revealHash()
|
328
|
+
expect(revealSpy).toHaveBeenCalledWith($match)
|
329
|
+
|
330
|
+
it 'reveals a named anchor matching the hash in the location', ->
|
331
|
+
revealSpy = up.layout.knife.mock('reveal')
|
332
|
+
$match = affix('a[name="hash"]')
|
333
|
+
location.hash = '#hash'
|
334
|
+
up.layout.revealHash()
|
335
|
+
expect(revealSpy).toHaveBeenCalledWith($match)
|
336
|
+
|
337
|
+
it 'does nothing and returns a rejected promise if no element or anchor matches the hash in the location', ->
|
338
|
+
revealSpy = up.layout.knife.mock('reveal')
|
339
|
+
location.hash = '#hash'
|
340
|
+
promise = up.layout.revealHash()
|
341
|
+
expect(revealSpy).not.toHaveBeenCalled()
|
342
|
+
expect(promise.state()).toEqual('rejected')
|
343
|
+
|
344
|
+
it 'does nothing and returns a resolved promise if the location has no hash', ->
|
345
|
+
revealSpy = up.layout.knife.mock('reveal')
|
346
|
+
location.hash = ''
|
347
|
+
promise = up.layout.revealHash()
|
348
|
+
expect(revealSpy).not.toHaveBeenCalled()
|
349
|
+
expect(promise.state()).toEqual('resolved')
|
350
|
+
|
321
351
|
describe 'up.layout.viewportsWithin', ->
|
322
352
|
|
323
353
|
it 'should have tests'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unpoly-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.34.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/assets/javascripts/unpoly/motion.coffee
|
110
110
|
- lib/assets/javascripts/unpoly/namespace.coffee.erb
|
111
111
|
- lib/assets/javascripts/unpoly/popup.coffee
|
112
|
+
- lib/assets/javascripts/unpoly/protocol.coffee
|
112
113
|
- lib/assets/javascripts/unpoly/proxy.coffee
|
113
114
|
- lib/assets/javascripts/unpoly/rails.coffee
|
114
115
|
- lib/assets/javascripts/unpoly/syntax.coffee
|
@@ -119,7 +120,7 @@ files:
|
|
119
120
|
- lib/assets/stylesheets/unpoly-bootstrap3/modal-ext.sass
|
120
121
|
- lib/assets/stylesheets/unpoly.sass
|
121
122
|
- lib/assets/stylesheets/unpoly/close.sass
|
122
|
-
- lib/assets/stylesheets/unpoly/
|
123
|
+
- lib/assets/stylesheets/unpoly/dom.sass
|
123
124
|
- lib/assets/stylesheets/unpoly/link.sass
|
124
125
|
- lib/assets/stylesheets/unpoly/modal.sass
|
125
126
|
- lib/assets/stylesheets/unpoly/popup.sass
|