summaryrefslogtreecommitdiffstats
path: root/js/dav/lib/template/filter.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/dav/lib/template/filter.js')
-rw-r--r--js/dav/lib/template/filter.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/js/dav/lib/template/filter.js b/js/dav/lib/template/filter.js
new file mode 100644
index 00000000..cf2d3b04
--- /dev/null
+++ b/js/dav/lib/template/filter.js
@@ -0,0 +1,20 @@
+export default function filter(item) {
+ if (!item.children || !item.children.length) {
+ return `<c:${item.type} ${formatAttrs(item.attrs)}/>`;
+ }
+
+ let children = item.children.map(filter);
+ return `<c:${item.type} ${formatAttrs(item.attrs)}>
+ ${children}
+ </c:${item.type}>`;
+}
+
+function formatAttrs(attrs) {
+ if (typeof attrs !== 'object') {
+ return '';
+ }
+
+ return Object.keys(attrs)
+ .map(attr => `${attr}="${attrs[attr]}"`)
+ .join(' ');
+}