Repository navigation
Expand file tree
/
Copy pathstaticFile.js
More file actions
63 lines (56 loc) · 1.52 KB
/
Copy pathstaticFile.js
File metadata and controls
63 lines (56 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*jslint node: true, regexp: true */
var staticfile = (function (hashes, prefix) {
'use strict';
/**
* @param {String} filename Filename to affix
* @return {String} Affixed filename
*/
function staticfile(filename, hash) {
return prefix + (
(hash = hashes[filename]) ?
staticfile.affix(filename, hash) :
filename
);
}
/**
* @param {String} prefix String to prefix hashed filenames with.
* @return {Object} this
*/
staticfile.prefix = function (str) {
prefix = str;
return this;
};
/**
* @param {String} filename Path to file
* @param {String} hash Hash to affix into filename
* @return {String} Affixed filename
*/
staticfile.affix = function (filename, hash, path, match) {
path = '';
if ((match = filename.match(/(^.*\/)([^\/]+$)/))) {
path = match[1];
filename = match[2];
}
match = filename.match(/(^[^\.]*)(.*$)/);
return path + match[1] + '_' + hash + match[2];
};
/**
* @param {Object} obj Map of filenames to hashes
* @return {Object} this
*/
staticfile.add = function (obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
hashes[key] = obj[key];
}
}
return this;
};
/**
* @return {Object} hashes
*/
staticfile.hashes = function () {
return hashes;
};
return staticfile;
}({}, ''));