2018-10-23 23:45:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-05-17 21:00:18 +08:00
|
|
|
var SUBSTITUTION_TOKENS = {
|
|
|
|
bbox: /!bbox!/g,
|
|
|
|
scale_denominator: /!scale_denominator!/g,
|
|
|
|
pixel_width: /!pixel_width!/g,
|
|
|
|
pixel_height: /!pixel_height!/g
|
|
|
|
};
|
|
|
|
|
|
|
|
var SubstitutionTokens = {
|
2019-10-22 01:07:24 +08:00
|
|
|
tokens: function (sql) {
|
|
|
|
return Object.keys(SUBSTITUTION_TOKENS).filter(function (tokenName) {
|
2016-05-19 18:10:19 +08:00
|
|
|
return !!sql.match(SUBSTITUTION_TOKENS[tokenName]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
hasTokens: function (sql) {
|
2016-05-19 18:10:19 +08:00
|
|
|
return this.tokens(sql).length > 0;
|
|
|
|
},
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
replace: function (sql, replaceValues) {
|
|
|
|
Object.keys(replaceValues).forEach(function (token) {
|
2016-05-17 21:00:18 +08:00
|
|
|
if (SUBSTITUTION_TOKENS[token]) {
|
|
|
|
sql = sql.replace(SUBSTITUTION_TOKENS[token], replaceValues[token]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return sql;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SubstitutionTokens;
|