-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
83 lines (73 loc) · 2.65 KB
/
index.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var fs = require('fs');
var Q = require('q');
var htmlencode = require('htmlencode');
var path = require('path');
var editorLoad = require('./assets/editorLoad');
var _counter = 1;
var _currentPage;
module.exports = {
website: {
assets: "./assets",
js: [
"http://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js",
"https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js",
"editor.js"
],
css: [
'editor.css'
]
},
hooks: {
"page:before": function (page) {
_currentPage = page;
return page;
}
},
blocks: {
codeeditor: {
process: function (block) {
if (this.generator === 'website') {
var id = _counter++;
var config = block.kwargs;
var height = config.height || '300px';
var settings = {
readOnly: config.readOnly || false,
mode: config.language || 'html',
theme: config.theme || 'chrome',
maxLines: config.maxLines || 25
};
var options = {};
options.css = "";
options.js = "";
options.editorSettings = settings;
options.height = height;
options.id = id;
options.initTab = config.initTab || 'html';
options.singleTab = config.singleTab || false;
if (options.singleTab) {
options.initTab = options.singleTab;
}
if (config.src) {
// Read the file
var fullPath = path.resolve(path.dirname(_currentPage.rawPath), config.src);
return Q.nfcall(fs.readFile, fullPath, "utf-8")
.then(function (data) {
data = htmlencode.htmlEncode(data).replace(/ /g, ' ');
options.html = data;
return editorLoad.load(options);
});
}
else{
//var body = htmlencode.htmlEncode(block.body).replace(/ /g, ' ');
return '';
//options.html = body;
//return editorLoad.load(options);
}
}
else {
return '';
}
}
}
}
};