vue-rails 2.0.1 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -9
- data/Gemfile +1 -3
- data/{LICENSE → LICENSE.md} +1 -1
- data/Rakefile +0 -1
- data/Readme.md +56 -0
- data/lib/vue-rails.rb +2 -5
- data/lib/vue-rails/engine.rb +6 -0
- data/lib/vue-rails/version.rb +1 -1
- data/vendor/assets/javascripts/vue-resource.js +1534 -0
- data/vendor/assets/javascripts/vue-router.js +1196 -749
- data/vendor/assets/javascripts/vue.js +6031 -4258
- data/vendor/assets/javascripts/vuex.js +811 -0
- data/vue-rails.gemspec +5 -6
- metadata +17 -13
- data/README.md +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fba1bfe175bd7dd8517658dc98514224b33db1c
|
4
|
+
data.tar.gz: 6e641e28011c3b18b2912d359828552092bd5a22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fc5d373cbfb6f38836c18aa980e737b6f2c02839cde0420f23e934522cd4d4eac91b11ff31fab8faef5c9e81be19220f0d1744662f977c103d7454a3204d308
|
7
|
+
data.tar.gz: f3ab20e493301b11fcfee75d70d7d0c9b470dc068d474e069b7bdb7bc1af555748a02a60e82c5e2c1e61f85fb17016720225bc469d9ad043349e8607d9496fde
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/{LICENSE → LICENSE.md}
RENAMED
data/Rakefile
CHANGED
data/Readme.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# vue-rails
|
2
|
+
|
3
|
+
Inspired by [vuejs-rails](https://github.com/adambutler/vuejs-rails)
|
4
|
+
|
5
|
+
[![Gem](https://img.shields.io/gem/v/vue-rails.svg)](https://rubygems.org/gems/vue-rails)
|
6
|
+
[![Gem](https://img.shields.io/gem/dt/vue-rails.svg)](https://rubygems.org/gems/vue-rails)
|
7
|
+
|
8
|
+
### About
|
9
|
+
|
10
|
+
Rails 3.1+ asset-pipeline gem to provide Vue.js
|
11
|
+
|
12
|
+
### Package Versions
|
13
|
+
|
14
|
+
- vue v2.2.1
|
15
|
+
- vue-router v2.2.1
|
16
|
+
- vue-resource v1.2.1
|
17
|
+
- vuex v2.2.1
|
18
|
+
|
19
|
+
### Setup
|
20
|
+
|
21
|
+
Have in your Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'vue-rails'
|
25
|
+
```
|
26
|
+
|
27
|
+
You can install Vue as part of Ruby on Rails projet
|
28
|
+
```
|
29
|
+
rails new your-project javascript=vue
|
30
|
+
```
|
31
|
+
|
32
|
+
And in your application.js manifest:
|
33
|
+
|
34
|
+
```js
|
35
|
+
//= require vue
|
36
|
+
//= require vue-router (optional)
|
37
|
+
//= require vue-resource (optional)
|
38
|
+
```
|
39
|
+
|
40
|
+
If your `application.js` requires TurboLinks (a default setting for new Rails apps), you should strongly consider disabling it, as it will cause pages to load without reloading the Javascript.
|
41
|
+
|
42
|
+
In `app/views/layouts/application.html.erb`, move this line from the head of the document to the end of the body:
|
43
|
+
|
44
|
+
```html
|
45
|
+
<%= javascript_include_tag 'application' %>
|
46
|
+
```
|
47
|
+
|
48
|
+
You may write your Vue.js code directly in your views using `<script>` tags, or in a separate Javascript file (recommended).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Contributions are welcome, please follow [GitHub Flow](https://guides.github.com/introduction/flow/index.html)
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
[MIT](LICENSE.md)
|
data/lib/vue-rails.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
require "
|
1
|
+
require "vue-rails/version"
|
2
2
|
|
3
3
|
module Vue
|
4
4
|
module Rails
|
5
|
-
if defined?(::Rails) and Gem::Requirement.new('>=
|
6
|
-
class Rails::Engine < ::Rails::Engine
|
7
|
-
end
|
8
|
-
end
|
5
|
+
require "vue-rails/engine" if defined?(::Rails) and Gem::Requirement.new('>= 3.1').satisfied_by?(Gem::Version.new ::Rails.version)
|
9
6
|
end
|
10
7
|
end
|
data/lib/vue-rails/version.rb
CHANGED
@@ -0,0 +1,1534 @@
|
|
1
|
+
/*!
|
2
|
+
* vue-resource v1.2.1
|
3
|
+
* https://github.com/pagekit/vue-resource
|
4
|
+
* Released under the MIT License.
|
5
|
+
*/
|
6
|
+
|
7
|
+
(function (global, factory) {
|
8
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
9
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
10
|
+
(global.VueResource = factory());
|
11
|
+
}(this, (function () { 'use strict';
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis)
|
15
|
+
*/
|
16
|
+
|
17
|
+
var RESOLVED = 0;
|
18
|
+
var REJECTED = 1;
|
19
|
+
var PENDING = 2;
|
20
|
+
|
21
|
+
function Promise$1(executor) {
|
22
|
+
|
23
|
+
this.state = PENDING;
|
24
|
+
this.value = undefined;
|
25
|
+
this.deferred = [];
|
26
|
+
|
27
|
+
var promise = this;
|
28
|
+
|
29
|
+
try {
|
30
|
+
executor(function (x) {
|
31
|
+
promise.resolve(x);
|
32
|
+
}, function (r) {
|
33
|
+
promise.reject(r);
|
34
|
+
});
|
35
|
+
} catch (e) {
|
36
|
+
promise.reject(e);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
Promise$1.reject = function (r) {
|
41
|
+
return new Promise$1(function (resolve, reject) {
|
42
|
+
reject(r);
|
43
|
+
});
|
44
|
+
};
|
45
|
+
|
46
|
+
Promise$1.resolve = function (x) {
|
47
|
+
return new Promise$1(function (resolve, reject) {
|
48
|
+
resolve(x);
|
49
|
+
});
|
50
|
+
};
|
51
|
+
|
52
|
+
Promise$1.all = function all(iterable) {
|
53
|
+
return new Promise$1(function (resolve, reject) {
|
54
|
+
var count = 0, result = [];
|
55
|
+
|
56
|
+
if (iterable.length === 0) {
|
57
|
+
resolve(result);
|
58
|
+
}
|
59
|
+
|
60
|
+
function resolver(i) {
|
61
|
+
return function (x) {
|
62
|
+
result[i] = x;
|
63
|
+
count += 1;
|
64
|
+
|
65
|
+
if (count === iterable.length) {
|
66
|
+
resolve(result);
|
67
|
+
}
|
68
|
+
};
|
69
|
+
}
|
70
|
+
|
71
|
+
for (var i = 0; i < iterable.length; i += 1) {
|
72
|
+
Promise$1.resolve(iterable[i]).then(resolver(i), reject);
|
73
|
+
}
|
74
|
+
});
|
75
|
+
};
|
76
|
+
|
77
|
+
Promise$1.race = function race(iterable) {
|
78
|
+
return new Promise$1(function (resolve, reject) {
|
79
|
+
for (var i = 0; i < iterable.length; i += 1) {
|
80
|
+
Promise$1.resolve(iterable[i]).then(resolve, reject);
|
81
|
+
}
|
82
|
+
});
|
83
|
+
};
|
84
|
+
|
85
|
+
var p$1 = Promise$1.prototype;
|
86
|
+
|
87
|
+
p$1.resolve = function resolve(x) {
|
88
|
+
var promise = this;
|
89
|
+
|
90
|
+
if (promise.state === PENDING) {
|
91
|
+
if (x === promise) {
|
92
|
+
throw new TypeError('Promise settled with itself.');
|
93
|
+
}
|
94
|
+
|
95
|
+
var called = false;
|
96
|
+
|
97
|
+
try {
|
98
|
+
var then = x && x['then'];
|
99
|
+
|
100
|
+
if (x !== null && typeof x === 'object' && typeof then === 'function') {
|
101
|
+
then.call(x, function (x) {
|
102
|
+
if (!called) {
|
103
|
+
promise.resolve(x);
|
104
|
+
}
|
105
|
+
called = true;
|
106
|
+
|
107
|
+
}, function (r) {
|
108
|
+
if (!called) {
|
109
|
+
promise.reject(r);
|
110
|
+
}
|
111
|
+
called = true;
|
112
|
+
});
|
113
|
+
return;
|
114
|
+
}
|
115
|
+
} catch (e) {
|
116
|
+
if (!called) {
|
117
|
+
promise.reject(e);
|
118
|
+
}
|
119
|
+
return;
|
120
|
+
}
|
121
|
+
|
122
|
+
promise.state = RESOLVED;
|
123
|
+
promise.value = x;
|
124
|
+
promise.notify();
|
125
|
+
}
|
126
|
+
};
|
127
|
+
|
128
|
+
p$1.reject = function reject(reason) {
|
129
|
+
var promise = this;
|
130
|
+
|
131
|
+
if (promise.state === PENDING) {
|
132
|
+
if (reason === promise) {
|
133
|
+
throw new TypeError('Promise settled with itself.');
|
134
|
+
}
|
135
|
+
|
136
|
+
promise.state = REJECTED;
|
137
|
+
promise.value = reason;
|
138
|
+
promise.notify();
|
139
|
+
}
|
140
|
+
};
|
141
|
+
|
142
|
+
p$1.notify = function notify() {
|
143
|
+
var promise = this;
|
144
|
+
|
145
|
+
nextTick(function () {
|
146
|
+
if (promise.state !== PENDING) {
|
147
|
+
while (promise.deferred.length) {
|
148
|
+
var deferred = promise.deferred.shift(),
|
149
|
+
onResolved = deferred[0],
|
150
|
+
onRejected = deferred[1],
|
151
|
+
resolve = deferred[2],
|
152
|
+
reject = deferred[3];
|
153
|
+
|
154
|
+
try {
|
155
|
+
if (promise.state === RESOLVED) {
|
156
|
+
if (typeof onResolved === 'function') {
|
157
|
+
resolve(onResolved.call(undefined, promise.value));
|
158
|
+
} else {
|
159
|
+
resolve(promise.value);
|
160
|
+
}
|
161
|
+
} else if (promise.state === REJECTED) {
|
162
|
+
if (typeof onRejected === 'function') {
|
163
|
+
resolve(onRejected.call(undefined, promise.value));
|
164
|
+
} else {
|
165
|
+
reject(promise.value);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
} catch (e) {
|
169
|
+
reject(e);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}
|
173
|
+
});
|
174
|
+
};
|
175
|
+
|
176
|
+
p$1.then = function then(onResolved, onRejected) {
|
177
|
+
var promise = this;
|
178
|
+
|
179
|
+
return new Promise$1(function (resolve, reject) {
|
180
|
+
promise.deferred.push([onResolved, onRejected, resolve, reject]);
|
181
|
+
promise.notify();
|
182
|
+
});
|
183
|
+
};
|
184
|
+
|
185
|
+
p$1.catch = function (onRejected) {
|
186
|
+
return this.then(undefined, onRejected);
|
187
|
+
};
|
188
|
+
|
189
|
+
/**
|
190
|
+
* Promise adapter.
|
191
|
+
*/
|
192
|
+
|
193
|
+
if (typeof Promise === 'undefined') {
|
194
|
+
window.Promise = Promise$1;
|
195
|
+
}
|
196
|
+
|
197
|
+
function PromiseObj(executor, context) {
|
198
|
+
|
199
|
+
if (executor instanceof Promise) {
|
200
|
+
this.promise = executor;
|
201
|
+
} else {
|
202
|
+
this.promise = new Promise(executor.bind(context));
|
203
|
+
}
|
204
|
+
|
205
|
+
this.context = context;
|
206
|
+
}
|
207
|
+
|
208
|
+
PromiseObj.all = function (iterable, context) {
|
209
|
+
return new PromiseObj(Promise.all(iterable), context);
|
210
|
+
};
|
211
|
+
|
212
|
+
PromiseObj.resolve = function (value, context) {
|
213
|
+
return new PromiseObj(Promise.resolve(value), context);
|
214
|
+
};
|
215
|
+
|
216
|
+
PromiseObj.reject = function (reason, context) {
|
217
|
+
return new PromiseObj(Promise.reject(reason), context);
|
218
|
+
};
|
219
|
+
|
220
|
+
PromiseObj.race = function (iterable, context) {
|
221
|
+
return new PromiseObj(Promise.race(iterable), context);
|
222
|
+
};
|
223
|
+
|
224
|
+
var p = PromiseObj.prototype;
|
225
|
+
|
226
|
+
p.bind = function (context) {
|
227
|
+
this.context = context;
|
228
|
+
return this;
|
229
|
+
};
|
230
|
+
|
231
|
+
p.then = function (fulfilled, rejected) {
|
232
|
+
|
233
|
+
if (fulfilled && fulfilled.bind && this.context) {
|
234
|
+
fulfilled = fulfilled.bind(this.context);
|
235
|
+
}
|
236
|
+
|
237
|
+
if (rejected && rejected.bind && this.context) {
|
238
|
+
rejected = rejected.bind(this.context);
|
239
|
+
}
|
240
|
+
|
241
|
+
return new PromiseObj(this.promise.then(fulfilled, rejected), this.context);
|
242
|
+
};
|
243
|
+
|
244
|
+
p.catch = function (rejected) {
|
245
|
+
|
246
|
+
if (rejected && rejected.bind && this.context) {
|
247
|
+
rejected = rejected.bind(this.context);
|
248
|
+
}
|
249
|
+
|
250
|
+
return new PromiseObj(this.promise.catch(rejected), this.context);
|
251
|
+
};
|
252
|
+
|
253
|
+
p.finally = function (callback) {
|
254
|
+
|
255
|
+
return this.then(function (value) {
|
256
|
+
callback.call(this);
|
257
|
+
return value;
|
258
|
+
}, function (reason) {
|
259
|
+
callback.call(this);
|
260
|
+
return Promise.reject(reason);
|
261
|
+
}
|
262
|
+
);
|
263
|
+
};
|
264
|
+
|
265
|
+
/**
|
266
|
+
* Utility functions.
|
267
|
+
*/
|
268
|
+
|
269
|
+
var ref = {};
|
270
|
+
var hasOwnProperty = ref.hasOwnProperty;
|
271
|
+
|
272
|
+
var ref$1 = [];
|
273
|
+
var slice = ref$1.slice;
|
274
|
+
var debug = false;
|
275
|
+
var ntick;
|
276
|
+
|
277
|
+
var inBrowser = typeof window !== 'undefined';
|
278
|
+
|
279
|
+
var Util = function (ref) {
|
280
|
+
var config = ref.config;
|
281
|
+
var nextTick = ref.nextTick;
|
282
|
+
|
283
|
+
ntick = nextTick;
|
284
|
+
debug = config.debug || !config.silent;
|
285
|
+
};
|
286
|
+
|
287
|
+
function warn(msg) {
|
288
|
+
if (typeof console !== 'undefined' && debug) {
|
289
|
+
console.warn('[VueResource warn]: ' + msg);
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
function error(msg) {
|
294
|
+
if (typeof console !== 'undefined') {
|
295
|
+
console.error(msg);
|
296
|
+
}
|
297
|
+
}
|
298
|
+
|
299
|
+
function nextTick(cb, ctx) {
|
300
|
+
return ntick(cb, ctx);
|
301
|
+
}
|
302
|
+
|
303
|
+
function trim(str) {
|
304
|
+
return str ? str.replace(/^\s*|\s*$/g, '') : '';
|
305
|
+
}
|
306
|
+
|
307
|
+
function toLower(str) {
|
308
|
+
return str ? str.toLowerCase() : '';
|
309
|
+
}
|
310
|
+
|
311
|
+
function toUpper(str) {
|
312
|
+
return str ? str.toUpperCase() : '';
|
313
|
+
}
|
314
|
+
|
315
|
+
var isArray = Array.isArray;
|
316
|
+
|
317
|
+
function isString(val) {
|
318
|
+
return typeof val === 'string';
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
function isFunction(val) {
|
324
|
+
return typeof val === 'function';
|
325
|
+
}
|
326
|
+
|
327
|
+
function isObject(obj) {
|
328
|
+
return obj !== null && typeof obj === 'object';
|
329
|
+
}
|
330
|
+
|
331
|
+
function isPlainObject(obj) {
|
332
|
+
return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype;
|
333
|
+
}
|
334
|
+
|
335
|
+
function isBlob(obj) {
|
336
|
+
return typeof Blob !== 'undefined' && obj instanceof Blob;
|
337
|
+
}
|
338
|
+
|
339
|
+
function isFormData(obj) {
|
340
|
+
return typeof FormData !== 'undefined' && obj instanceof FormData;
|
341
|
+
}
|
342
|
+
|
343
|
+
function when(value, fulfilled, rejected) {
|
344
|
+
|
345
|
+
var promise = PromiseObj.resolve(value);
|
346
|
+
|
347
|
+
if (arguments.length < 2) {
|
348
|
+
return promise;
|
349
|
+
}
|
350
|
+
|
351
|
+
return promise.then(fulfilled, rejected);
|
352
|
+
}
|
353
|
+
|
354
|
+
function options(fn, obj, opts) {
|
355
|
+
|
356
|
+
opts = opts || {};
|
357
|
+
|
358
|
+
if (isFunction(opts)) {
|
359
|
+
opts = opts.call(obj);
|
360
|
+
}
|
361
|
+
|
362
|
+
return merge(fn.bind({$vm: obj, $options: opts}), fn, {$options: opts});
|
363
|
+
}
|
364
|
+
|
365
|
+
function each(obj, iterator) {
|
366
|
+
|
367
|
+
var i, key;
|
368
|
+
|
369
|
+
if (isArray(obj)) {
|
370
|
+
for (i = 0; i < obj.length; i++) {
|
371
|
+
iterator.call(obj[i], obj[i], i);
|
372
|
+
}
|
373
|
+
} else if (isObject(obj)) {
|
374
|
+
for (key in obj) {
|
375
|
+
if (hasOwnProperty.call(obj, key)) {
|
376
|
+
iterator.call(obj[key], obj[key], key);
|
377
|
+
}
|
378
|
+
}
|
379
|
+
}
|
380
|
+
|
381
|
+
return obj;
|
382
|
+
}
|
383
|
+
|
384
|
+
var assign = Object.assign || _assign;
|
385
|
+
|
386
|
+
function merge(target) {
|
387
|
+
|
388
|
+
var args = slice.call(arguments, 1);
|
389
|
+
|
390
|
+
args.forEach(function (source) {
|
391
|
+
_merge(target, source, true);
|
392
|
+
});
|
393
|
+
|
394
|
+
return target;
|
395
|
+
}
|
396
|
+
|
397
|
+
function defaults(target) {
|
398
|
+
|
399
|
+
var args = slice.call(arguments, 1);
|
400
|
+
|
401
|
+
args.forEach(function (source) {
|
402
|
+
|
403
|
+
for (var key in source) {
|
404
|
+
if (target[key] === undefined) {
|
405
|
+
target[key] = source[key];
|
406
|
+
}
|
407
|
+
}
|
408
|
+
|
409
|
+
});
|
410
|
+
|
411
|
+
return target;
|
412
|
+
}
|
413
|
+
|
414
|
+
function _assign(target) {
|
415
|
+
|
416
|
+
var args = slice.call(arguments, 1);
|
417
|
+
|
418
|
+
args.forEach(function (source) {
|
419
|
+
_merge(target, source);
|
420
|
+
});
|
421
|
+
|
422
|
+
return target;
|
423
|
+
}
|
424
|
+
|
425
|
+
function _merge(target, source, deep) {
|
426
|
+
for (var key in source) {
|
427
|
+
if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
|
428
|
+
if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
|
429
|
+
target[key] = {};
|
430
|
+
}
|
431
|
+
if (isArray(source[key]) && !isArray(target[key])) {
|
432
|
+
target[key] = [];
|
433
|
+
}
|
434
|
+
_merge(target[key], source[key], deep);
|
435
|
+
} else if (source[key] !== undefined) {
|
436
|
+
target[key] = source[key];
|
437
|
+
}
|
438
|
+
}
|
439
|
+
}
|
440
|
+
|
441
|
+
/**
|
442
|
+
* Root Prefix Transform.
|
443
|
+
*/
|
444
|
+
|
445
|
+
var root = function (options$$1, next) {
|
446
|
+
|
447
|
+
var url = next(options$$1);
|
448
|
+
|
449
|
+
if (isString(options$$1.root) && !url.match(/^(https?:)?\//)) {
|
450
|
+
url = options$$1.root + '/' + url;
|
451
|
+
}
|
452
|
+
|
453
|
+
return url;
|
454
|
+
};
|
455
|
+
|
456
|
+
/**
|
457
|
+
* Query Parameter Transform.
|
458
|
+
*/
|
459
|
+
|
460
|
+
var query = function (options$$1, next) {
|
461
|
+
|
462
|
+
var urlParams = Object.keys(Url.options.params), query = {}, url = next(options$$1);
|
463
|
+
|
464
|
+
each(options$$1.params, function (value, key) {
|
465
|
+
if (urlParams.indexOf(key) === -1) {
|
466
|
+
query[key] = value;
|
467
|
+
}
|
468
|
+
});
|
469
|
+
|
470
|
+
query = Url.params(query);
|
471
|
+
|
472
|
+
if (query) {
|
473
|
+
url += (url.indexOf('?') == -1 ? '?' : '&') + query;
|
474
|
+
}
|
475
|
+
|
476
|
+
return url;
|
477
|
+
};
|
478
|
+
|
479
|
+
/**
|
480
|
+
* URL Template v2.0.6 (https://github.com/bramstein/url-template)
|
481
|
+
*/
|
482
|
+
|
483
|
+
function expand(url, params, variables) {
|
484
|
+
|
485
|
+
var tmpl = parse(url), expanded = tmpl.expand(params);
|
486
|
+
|
487
|
+
if (variables) {
|
488
|
+
variables.push.apply(variables, tmpl.vars);
|
489
|
+
}
|
490
|
+
|
491
|
+
return expanded;
|
492
|
+
}
|
493
|
+
|
494
|
+
function parse(template) {
|
495
|
+
|
496
|
+
var operators = ['+', '#', '.', '/', ';', '?', '&'], variables = [];
|
497
|
+
|
498
|
+
return {
|
499
|
+
vars: variables,
|
500
|
+
expand: function expand(context) {
|
501
|
+
return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) {
|
502
|
+
if (expression) {
|
503
|
+
|
504
|
+
var operator = null, values = [];
|
505
|
+
|
506
|
+
if (operators.indexOf(expression.charAt(0)) !== -1) {
|
507
|
+
operator = expression.charAt(0);
|
508
|
+
expression = expression.substr(1);
|
509
|
+
}
|
510
|
+
|
511
|
+
expression.split(/,/g).forEach(function (variable) {
|
512
|
+
var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable);
|
513
|
+
values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3]));
|
514
|
+
variables.push(tmp[1]);
|
515
|
+
});
|
516
|
+
|
517
|
+
if (operator && operator !== '+') {
|
518
|
+
|
519
|
+
var separator = ',';
|
520
|
+
|
521
|
+
if (operator === '?') {
|
522
|
+
separator = '&';
|
523
|
+
} else if (operator !== '#') {
|
524
|
+
separator = operator;
|
525
|
+
}
|
526
|
+
|
527
|
+
return (values.length !== 0 ? operator : '') + values.join(separator);
|
528
|
+
} else {
|
529
|
+
return values.join(',');
|
530
|
+
}
|
531
|
+
|
532
|
+
} else {
|
533
|
+
return encodeReserved(literal);
|
534
|
+
}
|
535
|
+
});
|
536
|
+
}
|
537
|
+
};
|
538
|
+
}
|
539
|
+
|
540
|
+
function getValues(context, operator, key, modifier) {
|
541
|
+
|
542
|
+
var value = context[key], result = [];
|
543
|
+
|
544
|
+
if (isDefined(value) && value !== '') {
|
545
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
546
|
+
value = value.toString();
|
547
|
+
|
548
|
+
if (modifier && modifier !== '*') {
|
549
|
+
value = value.substring(0, parseInt(modifier, 10));
|
550
|
+
}
|
551
|
+
|
552
|
+
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null));
|
553
|
+
} else {
|
554
|
+
if (modifier === '*') {
|
555
|
+
if (Array.isArray(value)) {
|
556
|
+
value.filter(isDefined).forEach(function (value) {
|
557
|
+
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null));
|
558
|
+
});
|
559
|
+
} else {
|
560
|
+
Object.keys(value).forEach(function (k) {
|
561
|
+
if (isDefined(value[k])) {
|
562
|
+
result.push(encodeValue(operator, value[k], k));
|
563
|
+
}
|
564
|
+
});
|
565
|
+
}
|
566
|
+
} else {
|
567
|
+
var tmp = [];
|
568
|
+
|
569
|
+
if (Array.isArray(value)) {
|
570
|
+
value.filter(isDefined).forEach(function (value) {
|
571
|
+
tmp.push(encodeValue(operator, value));
|
572
|
+
});
|
573
|
+
} else {
|
574
|
+
Object.keys(value).forEach(function (k) {
|
575
|
+
if (isDefined(value[k])) {
|
576
|
+
tmp.push(encodeURIComponent(k));
|
577
|
+
tmp.push(encodeValue(operator, value[k].toString()));
|
578
|
+
}
|
579
|
+
});
|
580
|
+
}
|
581
|
+
|
582
|
+
if (isKeyOperator(operator)) {
|
583
|
+
result.push(encodeURIComponent(key) + '=' + tmp.join(','));
|
584
|
+
} else if (tmp.length !== 0) {
|
585
|
+
result.push(tmp.join(','));
|
586
|
+
}
|
587
|
+
}
|
588
|
+
}
|
589
|
+
} else {
|
590
|
+
if (operator === ';') {
|
591
|
+
result.push(encodeURIComponent(key));
|
592
|
+
} else if (value === '' && (operator === '&' || operator === '?')) {
|
593
|
+
result.push(encodeURIComponent(key) + '=');
|
594
|
+
} else if (value === '') {
|
595
|
+
result.push('');
|
596
|
+
}
|
597
|
+
}
|
598
|
+
|
599
|
+
return result;
|
600
|
+
}
|
601
|
+
|
602
|
+
function isDefined(value) {
|
603
|
+
return value !== undefined && value !== null;
|
604
|
+
}
|
605
|
+
|
606
|
+
function isKeyOperator(operator) {
|
607
|
+
return operator === ';' || operator === '&' || operator === '?';
|
608
|
+
}
|
609
|
+
|
610
|
+
function encodeValue(operator, value, key) {
|
611
|
+
|
612
|
+
value = (operator === '+' || operator === '#') ? encodeReserved(value) : encodeURIComponent(value);
|
613
|
+
|
614
|
+
if (key) {
|
615
|
+
return encodeURIComponent(key) + '=' + value;
|
616
|
+
} else {
|
617
|
+
return value;
|
618
|
+
}
|
619
|
+
}
|
620
|
+
|
621
|
+
function encodeReserved(str) {
|
622
|
+
return str.split(/(%[0-9A-Fa-f]{2})/g).map(function (part) {
|
623
|
+
if (!/%[0-9A-Fa-f]/.test(part)) {
|
624
|
+
part = encodeURI(part);
|
625
|
+
}
|
626
|
+
return part;
|
627
|
+
}).join('');
|
628
|
+
}
|
629
|
+
|
630
|
+
/**
|
631
|
+
* URL Template (RFC 6570) Transform.
|
632
|
+
*/
|
633
|
+
|
634
|
+
var template = function (options) {
|
635
|
+
|
636
|
+
var variables = [], url = expand(options.url, options.params, variables);
|
637
|
+
|
638
|
+
variables.forEach(function (key) {
|
639
|
+
delete options.params[key];
|
640
|
+
});
|
641
|
+
|
642
|
+
return url;
|
643
|
+
};
|
644
|
+
|
645
|
+
/**
|
646
|
+
* Service for URL templating.
|
647
|
+
*/
|
648
|
+
|
649
|
+
function Url(url, params) {
|
650
|
+
|
651
|
+
var self = this || {}, options$$1 = url, transform;
|
652
|
+
|
653
|
+
if (isString(url)) {
|
654
|
+
options$$1 = {url: url, params: params};
|
655
|
+
}
|
656
|
+
|
657
|
+
options$$1 = merge({}, Url.options, self.$options, options$$1);
|
658
|
+
|
659
|
+
Url.transforms.forEach(function (handler) {
|
660
|
+
transform = factory(handler, transform, self.$vm);
|
661
|
+
});
|
662
|
+
|
663
|
+
return transform(options$$1);
|
664
|
+
}
|
665
|
+
|
666
|
+
/**
|
667
|
+
* Url options.
|
668
|
+
*/
|
669
|
+
|
670
|
+
Url.options = {
|
671
|
+
url: '',
|
672
|
+
root: null,
|
673
|
+
params: {}
|
674
|
+
};
|
675
|
+
|
676
|
+
/**
|
677
|
+
* Url transforms.
|
678
|
+
*/
|
679
|
+
|
680
|
+
Url.transforms = [template, query, root];
|
681
|
+
|
682
|
+
/**
|
683
|
+
* Encodes a Url parameter string.
|
684
|
+
*
|
685
|
+
* @param {Object} obj
|
686
|
+
*/
|
687
|
+
|
688
|
+
Url.params = function (obj) {
|
689
|
+
|
690
|
+
var params = [], escape = encodeURIComponent;
|
691
|
+
|
692
|
+
params.add = function (key, value) {
|
693
|
+
|
694
|
+
if (isFunction(value)) {
|
695
|
+
value = value();
|
696
|
+
}
|
697
|
+
|
698
|
+
if (value === null) {
|
699
|
+
value = '';
|
700
|
+
}
|
701
|
+
|
702
|
+
this.push(escape(key) + '=' + escape(value));
|
703
|
+
};
|
704
|
+
|
705
|
+
serialize(params, obj);
|
706
|
+
|
707
|
+
return params.join('&').replace(/%20/g, '+');
|
708
|
+
};
|
709
|
+
|
710
|
+
/**
|
711
|
+
* Parse a URL and return its components.
|
712
|
+
*
|
713
|
+
* @param {String} url
|
714
|
+
*/
|
715
|
+
|
716
|
+
Url.parse = function (url) {
|
717
|
+
|
718
|
+
var el = document.createElement('a');
|
719
|
+
|
720
|
+
if (document.documentMode) {
|
721
|
+
el.href = url;
|
722
|
+
url = el.href;
|
723
|
+
}
|
724
|
+
|
725
|
+
el.href = url;
|
726
|
+
|
727
|
+
return {
|
728
|
+
href: el.href,
|
729
|
+
protocol: el.protocol ? el.protocol.replace(/:$/, '') : '',
|
730
|
+
port: el.port,
|
731
|
+
host: el.host,
|
732
|
+
hostname: el.hostname,
|
733
|
+
pathname: el.pathname.charAt(0) === '/' ? el.pathname : '/' + el.pathname,
|
734
|
+
search: el.search ? el.search.replace(/^\?/, '') : '',
|
735
|
+
hash: el.hash ? el.hash.replace(/^#/, '') : ''
|
736
|
+
};
|
737
|
+
};
|
738
|
+
|
739
|
+
function factory(handler, next, vm) {
|
740
|
+
return function (options$$1) {
|
741
|
+
return handler.call(vm, options$$1, next);
|
742
|
+
};
|
743
|
+
}
|
744
|
+
|
745
|
+
function serialize(params, obj, scope) {
|
746
|
+
|
747
|
+
var array = isArray(obj), plain = isPlainObject(obj), hash;
|
748
|
+
|
749
|
+
each(obj, function (value, key) {
|
750
|
+
|
751
|
+
hash = isObject(value) || isArray(value);
|
752
|
+
|
753
|
+
if (scope) {
|
754
|
+
key = scope + '[' + (plain || hash ? key : '') + ']';
|
755
|
+
}
|
756
|
+
|
757
|
+
if (!scope && array) {
|
758
|
+
params.add(value.name, value.value);
|
759
|
+
} else if (hash) {
|
760
|
+
serialize(params, value, key);
|
761
|
+
} else {
|
762
|
+
params.add(key, value);
|
763
|
+
}
|
764
|
+
});
|
765
|
+
}
|
766
|
+
|
767
|
+
/**
|
768
|
+
* XDomain client (Internet Explorer).
|
769
|
+
*/
|
770
|
+
|
771
|
+
var xdrClient = function (request) {
|
772
|
+
return new PromiseObj(function (resolve) {
|
773
|
+
|
774
|
+
var xdr = new XDomainRequest(), handler = function (ref) {
|
775
|
+
var type = ref.type;
|
776
|
+
|
777
|
+
|
778
|
+
var status = 0;
|
779
|
+
|
780
|
+
if (type === 'load') {
|
781
|
+
status = 200;
|
782
|
+
} else if (type === 'error') {
|
783
|
+
status = 500;
|
784
|
+
}
|
785
|
+
|
786
|
+
resolve(request.respondWith(xdr.responseText, {status: status}));
|
787
|
+
};
|
788
|
+
|
789
|
+
request.abort = function () { return xdr.abort(); };
|
790
|
+
|
791
|
+
xdr.open(request.method, request.getUrl());
|
792
|
+
|
793
|
+
if (request.timeout) {
|
794
|
+
xdr.timeout = request.timeout;
|
795
|
+
}
|
796
|
+
|
797
|
+
xdr.onload = handler;
|
798
|
+
xdr.onabort = handler;
|
799
|
+
xdr.onerror = handler;
|
800
|
+
xdr.ontimeout = handler;
|
801
|
+
xdr.onprogress = function () {};
|
802
|
+
xdr.send(request.getBody());
|
803
|
+
});
|
804
|
+
};
|
805
|
+
|
806
|
+
/**
|
807
|
+
* CORS Interceptor.
|
808
|
+
*/
|
809
|
+
|
810
|
+
var SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest();
|
811
|
+
|
812
|
+
var cors = function (request, next) {
|
813
|
+
|
814
|
+
if (inBrowser) {
|
815
|
+
|
816
|
+
var orgUrl = Url.parse(location.href);
|
817
|
+
var reqUrl = Url.parse(request.getUrl());
|
818
|
+
|
819
|
+
if (reqUrl.protocol !== orgUrl.protocol || reqUrl.host !== orgUrl.host) {
|
820
|
+
|
821
|
+
request.crossOrigin = true;
|
822
|
+
request.emulateHTTP = false;
|
823
|
+
|
824
|
+
if (!SUPPORTS_CORS) {
|
825
|
+
request.client = xdrClient;
|
826
|
+
}
|
827
|
+
}
|
828
|
+
}
|
829
|
+
|
830
|
+
next();
|
831
|
+
};
|
832
|
+
|
833
|
+
/**
|
834
|
+
* Body Interceptor.
|
835
|
+
*/
|
836
|
+
|
837
|
+
var body = function (request, next) {
|
838
|
+
|
839
|
+
if (isFormData(request.body)) {
|
840
|
+
|
841
|
+
request.headers.delete('Content-Type');
|
842
|
+
|
843
|
+
} else if (isObject(request.body) || isArray(request.body)) {
|
844
|
+
|
845
|
+
if (request.emulateJSON) {
|
846
|
+
request.body = Url.params(request.body);
|
847
|
+
request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
|
848
|
+
} else {
|
849
|
+
request.body = JSON.stringify(request.body);
|
850
|
+
}
|
851
|
+
}
|
852
|
+
|
853
|
+
next(function (response) {
|
854
|
+
|
855
|
+
Object.defineProperty(response, 'data', {
|
856
|
+
|
857
|
+
get: function get() {
|
858
|
+
return this.body;
|
859
|
+
},
|
860
|
+
|
861
|
+
set: function set(body) {
|
862
|
+
this.body = body;
|
863
|
+
}
|
864
|
+
|
865
|
+
});
|
866
|
+
|
867
|
+
return response.bodyText ? when(response.text(), function (text) {
|
868
|
+
|
869
|
+
var type = response.headers.get('Content-Type') || '';
|
870
|
+
|
871
|
+
if (type.indexOf('application/json') === 0 || isJson(text)) {
|
872
|
+
|
873
|
+
try {
|
874
|
+
response.body = JSON.parse(text);
|
875
|
+
} catch (e) {
|
876
|
+
response.body = null;
|
877
|
+
}
|
878
|
+
|
879
|
+
} else {
|
880
|
+
response.body = text;
|
881
|
+
}
|
882
|
+
|
883
|
+
return response;
|
884
|
+
|
885
|
+
}) : response;
|
886
|
+
|
887
|
+
});
|
888
|
+
};
|
889
|
+
|
890
|
+
function isJson(str) {
|
891
|
+
|
892
|
+
var start = str.match(/^\[|^\{(?!\{)/), end = {'[': /]$/, '{': /}$/};
|
893
|
+
|
894
|
+
return start && end[start[0]].test(str);
|
895
|
+
}
|
896
|
+
|
897
|
+
/**
|
898
|
+
* JSONP client (Browser).
|
899
|
+
*/
|
900
|
+
|
901
|
+
var jsonpClient = function (request) {
|
902
|
+
return new PromiseObj(function (resolve) {
|
903
|
+
|
904
|
+
var name = request.jsonp || 'callback', callback = request.jsonpCallback || '_jsonp' + Math.random().toString(36).substr(2), body = null, handler, script;
|
905
|
+
|
906
|
+
handler = function (ref) {
|
907
|
+
var type = ref.type;
|
908
|
+
|
909
|
+
|
910
|
+
var status = 0;
|
911
|
+
|
912
|
+
if (type === 'load' && body !== null) {
|
913
|
+
status = 200;
|
914
|
+
} else if (type === 'error') {
|
915
|
+
status = 500;
|
916
|
+
}
|
917
|
+
|
918
|
+
if (status && window[callback]) {
|
919
|
+
delete window[callback];
|
920
|
+
document.body.removeChild(script);
|
921
|
+
}
|
922
|
+
|
923
|
+
resolve(request.respondWith(body, {status: status}));
|
924
|
+
};
|
925
|
+
|
926
|
+
window[callback] = function (result) {
|
927
|
+
body = JSON.stringify(result);
|
928
|
+
};
|
929
|
+
|
930
|
+
request.abort = function () {
|
931
|
+
handler({type: 'abort'});
|
932
|
+
};
|
933
|
+
|
934
|
+
request.params[name] = callback;
|
935
|
+
|
936
|
+
if (request.timeout) {
|
937
|
+
setTimeout(request.abort, request.timeout);
|
938
|
+
}
|
939
|
+
|
940
|
+
script = document.createElement('script');
|
941
|
+
script.src = request.getUrl();
|
942
|
+
script.type = 'text/javascript';
|
943
|
+
script.async = true;
|
944
|
+
script.onload = handler;
|
945
|
+
script.onerror = handler;
|
946
|
+
|
947
|
+
document.body.appendChild(script);
|
948
|
+
});
|
949
|
+
};
|
950
|
+
|
951
|
+
/**
|
952
|
+
* JSONP Interceptor.
|
953
|
+
*/
|
954
|
+
|
955
|
+
var jsonp = function (request, next) {
|
956
|
+
|
957
|
+
if (request.method == 'JSONP') {
|
958
|
+
request.client = jsonpClient;
|
959
|
+
}
|
960
|
+
|
961
|
+
next();
|
962
|
+
};
|
963
|
+
|
964
|
+
/**
|
965
|
+
* Before Interceptor.
|
966
|
+
*/
|
967
|
+
|
968
|
+
var before = function (request, next) {
|
969
|
+
|
970
|
+
if (isFunction(request.before)) {
|
971
|
+
request.before.call(this, request);
|
972
|
+
}
|
973
|
+
|
974
|
+
next();
|
975
|
+
};
|
976
|
+
|
977
|
+
/**
|
978
|
+
* HTTP method override Interceptor.
|
979
|
+
*/
|
980
|
+
|
981
|
+
var method = function (request, next) {
|
982
|
+
|
983
|
+
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) {
|
984
|
+
request.headers.set('X-HTTP-Method-Override', request.method);
|
985
|
+
request.method = 'POST';
|
986
|
+
}
|
987
|
+
|
988
|
+
next();
|
989
|
+
};
|
990
|
+
|
991
|
+
/**
|
992
|
+
* Header Interceptor.
|
993
|
+
*/
|
994
|
+
|
995
|
+
var header = function (request, next) {
|
996
|
+
|
997
|
+
var headers = assign({}, Http.headers.common,
|
998
|
+
!request.crossOrigin ? Http.headers.custom : {},
|
999
|
+
Http.headers[toLower(request.method)]
|
1000
|
+
);
|
1001
|
+
|
1002
|
+
each(headers, function (value, name) {
|
1003
|
+
if (!request.headers.has(name)) {
|
1004
|
+
request.headers.set(name, value);
|
1005
|
+
}
|
1006
|
+
});
|
1007
|
+
|
1008
|
+
next();
|
1009
|
+
};
|
1010
|
+
|
1011
|
+
/**
|
1012
|
+
* XMLHttp client (Browser).
|
1013
|
+
*/
|
1014
|
+
|
1015
|
+
var SUPPORTS_BLOB = typeof Blob !== 'undefined' && typeof FileReader !== 'undefined';
|
1016
|
+
|
1017
|
+
var xhrClient = function (request) {
|
1018
|
+
return new PromiseObj(function (resolve) {
|
1019
|
+
|
1020
|
+
var xhr = new XMLHttpRequest(), handler = function (event) {
|
1021
|
+
|
1022
|
+
var response = request.respondWith(
|
1023
|
+
'response' in xhr ? xhr.response : xhr.responseText, {
|
1024
|
+
status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug
|
1025
|
+
statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText)
|
1026
|
+
}
|
1027
|
+
);
|
1028
|
+
|
1029
|
+
each(trim(xhr.getAllResponseHeaders()).split('\n'), function (row) {
|
1030
|
+
response.headers.append(row.slice(0, row.indexOf(':')), row.slice(row.indexOf(':') + 1));
|
1031
|
+
});
|
1032
|
+
|
1033
|
+
resolve(response);
|
1034
|
+
};
|
1035
|
+
|
1036
|
+
request.abort = function () { return xhr.abort(); };
|
1037
|
+
|
1038
|
+
if (request.progress) {
|
1039
|
+
if (request.method === 'GET') {
|
1040
|
+
xhr.addEventListener('progress', request.progress);
|
1041
|
+
} else if (/^(POST|PUT)$/i.test(request.method)) {
|
1042
|
+
xhr.upload.addEventListener('progress', request.progress);
|
1043
|
+
}
|
1044
|
+
}
|
1045
|
+
|
1046
|
+
xhr.open(request.method, request.getUrl(), true);
|
1047
|
+
|
1048
|
+
if (request.timeout) {
|
1049
|
+
xhr.timeout = request.timeout;
|
1050
|
+
}
|
1051
|
+
|
1052
|
+
if (request.credentials === true) {
|
1053
|
+
xhr.withCredentials = true;
|
1054
|
+
}
|
1055
|
+
|
1056
|
+
if (!request.crossOrigin) {
|
1057
|
+
request.headers.set('X-Requested-With', 'XMLHttpRequest');
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
if ('responseType' in xhr && SUPPORTS_BLOB) {
|
1061
|
+
xhr.responseType = 'blob';
|
1062
|
+
}
|
1063
|
+
|
1064
|
+
request.headers.forEach(function (value, name) {
|
1065
|
+
xhr.setRequestHeader(name, value);
|
1066
|
+
});
|
1067
|
+
|
1068
|
+
xhr.onload = handler;
|
1069
|
+
xhr.onabort = handler;
|
1070
|
+
xhr.onerror = handler;
|
1071
|
+
xhr.ontimeout = handler;
|
1072
|
+
xhr.send(request.getBody());
|
1073
|
+
});
|
1074
|
+
};
|
1075
|
+
|
1076
|
+
/**
|
1077
|
+
* Http client (Node).
|
1078
|
+
*/
|
1079
|
+
|
1080
|
+
var nodeClient = function (request) {
|
1081
|
+
|
1082
|
+
var client = require('got');
|
1083
|
+
|
1084
|
+
return new PromiseObj(function (resolve) {
|
1085
|
+
|
1086
|
+
var url = request.getUrl();
|
1087
|
+
var body = request.getBody();
|
1088
|
+
var method = request.method;
|
1089
|
+
var headers = {}, handler;
|
1090
|
+
|
1091
|
+
request.headers.forEach(function (value, name) {
|
1092
|
+
headers[name] = value;
|
1093
|
+
});
|
1094
|
+
|
1095
|
+
client(url, {body: body, method: method, headers: headers}).then(handler = function (resp) {
|
1096
|
+
|
1097
|
+
var response = request.respondWith(resp.body, {
|
1098
|
+
status: resp.statusCode,
|
1099
|
+
statusText: trim(resp.statusMessage)
|
1100
|
+
}
|
1101
|
+
);
|
1102
|
+
|
1103
|
+
each(resp.headers, function (value, name) {
|
1104
|
+
response.headers.set(name, value);
|
1105
|
+
});
|
1106
|
+
|
1107
|
+
resolve(response);
|
1108
|
+
|
1109
|
+
}, function (error$$1) { return handler(error$$1.response); });
|
1110
|
+
});
|
1111
|
+
};
|
1112
|
+
|
1113
|
+
/**
|
1114
|
+
* Base client.
|
1115
|
+
*/
|
1116
|
+
|
1117
|
+
var Client = function (context) {
|
1118
|
+
|
1119
|
+
var reqHandlers = [sendRequest], resHandlers = [], handler;
|
1120
|
+
|
1121
|
+
if (!isObject(context)) {
|
1122
|
+
context = null;
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
function Client(request) {
|
1126
|
+
return new PromiseObj(function (resolve) {
|
1127
|
+
|
1128
|
+
function exec() {
|
1129
|
+
|
1130
|
+
handler = reqHandlers.pop();
|
1131
|
+
|
1132
|
+
if (isFunction(handler)) {
|
1133
|
+
handler.call(context, request, next);
|
1134
|
+
} else {
|
1135
|
+
warn(("Invalid interceptor of type " + (typeof handler) + ", must be a function"));
|
1136
|
+
next();
|
1137
|
+
}
|
1138
|
+
}
|
1139
|
+
|
1140
|
+
function next(response) {
|
1141
|
+
|
1142
|
+
if (isFunction(response)) {
|
1143
|
+
|
1144
|
+
resHandlers.unshift(response);
|
1145
|
+
|
1146
|
+
} else if (isObject(response)) {
|
1147
|
+
|
1148
|
+
resHandlers.forEach(function (handler) {
|
1149
|
+
response = when(response, function (response) {
|
1150
|
+
return handler.call(context, response) || response;
|
1151
|
+
});
|
1152
|
+
});
|
1153
|
+
|
1154
|
+
when(response, resolve);
|
1155
|
+
|
1156
|
+
return;
|
1157
|
+
}
|
1158
|
+
|
1159
|
+
exec();
|
1160
|
+
}
|
1161
|
+
|
1162
|
+
exec();
|
1163
|
+
|
1164
|
+
}, context);
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
Client.use = function (handler) {
|
1168
|
+
reqHandlers.push(handler);
|
1169
|
+
};
|
1170
|
+
|
1171
|
+
return Client;
|
1172
|
+
};
|
1173
|
+
|
1174
|
+
function sendRequest(request, resolve) {
|
1175
|
+
|
1176
|
+
var client = request.client || (inBrowser ? xhrClient : nodeClient);
|
1177
|
+
|
1178
|
+
resolve(client(request));
|
1179
|
+
}
|
1180
|
+
|
1181
|
+
/**
|
1182
|
+
* HTTP Headers.
|
1183
|
+
*/
|
1184
|
+
|
1185
|
+
var Headers = function Headers(headers) {
|
1186
|
+
var this$1 = this;
|
1187
|
+
|
1188
|
+
|
1189
|
+
this.map = {};
|
1190
|
+
|
1191
|
+
each(headers, function (value, name) { return this$1.append(name, value); });
|
1192
|
+
};
|
1193
|
+
|
1194
|
+
Headers.prototype.has = function has (name) {
|
1195
|
+
return getName(this.map, name) !== null;
|
1196
|
+
};
|
1197
|
+
|
1198
|
+
Headers.prototype.get = function get (name) {
|
1199
|
+
|
1200
|
+
var list = this.map[getName(this.map, name)];
|
1201
|
+
|
1202
|
+
return list ? list.join() : null;
|
1203
|
+
};
|
1204
|
+
|
1205
|
+
Headers.prototype.getAll = function getAll (name) {
|
1206
|
+
return this.map[getName(this.map, name)] || [];
|
1207
|
+
};
|
1208
|
+
|
1209
|
+
Headers.prototype.set = function set (name, value) {
|
1210
|
+
this.map[normalizeName(getName(this.map, name) || name)] = [trim(value)];
|
1211
|
+
};
|
1212
|
+
|
1213
|
+
Headers.prototype.append = function append (name, value){
|
1214
|
+
|
1215
|
+
var list = this.map[getName(this.map, name)];
|
1216
|
+
|
1217
|
+
if (list) {
|
1218
|
+
list.push(trim(value));
|
1219
|
+
} else {
|
1220
|
+
this.set(name, value);
|
1221
|
+
}
|
1222
|
+
};
|
1223
|
+
|
1224
|
+
Headers.prototype.delete = function delete$1 (name){
|
1225
|
+
delete this.map[getName(this.map, name)];
|
1226
|
+
};
|
1227
|
+
|
1228
|
+
Headers.prototype.deleteAll = function deleteAll (){
|
1229
|
+
this.map = {};
|
1230
|
+
};
|
1231
|
+
|
1232
|
+
Headers.prototype.forEach = function forEach (callback, thisArg) {
|
1233
|
+
var this$1 = this;
|
1234
|
+
|
1235
|
+
each(this.map, function (list, name) {
|
1236
|
+
each(list, function (value) { return callback.call(thisArg, value, name, this$1); });
|
1237
|
+
});
|
1238
|
+
};
|
1239
|
+
|
1240
|
+
function getName(map, name) {
|
1241
|
+
return Object.keys(map).reduce(function (prev, curr) {
|
1242
|
+
return toLower(name) === toLower(curr) ? curr : prev;
|
1243
|
+
}, null);
|
1244
|
+
}
|
1245
|
+
|
1246
|
+
function normalizeName(name) {
|
1247
|
+
|
1248
|
+
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
|
1249
|
+
throw new TypeError('Invalid character in header field name');
|
1250
|
+
}
|
1251
|
+
|
1252
|
+
return trim(name);
|
1253
|
+
}
|
1254
|
+
|
1255
|
+
/**
|
1256
|
+
* HTTP Response.
|
1257
|
+
*/
|
1258
|
+
|
1259
|
+
var Response = function Response(body, ref) {
|
1260
|
+
var url = ref.url;
|
1261
|
+
var headers = ref.headers;
|
1262
|
+
var status = ref.status;
|
1263
|
+
var statusText = ref.statusText;
|
1264
|
+
|
1265
|
+
|
1266
|
+
this.url = url;
|
1267
|
+
this.ok = status >= 200 && status < 300;
|
1268
|
+
this.status = status || 0;
|
1269
|
+
this.statusText = statusText || '';
|
1270
|
+
this.headers = new Headers(headers);
|
1271
|
+
this.body = body;
|
1272
|
+
|
1273
|
+
if (isString(body)) {
|
1274
|
+
|
1275
|
+
this.bodyText = body;
|
1276
|
+
|
1277
|
+
} else if (isBlob(body)) {
|
1278
|
+
|
1279
|
+
this.bodyBlob = body;
|
1280
|
+
|
1281
|
+
if (isBlobText(body)) {
|
1282
|
+
this.bodyText = blobText(body);
|
1283
|
+
}
|
1284
|
+
}
|
1285
|
+
};
|
1286
|
+
|
1287
|
+
Response.prototype.blob = function blob () {
|
1288
|
+
return when(this.bodyBlob);
|
1289
|
+
};
|
1290
|
+
|
1291
|
+
Response.prototype.text = function text () {
|
1292
|
+
return when(this.bodyText);
|
1293
|
+
};
|
1294
|
+
|
1295
|
+
Response.prototype.json = function json () {
|
1296
|
+
return when(this.text(), function (text) { return JSON.parse(text); });
|
1297
|
+
};
|
1298
|
+
|
1299
|
+
function blobText(body) {
|
1300
|
+
return new PromiseObj(function (resolve) {
|
1301
|
+
|
1302
|
+
var reader = new FileReader();
|
1303
|
+
|
1304
|
+
reader.readAsText(body);
|
1305
|
+
reader.onload = function () {
|
1306
|
+
resolve(reader.result);
|
1307
|
+
};
|
1308
|
+
|
1309
|
+
});
|
1310
|
+
}
|
1311
|
+
|
1312
|
+
function isBlobText(body) {
|
1313
|
+
return body.type.indexOf('text') === 0 || body.type.indexOf('json') !== -1;
|
1314
|
+
}
|
1315
|
+
|
1316
|
+
/**
|
1317
|
+
* HTTP Request.
|
1318
|
+
*/
|
1319
|
+
|
1320
|
+
var Request = function Request(options$$1) {
|
1321
|
+
|
1322
|
+
this.body = null;
|
1323
|
+
this.params = {};
|
1324
|
+
|
1325
|
+
assign(this, options$$1, {
|
1326
|
+
method: toUpper(options$$1.method || 'GET')
|
1327
|
+
});
|
1328
|
+
|
1329
|
+
if (!(this.headers instanceof Headers)) {
|
1330
|
+
this.headers = new Headers(this.headers);
|
1331
|
+
}
|
1332
|
+
};
|
1333
|
+
|
1334
|
+
Request.prototype.getUrl = function getUrl (){
|
1335
|
+
return Url(this);
|
1336
|
+
};
|
1337
|
+
|
1338
|
+
Request.prototype.getBody = function getBody (){
|
1339
|
+
return this.body;
|
1340
|
+
};
|
1341
|
+
|
1342
|
+
Request.prototype.respondWith = function respondWith (body, options$$1) {
|
1343
|
+
return new Response(body, assign(options$$1 || {}, {url: this.getUrl()}));
|
1344
|
+
};
|
1345
|
+
|
1346
|
+
/**
|
1347
|
+
* Service for sending network requests.
|
1348
|
+
*/
|
1349
|
+
|
1350
|
+
var COMMON_HEADERS = {'Accept': 'application/json, text/plain, */*'};
|
1351
|
+
var JSON_CONTENT_TYPE = {'Content-Type': 'application/json;charset=utf-8'};
|
1352
|
+
|
1353
|
+
function Http(options$$1) {
|
1354
|
+
|
1355
|
+
var self = this || {}, client = Client(self.$vm);
|
1356
|
+
|
1357
|
+
defaults(options$$1 || {}, self.$options, Http.options);
|
1358
|
+
|
1359
|
+
Http.interceptors.forEach(function (handler) {
|
1360
|
+
client.use(handler);
|
1361
|
+
});
|
1362
|
+
|
1363
|
+
return client(new Request(options$$1)).then(function (response) {
|
1364
|
+
|
1365
|
+
return response.ok ? response : PromiseObj.reject(response);
|
1366
|
+
|
1367
|
+
}, function (response) {
|
1368
|
+
|
1369
|
+
if (response instanceof Error) {
|
1370
|
+
error(response);
|
1371
|
+
}
|
1372
|
+
|
1373
|
+
return PromiseObj.reject(response);
|
1374
|
+
});
|
1375
|
+
}
|
1376
|
+
|
1377
|
+
Http.options = {};
|
1378
|
+
|
1379
|
+
Http.headers = {
|
1380
|
+
put: JSON_CONTENT_TYPE,
|
1381
|
+
post: JSON_CONTENT_TYPE,
|
1382
|
+
patch: JSON_CONTENT_TYPE,
|
1383
|
+
delete: JSON_CONTENT_TYPE,
|
1384
|
+
common: COMMON_HEADERS,
|
1385
|
+
custom: {}
|
1386
|
+
};
|
1387
|
+
|
1388
|
+
Http.interceptors = [before, method, body, jsonp, header, cors];
|
1389
|
+
|
1390
|
+
['get', 'delete', 'head', 'jsonp'].forEach(function (method$$1) {
|
1391
|
+
|
1392
|
+
Http[method$$1] = function (url, options$$1) {
|
1393
|
+
return this(assign(options$$1 || {}, {url: url, method: method$$1}));
|
1394
|
+
};
|
1395
|
+
|
1396
|
+
});
|
1397
|
+
|
1398
|
+
['post', 'put', 'patch'].forEach(function (method$$1) {
|
1399
|
+
|
1400
|
+
Http[method$$1] = function (url, body$$1, options$$1) {
|
1401
|
+
return this(assign(options$$1 || {}, {url: url, method: method$$1, body: body$$1}));
|
1402
|
+
};
|
1403
|
+
|
1404
|
+
});
|
1405
|
+
|
1406
|
+
/**
|
1407
|
+
* Service for interacting with RESTful services.
|
1408
|
+
*/
|
1409
|
+
|
1410
|
+
function Resource(url, params, actions, options$$1) {
|
1411
|
+
|
1412
|
+
var self = this || {}, resource = {};
|
1413
|
+
|
1414
|
+
actions = assign({},
|
1415
|
+
Resource.actions,
|
1416
|
+
actions
|
1417
|
+
);
|
1418
|
+
|
1419
|
+
each(actions, function (action, name) {
|
1420
|
+
|
1421
|
+
action = merge({url: url, params: assign({}, params)}, options$$1, action);
|
1422
|
+
|
1423
|
+
resource[name] = function () {
|
1424
|
+
return (self.$http || Http)(opts(action, arguments));
|
1425
|
+
};
|
1426
|
+
});
|
1427
|
+
|
1428
|
+
return resource;
|
1429
|
+
}
|
1430
|
+
|
1431
|
+
function opts(action, args) {
|
1432
|
+
|
1433
|
+
var options$$1 = assign({}, action), params = {}, body;
|
1434
|
+
|
1435
|
+
switch (args.length) {
|
1436
|
+
|
1437
|
+
case 2:
|
1438
|
+
|
1439
|
+
params = args[0];
|
1440
|
+
body = args[1];
|
1441
|
+
|
1442
|
+
break;
|
1443
|
+
|
1444
|
+
case 1:
|
1445
|
+
|
1446
|
+
if (/^(POST|PUT|PATCH)$/i.test(options$$1.method)) {
|
1447
|
+
body = args[0];
|
1448
|
+
} else {
|
1449
|
+
params = args[0];
|
1450
|
+
}
|
1451
|
+
|
1452
|
+
break;
|
1453
|
+
|
1454
|
+
case 0:
|
1455
|
+
|
1456
|
+
break;
|
1457
|
+
|
1458
|
+
default:
|
1459
|
+
|
1460
|
+
throw 'Expected up to 2 arguments [params, body], got ' + args.length + ' arguments';
|
1461
|
+
}
|
1462
|
+
|
1463
|
+
options$$1.body = body;
|
1464
|
+
options$$1.params = assign({}, options$$1.params, params);
|
1465
|
+
|
1466
|
+
return options$$1;
|
1467
|
+
}
|
1468
|
+
|
1469
|
+
Resource.actions = {
|
1470
|
+
|
1471
|
+
get: {method: 'GET'},
|
1472
|
+
save: {method: 'POST'},
|
1473
|
+
query: {method: 'GET'},
|
1474
|
+
update: {method: 'PUT'},
|
1475
|
+
remove: {method: 'DELETE'},
|
1476
|
+
delete: {method: 'DELETE'}
|
1477
|
+
|
1478
|
+
};
|
1479
|
+
|
1480
|
+
/**
|
1481
|
+
* Install plugin.
|
1482
|
+
*/
|
1483
|
+
|
1484
|
+
function plugin(Vue) {
|
1485
|
+
|
1486
|
+
if (plugin.installed) {
|
1487
|
+
return;
|
1488
|
+
}
|
1489
|
+
|
1490
|
+
Util(Vue);
|
1491
|
+
|
1492
|
+
Vue.url = Url;
|
1493
|
+
Vue.http = Http;
|
1494
|
+
Vue.resource = Resource;
|
1495
|
+
Vue.Promise = PromiseObj;
|
1496
|
+
|
1497
|
+
Object.defineProperties(Vue.prototype, {
|
1498
|
+
|
1499
|
+
$url: {
|
1500
|
+
get: function get() {
|
1501
|
+
return options(Vue.url, this, this.$options.url);
|
1502
|
+
}
|
1503
|
+
},
|
1504
|
+
|
1505
|
+
$http: {
|
1506
|
+
get: function get() {
|
1507
|
+
return options(Vue.http, this, this.$options.http);
|
1508
|
+
}
|
1509
|
+
},
|
1510
|
+
|
1511
|
+
$resource: {
|
1512
|
+
get: function get() {
|
1513
|
+
return Vue.resource.bind(this);
|
1514
|
+
}
|
1515
|
+
},
|
1516
|
+
|
1517
|
+
$promise: {
|
1518
|
+
get: function get() {
|
1519
|
+
var this$1 = this;
|
1520
|
+
|
1521
|
+
return function (executor) { return new Vue.Promise(executor, this$1); };
|
1522
|
+
}
|
1523
|
+
}
|
1524
|
+
|
1525
|
+
});
|
1526
|
+
}
|
1527
|
+
|
1528
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
1529
|
+
window.Vue.use(plugin);
|
1530
|
+
}
|
1531
|
+
|
1532
|
+
return plugin;
|
1533
|
+
|
1534
|
+
})));
|