forked from maksrom/javascript-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.js
More file actions
executable file
·37 lines (31 loc) · 1.38 KB
/
parser.js
File metadata and controls
executable file
·37 lines (31 loc) · 1.38 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
var _ = require('lodash');
var CompositeTag = require('../node/compositeTag');
var TextNode = require('../node/textNode');
// Обычно при создании парсера опции создаются как sub_opts, чтобы передать текущие опции, расширив их
// Произвольный парсер имеет опции
// :trusted - доверенный режим или обычный юзер
function Parser(options) {
options = options || {};
this.validateOptions(options);
this.options = options;
this.resourceWebRoot = options.resourceWebRoot;
this.staticHost = options.staticHost;
this.trusted = options.trusted;
}
// Проверить наличие нужных опций
//
// Каждый парсер переопределит это, как считает нужным
// Как правило, в переопределённом методе не нужно вызывать super,
// Так будет понятно, что именно нужно парсеру
Parser.prototype.validateOptions = function(options) {
// throw if something's wrong
};
Parser.prototype.parse = function() {
throw new Error("Not implemented");
};
Parser.prototype.parseAndWrap = function(tag, attrs) {
var result = new CompositeTag(tag, this.parse(), attrs);
result.trusted = this.trusted;
return result;
};
module.exports = Parser;