From 84a2a579359a909b1da7c28c4e95c0bce246f07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Sat, 7 Nov 2015 20:48:40 -0300 Subject: [PATCH] fix \n\n CRLN from API for show in view --- dist/javascripts/bundle.js | 16 +++++++++++----- dist/javascripts/bundle.min.js | 2 +- src/coffeescripts/github-latest-commits.coffee | 6 +++++- src/javascripts/github-latest-commits.js | 16 +++++++++++----- 4 files changed, 28 insertions(+), 12 deletions(-) mode change 100644 => 100755 dist/javascripts/bundle.js mode change 100644 => 100755 dist/javascripts/bundle.min.js diff --git a/dist/javascripts/bundle.js b/dist/javascripts/bundle.js old mode 100644 new mode 100755 index 7478879..0ed1b6e --- a/dist/javascripts/bundle.js +++ b/dist/javascripts/bundle.js @@ -2,6 +2,8 @@ /* Helper to parse query string params */ +var formatMessage; + $.extend({ getUrlVars: function() { var hash, hashes, i, vars; @@ -22,6 +24,10 @@ $.extend({ } }); +formatMessage = function(msg) { + return msg.replace(/\n/g, "
"); +}; + $(function() { var branch, callback, container, limit, params, repo, url, username; params = $.getUrlVars(); @@ -31,20 +37,20 @@ $(function() { branch = params.branch; container = $('#latest-commits-widget'); callback = function(response) { - var index, items, result, ul, _results; + var index, items, result, results, ul; items = response.data; ul = $('#commit-history'); ul.empty(); - _results = []; + results = []; for (index in items) { result = items[index]; - _results.push((function(index, result) { + results.push((function(index, result) { if (result.author != null) { - return ul.append("
  • \n
    \n \n
    \n
    \n " + result.author.login + "\n
    \n " + ($.timeago(result.commit.committer.date)) + "
    SHA: " + result.sha + "\n
    \n " + result.commit.message + "\n
    \n
  • "); + return ul.append("
  • \n
    \n \n
    \n
    \n " + result.author.login + "\n
    \n " + ($.timeago(result.commit.committer.date)) + "
    SHA: " + result.sha + "\n
    \n " + (formatMessage(result.commit.message)) + "\n
    \n
  • "); } })(index, result)); } - return _results; + return results; }; container.find('h4').text("Latest Commits to " + username + "/" + repo); url = "https://api.github.com/repos/" + username + "/" + repo + "/commits?callback=callback"; diff --git a/dist/javascripts/bundle.min.js b/dist/javascripts/bundle.min.js old mode 100644 new mode 100755 index fc3e240..40a7629 --- a/dist/javascripts/bundle.min.js +++ b/dist/javascripts/bundle.min.js @@ -1 +1 @@ -$.extend({getUrlVars:function(){var t,e,a,r;for(r=[],t=void 0,e=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),a=0;a\n
    \n \n
    \n
    \n '+e.author.login+'\n
    \n '+$.timeago(e.commit.committer.date)+'
    SHA: '+e.sha+'\n
    \n '+e.commit.message+"\n
    \n"):void 0}(e,r));return o},a.find("h4").text("Latest Commits to "+s+"/"+i),o="https://api.github.com/repos/"+s+"/"+i+"/commits?callback=callback",null!=n.branch&&(o+="&sha="+t),$.ajax(o,{data:{per_page:r},dataType:"jsonp",type:"get"}).success(function(t){return e(t)})}),function(t){function e(){var e=a(this);return isNaN(e.datetime)||t(this).text(r(e.datetime)),this}function a(e){if(e=t(e),!e.data("timeago")){e.data("timeago",{datetime:i.datetime(e)});var a=t.trim(e.text());a.length>0&&e.attr("title",a)}return e.data("timeago")}function r(t){return i.inWords(n(t))}function n(t){return(new Date).getTime()-t.getTime()}t.timeago=function(e){return r(e instanceof Date?e:"string"==typeof e?t.timeago.parse(e):t.timeago.datetime(e))};var i=t.timeago;t.extend(t.timeago,{settings:{refreshMillis:6e4,allowFuture:!1,strings:{prefixAgo:null,prefixFromNow:null,suffixAgo:"ago",suffixFromNow:"from now",seconds:"less than a minute",minute:"about a minute",minutes:"%d minutes",hour:"about an hour",hours:"about %d hours",day:"a day",days:"%d days",month:"about a month",months:"%d months",year:"about a year",years:"%d years",wordSeparator:" ",numbers:[]}},inWords:function(e){function a(a,n){var i=t.isFunction(a)?a(n,e):a,o=r.numbers&&r.numbers[n]||n;return i.replace(/%d/i,o)}var r=this.settings.strings,n=r.prefixAgo,i=r.suffixAgo;this.settings.allowFuture&&0>e&&(n=r.prefixFromNow,i=r.suffixFromNow);var o=Math.abs(e)/1e3,s=o/60,u=s/60,m=u/24,c=m/365,l=45>o&&a(r.seconds,Math.round(o))||90>o&&a(r.minute,1)||45>s&&a(r.minutes,Math.round(s))||90>s&&a(r.hour,1)||24>u&&a(r.hours,Math.round(u))||42>u&&a(r.day,1)||30>m&&a(r.days,Math.round(m))||45>m&&a(r.month,1)||365>m&&a(r.months,Math.round(m/30))||1.5>c&&a(r.year,1)||a(r.years,Math.round(c)),d=void 0===r.wordSeparator?" ":r.wordSeparator;return t.trim([n,l,i].join(d))},parse:function(e){var a=t.trim(e);return a=a.replace(/\.\d\d\d+/,""),a=a.replace(/-/,"/").replace(/-/,"/"),a=a.replace(/T/," ").replace(/Z/," UTC"),a=a.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"),new Date(a)},datetime:function(e){var a="time"===t(e).get(0).tagName.toLowerCase(),r=t(e).attr(a?"datetime":"title");return i.parse(r)}}),t.fn.timeago=function(){var t=this;t.each(e);var a=i.settings;return a.refreshMillis>0&&setInterval(function(){t.each(e)},a.refreshMillis),t},document.createElement("abbr"),document.createElement("time")}(jQuery); \ No newline at end of file +var formatMessage;$.extend({getUrlVars:function(){var t,e,a,r;for(r=[],t=void 0,e=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),a=0;a")},$(function(){var t,e,a,r,n,i,o,s;return n=$.getUrlVars(),s=n.username,i=n.repo,r=n.limit,t=n.branch,a=$("#latest-commits-widget"),e=function(t){var e,a,r,n,o;a=t.data,o=$("#commit-history"),o.empty(),n=[];for(e in a)r=a[e],n.push(function(t,e){return null!=e.author?o.append('
  • \n
    \n \n
    \n
    \n '+e.author.login+'\n
    \n '+$.timeago(e.commit.committer.date)+'
    SHA: '+e.sha+'\n
    \n '+formatMessage(e.commit.message)+"\n
    \n
  • "):void 0}(e,r));return n},a.find("h4").text("Latest Commits to "+s+"/"+i),o="https://api.github.com/repos/"+s+"/"+i+"/commits?callback=callback",null!=n.branch&&(o+="&sha="+t),$.ajax(o,{data:{per_page:r},dataType:"jsonp",type:"get"}).success(function(t){return e(t)})}),function(t){function e(){var e=a(this);return isNaN(e.datetime)||t(this).text(r(e.datetime)),this}function a(e){if(e=t(e),!e.data("timeago")){e.data("timeago",{datetime:i.datetime(e)});var a=t.trim(e.text());a.length>0&&e.attr("title",a)}return e.data("timeago")}function r(t){return i.inWords(n(t))}function n(t){return(new Date).getTime()-t.getTime()}t.timeago=function(e){return r(e instanceof Date?e:"string"==typeof e?t.timeago.parse(e):t.timeago.datetime(e))};var i=t.timeago;t.extend(t.timeago,{settings:{refreshMillis:6e4,allowFuture:!1,strings:{prefixAgo:null,prefixFromNow:null,suffixAgo:"ago",suffixFromNow:"from now",seconds:"less than a minute",minute:"about a minute",minutes:"%d minutes",hour:"about an hour",hours:"about %d hours",day:"a day",days:"%d days",month:"about a month",months:"%d months",year:"about a year",years:"%d years",wordSeparator:" ",numbers:[]}},inWords:function(e){function a(a,n){var i=t.isFunction(a)?a(n,e):a,o=r.numbers&&r.numbers[n]||n;return i.replace(/%d/i,o)}var r=this.settings.strings,n=r.prefixAgo,i=r.suffixAgo;this.settings.allowFuture&&0>e&&(n=r.prefixFromNow,i=r.suffixFromNow);var o=Math.abs(e)/1e3,s=o/60,u=s/60,m=u/24,c=m/365,l=45>o&&a(r.seconds,Math.round(o))||90>o&&a(r.minute,1)||45>s&&a(r.minutes,Math.round(s))||90>s&&a(r.hour,1)||24>u&&a(r.hours,Math.round(u))||42>u&&a(r.day,1)||30>m&&a(r.days,Math.round(m))||45>m&&a(r.month,1)||365>m&&a(r.months,Math.round(m/30))||1.5>c&&a(r.year,1)||a(r.years,Math.round(c)),d=void 0===r.wordSeparator?" ":r.wordSeparator;return t.trim([n,l,i].join(d))},parse:function(e){var a=t.trim(e);return a=a.replace(/\.\d\d\d+/,""),a=a.replace(/-/,"/").replace(/-/,"/"),a=a.replace(/T/," ").replace(/Z/," UTC"),a=a.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"),new Date(a)},datetime:function(e){var a="time"===t(e).get(0).tagName.toLowerCase(),r=a?t(e).attr("datetime"):t(e).attr("title");return i.parse(r)}}),t.fn.timeago=function(){var t=this;t.each(e);var a=i.settings;return a.refreshMillis>0&&setInterval(function(){t.each(e)},a.refreshMillis),t},document.createElement("abbr"),document.createElement("time")}(jQuery); \ No newline at end of file diff --git a/src/coffeescripts/github-latest-commits.coffee b/src/coffeescripts/github-latest-commits.coffee index b149dc1..9e20d11 100755 --- a/src/coffeescripts/github-latest-commits.coffee +++ b/src/coffeescripts/github-latest-commits.coffee @@ -18,6 +18,9 @@ $.extend getUrlVar: (name) -> $.getUrlVars()[name] +formatMessage = (msg) -> + msg.replace(/\n/g, "
    "); + $ -> params = $.getUrlVars() # config parameters @@ -44,7 +47,7 @@ $ ->
    #{$.timeago(result.commit.committer.date)}
    SHA: #{result.sha}
    - #{result.commit.message} + #{formatMessage(result.commit.message)} """) @@ -63,3 +66,4 @@ $ -> type: "get" ).success (response) -> callback(response) + diff --git a/src/javascripts/github-latest-commits.js b/src/javascripts/github-latest-commits.js index b48e7e7..0bcff4b 100755 --- a/src/javascripts/github-latest-commits.js +++ b/src/javascripts/github-latest-commits.js @@ -2,6 +2,8 @@ /* Helper to parse query string params */ +var formatMessage; + $.extend({ getUrlVars: function() { var hash, hashes, i, vars; @@ -22,6 +24,10 @@ $.extend({ } }); +formatMessage = function(msg) { + return msg.replace(/\n/g, "
    "); +}; + $(function() { var branch, callback, container, limit, params, repo, url, username; params = $.getUrlVars(); @@ -31,20 +37,20 @@ $(function() { branch = params.branch; container = $('#latest-commits-widget'); callback = function(response) { - var index, items, result, ul, _results; + var index, items, result, results, ul; items = response.data; ul = $('#commit-history'); ul.empty(); - _results = []; + results = []; for (index in items) { result = items[index]; - _results.push((function(index, result) { + results.push((function(index, result) { if (result.author != null) { - return ul.append("
  • \n
    \n \n
    \n
    \n " + result.author.login + "\n
    \n " + ($.timeago(result.commit.committer.date)) + "
    SHA: " + result.sha + "\n
    \n " + result.commit.message + "\n
    \n
  • "); + return ul.append("
  • \n
    \n \n
    \n
    \n " + result.author.login + "\n
    \n " + ($.timeago(result.commit.committer.date)) + "
    SHA: " + result.sha + "\n
    \n " + (formatMessage(result.commit.message)) + "\n
    \n
  • "); } })(index, result)); } - return _results; + return results; }; container.find('h4').text("Latest Commits to " + username + "/" + repo); url = "https://api.github.com/repos/" + username + "/" + repo + "/commits?callback=callback";