Skip to content

Commit

Permalink
Merge pull request #340 from annarieger/leaveasurl-check
Browse files Browse the repository at this point in the history
Add optional parameter leaveAsUrl to resolveAttributeTemplate method
  • Loading branch information
annarieger committed Dec 4, 2020
2 parents 4c8a4c4 + f70d7af commit 005326f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/FeatureUtil/FeatureUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ class FeatureUtil {
* value it received. This can be used for last minute adjustments before
* replacing happens, e.g. to filter out falsy values or to do number
* formatting and such.
* @param {boolean} leaveAsUrl If set to true, template won't be wrapped into
* <a>-tag and will be returned as URL. Default is false.
* @return {string} The resolved template string.
*/
static resolveAttributeTemplate(feature, template, noValueFoundText = 'n.v.', valueAdjust = (key, val) => val) {
static resolveAttributeTemplate(feature, template, noValueFoundText = 'n.v.',
valueAdjust = (key, val) => val, leaveAsUrl = false) {
let attributeTemplatePrefix = '\\{\\{';
let attributeTemplateSuffix = '\\}\\}';
let resolved = '';
Expand Down Expand Up @@ -116,11 +119,13 @@ class FeatureUtil {
resolved = feature.getId();
}

// Replace any HTTP url with an <a> element.
resolved = StringUtil.urlify(resolved);
if (!leaveAsUrl) {
// Replace any HTTP url with an <a> element.
resolved = StringUtil.urlify(resolved);

// Replace all newline breaks with a html <br> tag.
resolved = resolved.replace(/\n/g, '<br>');
// Replace all newline breaks with a html <br> tag.
resolved = resolved.replace(/\n/g, '<br>');
}

return resolved;
}
Expand Down

0 comments on commit 005326f

Please sign in to comment.