Add a markdown-view directive and change all uses of markdown in the partials to use the directive

This commit is contained in:
Joseph Schorr 2013-11-04 19:36:56 -05:00
parent 96730965cd
commit 9beb627ab0
10 changed files with 83 additions and 89 deletions

View file

@ -1,3 +1,40 @@
function getFirstTextLine(commentString) {
if (!commentString) { return ''; }
var lines = commentString.split('\n');
var MARKDOWN_CHARS = {
'#': true,
'-': true,
'>': true,
'`': true
};
for (var i = 0; i < lines.length; ++i) {
// Skip code lines.
if (lines[i].indexOf(' ') == 0) {
continue;
}
// Skip empty lines.
if ($.trim(lines[i]).length == 0) {
continue;
}
// Skip control lines.
if (MARKDOWN_CHARS[$.trim(lines[i])[0]]) {
continue;
}
return getMarkedDown(lines[i]);
}
return '';
}
function getMarkedDown(string) {
return Markdown.getSanitizingConverter().makeHtml(string || '');
}
// Start the application code itself.
quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics', 'angulartics.mixpanel', '$strap.directives'], function($provide) {
$provide.factory('UserService', ['Restangular', function(Restangular) {
@ -215,6 +252,31 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
RestangularProvider.setBaseUrl('/api/');
});
quayApp.directive('markdownView', function () {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/markdown-view.html',
replace: false,
transclude: false,
restrict: 'C',
scope: {
'content': '=content',
'firstLineOnly': '=firstLineOnly'
},
controller: function($scope, $element) {
$scope.getMarkedDown = function(content, firstLineOnly) {
if (firstLineOnly) {
content = getFirstTextLine(content);
}
return getMarkedDown(content);
};
}
};
return directiveDefinitionObject;
});
quayApp.directive('repoCircle', function () {
var directiveDefinitionObject = {
priority: 0,

View file

@ -25,43 +25,6 @@ function getRestUrl(args) {
return url;
}
function getFirstTextLine(commentString) {
if (!commentString) { return; }
var lines = commentString.split('\n');
var MARKDOWN_CHARS = {
'#': true,
'-': true,
'>': true,
'`': true
};
for (var i = 0; i < lines.length; ++i) {
// Skip code lines.
if (lines[i].indexOf(' ') == 0) {
continue;
}
// Skip empty lines.
if ($.trim(lines[i]).length == 0) {
continue;
}
// Skip control lines.
if (MARKDOWN_CHARS[$.trim(lines[i])[0]]) {
continue;
}
return getMarkedDown(lines[i]);
}
return '';
}
function getMarkedDown(string) {
return Markdown.getSanitizingConverter().makeHtml(string || '');
}
function HeaderCtrl($scope, $location, UserService, Restangular) {
$scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) {
$scope.user = currentUser;
@ -195,15 +158,6 @@ function RepoListCtrl($scope, Restangular, UserService) {
$scope.user = currentUser;
}, true);
$scope.getCommentFirstLine = function(commentString) {
return getMarkedDown(getFirstTextLine(commentString));
};
$scope.getMarkedDown = function(string) {
if (!string) { return ''; }
return getMarkedDown(string);
};
$scope.loading = true;
$scope.public_repositories = null;
$scope.private_repositories = null;
@ -245,10 +199,6 @@ function LandingCtrl($scope, $timeout, $location, Restangular, UserService, KeyS
$scope.awaitingConfirmation = false;
$scope.registering = false;
$scope.getCommentFirstLine = function(commentString) {
return getMarkedDown(getFirstTextLine(commentString));
};
$scope.register = function() {
$('.form-signup').popover('hide');
$scope.registering = true;
@ -322,19 +272,10 @@ function RepoCtrl($scope, Restangular, $routeParams, $rootScope, $location, $tim
return Date.parse(dateString);
};
$scope.getCommentFirstLine = function(commentString) {
return getMarkedDown(getFirstTextLine(commentString));
};
$scope.getTimeSince = function(createdTime) {
return moment($scope.parseDate(createdTime)).fromNow();
};
$scope.getMarkedDown = function(string) {
if (!string) { return ''; }
return getMarkedDown(string);
};
var getDefaultTag = function() {
if ($scope.repo === undefined) {
return undefined;
@ -866,11 +807,6 @@ function ImageViewCtrl($scope, $routeParams, $rootScope, Restangular) {
$('#copyClipboard').clipboardCopy();
$scope.getMarkedDown = function(string) {
if (!string) { return ''; }
return getMarkedDown(string);
};
$scope.parseDate = function(dateString) {
return Date.parse(dateString);
};
@ -1079,11 +1015,6 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangula
$('#editModal').modal({});
};
$scope.getMarkedDown = function(string) {
if (!string) { return ''; }
return getMarkedDown(string);
};
$scope.saveDescription = function() {
$('#editModal').modal('hide');
$scope.repo.description = $('#wmd-input-description')[0].value;
@ -1180,15 +1111,6 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangula
function OrgViewCtrl($scope, Restangular, $routeParams) {
var orgname = $routeParams.orgname;
$scope.getDescriptionFirstLine = function(commentString) {
return getMarkedDown(getFirstTextLine(commentString));
};
$scope.getMarkedDown = function(string) {
if (!string) { return ''; }
return getMarkedDown(string);
};
var loadOrganization = function() {
var getOrganization = Restangular.one(getRestUrl('organization', orgname));
getOrganization.get().then(function(resp) {