Skip to content

Commit 84a2a57

Browse files
committed
fix \n\n CRLN from API for show in view
1 parent 1fcd3ad commit 84a2a57

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

dist/javascripts/bundle.js

100644100755
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/*
33
Helper to parse query string params
44
*/
5+
var formatMessage;
6+
57
$.extend({
68
getUrlVars: function() {
79
var hash, hashes, i, vars;
@@ -22,6 +24,10 @@ $.extend({
2224
}
2325
});
2426

27+
formatMessage = function(msg) {
28+
return msg.replace(/\n/g, "<br />");
29+
};
30+
2531
$(function() {
2632
var branch, callback, container, limit, params, repo, url, username;
2733
params = $.getUrlVars();
@@ -31,20 +37,20 @@ $(function() {
3137
branch = params.branch;
3238
container = $('#latest-commits-widget');
3339
callback = function(response) {
34-
var index, items, result, ul, _results;
40+
var index, items, result, results, ul;
3541
items = response.data;
3642
ul = $('#commit-history');
3743
ul.empty();
38-
_results = [];
44+
results = [];
3945
for (index in items) {
4046
result = items[index];
41-
_results.push((function(index, result) {
47+
results.push((function(index, result) {
4248
if (result.author != null) {
43-
return ul.append("<li class=\"clearfix\">\n <div class=\"left\">\n <img class=\"commit-avatar\" src=\"" + result.author.avatar_url + "\">\n </div>\n <div class=\"commit-author-info left\">\n <a href=\"https://github.com/" + result.author.login + "\"><b class=\"commit-author\">" + result.author.login + "</b></a>\n <br />\n <b class=\"commit-date\">" + ($.timeago(result.commit.committer.date)) + "</b><br /><i class=\"commit-sha\">SHA: " + result.sha + "</i>\n <br />\n <a class=\"commit-message\" href=\"https://github.com/" + username + "/" + repo + "/commit/" + result.sha + "\" target=\"_blank\">" + result.commit.message + "</a>\n </div>\n</li>");
49+
return ul.append("<li class=\"clearfix\">\n <div class=\"left\">\n <img class=\"commit-avatar\" src=\"" + result.author.avatar_url + "\">\n </div>\n <div class=\"commit-author-info left\">\n <a href=\"https://github.com/" + result.author.login + "\"><b class=\"commit-author\">" + result.author.login + "</b></a>\n <br />\n <b class=\"commit-date\">" + ($.timeago(result.commit.committer.date)) + "</b><br /><i class=\"commit-sha\">SHA: " + result.sha + "</i>\n <br />\n <a class=\"commit-message\" href=\"https://github.com/" + username + "/" + repo + "/commit/" + result.sha + "\" target=\"_blank\">" + (formatMessage(result.commit.message)) + "</a>\n </div>\n</li>");
4450
}
4551
})(index, result));
4652
}
47-
return _results;
53+
return results;
4854
};
4955
container.find('h4').text("Latest Commits to " + username + "/" + repo);
5056
url = "https://api.github.com/repos/" + username + "/" + repo + "/commits?callback=callback";

dist/javascripts/bundle.min.js

100644100755
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/coffeescripts/github-latest-commits.coffee

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ $.extend
1818
getUrlVar: (name) ->
1919
$.getUrlVars()[name]
2020

21+
formatMessage = (msg) ->
22+
msg.replace(/\n/g, "<br />");
23+
2124
$ ->
2225
params = $.getUrlVars()
2326
# config parameters
@@ -44,7 +47,7 @@ $ ->
4447
<br />
4548
<b class="commit-date">#{$.timeago(result.commit.committer.date)}</b><br /><i class="commit-sha">SHA: #{result.sha}</i>
4649
<br />
47-
<a class="commit-message" href="https://github.com/#{username}/#{repo}/commit/#{result.sha}" target="_blank">#{result.commit.message}</a>
50+
<a class="commit-message" href="https://github.com/#{username}/#{repo}/commit/#{result.sha}" target="_blank">#{formatMessage(result.commit.message)}</a>
4851
</div>
4952
</li>
5053
""")
@@ -63,3 +66,4 @@ $ ->
6366
type: "get"
6467
).success (response) ->
6568
callback(response)
69+

src/javascripts/github-latest-commits.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/*
33
Helper to parse query string params
44
*/
5+
var formatMessage;
6+
57
$.extend({
68
getUrlVars: function() {
79
var hash, hashes, i, vars;
@@ -22,6 +24,10 @@ $.extend({
2224
}
2325
});
2426

27+
formatMessage = function(msg) {
28+
return msg.replace(/\n/g, "<br />");
29+
};
30+
2531
$(function() {
2632
var branch, callback, container, limit, params, repo, url, username;
2733
params = $.getUrlVars();
@@ -31,20 +37,20 @@ $(function() {
3137
branch = params.branch;
3238
container = $('#latest-commits-widget');
3339
callback = function(response) {
34-
var index, items, result, ul, _results;
40+
var index, items, result, results, ul;
3541
items = response.data;
3642
ul = $('#commit-history');
3743
ul.empty();
38-
_results = [];
44+
results = [];
3945
for (index in items) {
4046
result = items[index];
41-
_results.push((function(index, result) {
47+
results.push((function(index, result) {
4248
if (result.author != null) {
43-
return ul.append("<li class=\"clearfix\">\n <div class=\"left\">\n <img class=\"commit-avatar\" src=\"" + result.author.avatar_url + "\">\n </div>\n <div class=\"commit-author-info left\">\n <a href=\"https://github.com/" + result.author.login + "\"><b class=\"commit-author\">" + result.author.login + "</b></a>\n <br />\n <b class=\"commit-date\">" + ($.timeago(result.commit.committer.date)) + "</b><br /><i class=\"commit-sha\">SHA: " + result.sha + "</i>\n <br />\n <a class=\"commit-message\" href=\"https://github.com/" + username + "/" + repo + "/commit/" + result.sha + "\" target=\"_blank\">" + result.commit.message + "</a>\n </div>\n</li>");
49+
return ul.append("<li class=\"clearfix\">\n <div class=\"left\">\n <img class=\"commit-avatar\" src=\"" + result.author.avatar_url + "\">\n </div>\n <div class=\"commit-author-info left\">\n <a href=\"https://github.com/" + result.author.login + "\"><b class=\"commit-author\">" + result.author.login + "</b></a>\n <br />\n <b class=\"commit-date\">" + ($.timeago(result.commit.committer.date)) + "</b><br /><i class=\"commit-sha\">SHA: " + result.sha + "</i>\n <br />\n <a class=\"commit-message\" href=\"https://github.com/" + username + "/" + repo + "/commit/" + result.sha + "\" target=\"_blank\">" + (formatMessage(result.commit.message)) + "</a>\n </div>\n</li>");
4450
}
4551
})(index, result));
4652
}
47-
return _results;
53+
return results;
4854
};
4955
container.find('h4').text("Latest Commits to " + username + "/" + repo);
5056
url = "https://api.github.com/repos/" + username + "/" + repo + "/commits?callback=callback";

0 commit comments

Comments
 (0)