From 9beb627ab09143aa99da6fa2e722f2ce9f7be456 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 4 Nov 2013 19:36:56 -0500 Subject: [PATCH] Add a markdown-view directive and change all uses of markdown in the partials to use the directive --- static/css/quay.css | 12 +++-- static/directives/markdown-view.html | 1 + static/js/app.js | 62 ++++++++++++++++++++++ static/js/controllers.js | 78 ---------------------------- static/partials/image-view.html | 4 +- static/partials/landing.html | 2 +- static/partials/new-repo.html | 2 +- static/partials/org-view.html | 2 +- static/partials/repo-list.html | 4 +- static/partials/view-repo.html | 5 +- 10 files changed, 83 insertions(+), 89 deletions(-) create mode 100644 static/directives/markdown-view.html diff --git a/static/css/quay.css b/static/css/quay.css index 4de0c99ed..663a25154 100644 --- a/static/css/quay.css +++ b/static/css/quay.css @@ -27,6 +27,10 @@ margin-left: 10px; } +.organization-header-element .team-name { + text-transform: capitalize; +} + .namespace-selector-dropdown .namespace { padding: 6px; padding-left: 10px; @@ -1390,13 +1394,15 @@ p.editable:hover i { .org-view .team-listing { margin: 10px; padding: 10px; - border-bottom: 1px solid #eee; - min-width: 400px; - display: inline-block; +} + +.org-view .team-listing i { + margin-right: 10px; } .org-view .team-title { font-size: 20px; + text-transform: capitalize; } /* Overrides for typeahead to work with bootstrap 3. */ diff --git a/static/directives/markdown-view.html b/static/directives/markdown-view.html new file mode 100644 index 000000000..fe915b857 --- /dev/null +++ b/static/directives/markdown-view.html @@ -0,0 +1 @@ + diff --git a/static/js/app.js b/static/js/app.js index 6fb984a47..333f0d047 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -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, diff --git a/static/js/controllers.js b/static/js/controllers.js index 9bbe2c3a1..55d277f75 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -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) { diff --git a/static/partials/image-view.html b/static/partials/image-view.html index 5e4477116..5d2753d8a 100644 --- a/static/partials/image-view.html +++ b/static/partials/image-view.html @@ -20,7 +20,9 @@ -
+
+ +
diff --git a/static/partials/landing.html b/static/partials/landing.html index 4e3426972..aadb8fadd 100644 --- a/static/partials/landing.html +++ b/static/partials/landing.html @@ -17,7 +17,7 @@
diff --git a/static/partials/new-repo.html b/static/partials/new-repo.html index 8330cc6d4..70effd42a 100644 --- a/static/partials/new-repo.html +++ b/static/partials/new-repo.html @@ -40,7 +40,7 @@
Description:

- +

diff --git a/static/partials/org-view.html b/static/partials/org-view.html index 964f7768f..197e7f262 100644 --- a/static/partials/org-view.html +++ b/static/partials/org-view.html @@ -19,6 +19,6 @@ {{ team.name }}
-
+
diff --git a/static/partials/repo-list.html b/static/partials/repo-list.html index 5edd390d0..22ae0455d 100644 --- a/static/partials/repo-list.html +++ b/static/partials/repo-list.html @@ -16,7 +16,7 @@ @@ -34,7 +34,7 @@ diff --git a/static/partials/view-repo.html b/static/partials/view-repo.html index 2efe29be1..bcbc789ab 100644 --- a/static/partials/view-repo.html +++ b/static/partials/view-repo.html @@ -54,7 +54,7 @@

- +

@@ -122,7 +122,8 @@
-
+
+