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 = {
|
2016-05-19 18:10:19 +08:00
|
|
|
tokens: function(sql) {
|
|
|
|
return Object.keys(SUBSTITUTION_TOKENS).filter(function(tokenName) {
|
|
|
|
return !!sql.match(SUBSTITUTION_TOKENS[tokenName]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
hasTokens: function(sql) {
|
|
|
|
return this.tokens(sql).length > 0;
|
|
|
|
},
|
|
|
|
|
2016-05-17 21:00:18 +08:00
|
|
|
replace: function(sql, replaceValues) {
|
|
|
|
Object.keys(replaceValues).forEach(function(token) {
|
|
|
|
if (SUBSTITUTION_TOKENS[token]) {
|
|
|
|
sql = sql.replace(SUBSTITUTION_TOKENS[token], replaceValues[token]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return sql;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SubstitutionTokens;
|