mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
(function (tree) {
|
|
|
|
tree.Quoted = function (str, content, escaped, index, currentFileInfo) {
|
|
this.escaped = escaped;
|
|
this.value = content || '';
|
|
this.quote = str.charAt(0);
|
|
this.index = index;
|
|
this.currentFileInfo = currentFileInfo;
|
|
};
|
|
tree.Quoted.prototype = {
|
|
type: "Quoted",
|
|
toCSS: function () {
|
|
if (this.escaped) {
|
|
return this.value;
|
|
} else {
|
|
return this.quote + this.value + this.quote;
|
|
}
|
|
},
|
|
eval: function (env) {
|
|
var that = this;
|
|
var value = this.value.replace(/`([^`]+)`/g, function (_, exp) {
|
|
return new(tree.JavaScript)(exp, that.index, true).eval(env).value;
|
|
}).replace(/@\{([\w-]+)\}/g, function (_, name) {
|
|
var v = new(tree.Variable)('@' + name, that.index, that.currentFileInfo).eval(env, true);
|
|
return (v instanceof tree.Quoted) ? v.value : v.toCSS();
|
|
});
|
|
return new(tree.Quoted)(this.quote + value + this.quote, value, this.escaped, this.index);
|
|
},
|
|
compare: function (x) {
|
|
if (!x.toCSS) {
|
|
return -1;
|
|
}
|
|
|
|
var left = this.toCSS(),
|
|
right = x.toCSS();
|
|
|
|
if (left === right) {
|
|
return 0;
|
|
}
|
|
|
|
return left < right ? -1 : 1;
|
|
}
|
|
};
|
|
|
|
})(require('../tree'));
|