From: Mike Taylor Date: Fri, 26 Jun 2015 17:25:56 +0000 (+0100) Subject: Part of ACREP-32. X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=4e1cf7acd7be692d8d56bc6941b676ad51a71bfa;p=mkws-moved-to-github.git Part of ACREP-32. Provide new Handlebars helper mkws-best-url, which returns the first item in a list that matches a regular-expression suggesting that it's a URL (basically anything that starts with http://, https:// or //). Also provide mkws-other-urls (not yet tested), which returns all the other URLs in the list except the first. --- diff --git a/src/mkws-handlebars.js b/src/mkws-handlebars.js index 2aaba2c..3e8ee6d 100644 --- a/src/mkws-handlebars.js +++ b/src/mkws-handlebars.js @@ -81,6 +81,31 @@ Handlebars.registerHelper('mkws-first', function(items, options) { }); +var _urlRegexp = /^(https?:)?\/\//; +Handlebars.registerHelper('mkws-best-url', function(items) { + for (var i in items) { + var item = items[i] + if (item.match(_urlRegexp)) { + mkws.warn("'" + item + "' *is* a URL"); + return item; + } + mkws.warn("'" + item + "' is not a URL"); + } + return ""; +}); +Handlebars.registerHelper('mkws-other-urls', function(items) { + var res = []; + for (var i in items) { + var item = items[i] + if (item.match(_urlRegexp)) { + res.push(item); + } + } + return res; +}); + + + Handlebars.registerHelper('mkws-commaList', function(items, options) { var out = "";