-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathInclude.gs
57 lines (50 loc) · 2.02 KB
/
Include.gs
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
/**
*used to include code in htmloutput
*@nameSpace Include
*/
var Include = (function (ns) {
/**
* given an array of .gs file names, it will get the source and return them concatenated for insertion into htmlservice
* like this you can share the same code between client and server side, and use the Apps Script IDE to manage your js code
* @param {string[]} scripts the names of all the scripts needed
* @return {string} the code inside script tags
*/
ns.gs = function (scripts) {
return '<script>\n' + scripts.map (function (d) {
// getResource returns a blob
return ScriptApp.getResource(d).getDataAsString();
})
.join('\n\n') + '</script>\n';
};
/**
* given an array of .html file names, it will get the source and return them concatenated for insertion into htmlservice
* @param {string[]} scripts the names of all the scripts needed
* @param {string} ext file extendion
* @return {string} the code inside script tags
*/
ns.html = function (scripts, ext) {
return scripts.map (function (d) {
return HtmlService.createHtmlOutputFromFile(d+(ext||'')).getContent();
})
.join('\n\n');
};
/**
* given an array of .html file names, it will get the source and return them concatenated for insertion into htmlservice
* inserts css style
* @param {string[]} scripts the names of all the scripts needed
* @return {string} the code inside script tags
*/
ns.js = function (scripts) {
return '<script>\n' + ns.html(scripts,'.js') + '</script>\n';
};
/**
* given an array of .html file names, it will get the source and return them concatenated for insertion into htmlservice
* like this you can share the same code between client and server side, and use the Apps Script IDE to manage your js code
* @param {string[]} scripts the names of all the scripts needed
* @return {string} the code inside script tags
*/
ns.css = function (scripts) {
return '<style>\n' + ns.html(scripts,'.css') + '</style>\n';
};
return ns;
})(Include || {});