var LinkHelper = { url: function(url) { return url.match(/(https?:\/\/[^\s]*)/gi); }, link: function(url) { return '\#{link_name}'.interpolate({ url: url, link_name: url}); }, image_url: function(url) { return url.match(/\.(jpe?g|png|gif)/i); }, image: function(url) { return ''.interpolate({ url: url, image: url }) }, twitpic_url: function(url) { return url.match(/\bhttp:\/\/twitpic.com\/(show|[^\s]*)\b/i); }, twitpic: function(url) { var twitpic_id = url.split('/').last(); return ''.interpolate({ twitpic_id: twitpic_id, url: url }) }, youtube_url: function(url) { return url.match(/youtube\.com/) && url.match(/watch\?v/); }, youtube: function(url) { var youtube_url_id = url.match(/\?v=([^&\s]*)/); if (youtube_url_id && youtube_url_id[1]) { var youtube_url = 'http://www.youtube.com/v/' + youtube_url_id[1]; var youtube_html = ''; return youtube_html.interpolate({ movie_url: youtube_url, url: youtube_url }); } else { return this.link(url); } }, vimeo_url: function(url) { return url.match(/vimeo\.com/) && url.match(/\/\d+/); }, vimeo: function(url) { var vimeo_url_id = url.match(/\d+/); if (vimeo_url_id) { var vimeo_url = 'http://vimeo.com/' + vimeo_url_id; var vimeo_html = ''; return vimeo_html.interpolate({ movie_url: vimeo_url, url: vimeo_url }); } else { return this.link(url); } } };