Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional parameter leaveAsUrl to resolveAttributeTemplate method #340

Merged
merged 1 commit into from
Dec 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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