Skip to content

Commit a95fd6e

Browse files
authored
Merge pull request #532 from mulesoft/3.x.x/develop
CONSOLE-281: display urls in methods description
2 parents 3b5b041 + c2d3257 commit a95fd6e

File tree

7 files changed

+113
-36
lines changed

7 files changed

+113
-36
lines changed

dist/scripts/api-console.js

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -511,25 +511,47 @@
511511
scope: {
512512
markdown: '='
513513
},
514-
controller: ['$scope', '$sanitize', '$window', '$element', function($scope, $sanitize, $window, $element) {
515-
$scope.$watch('markdown', function (markdown) {
516-
var allowUnsafeMarkdown = $scope.$parent.allowUnsafeMarkdown;
514+
controller: 'MarkdownController'
515+
};
516+
};
517517

518-
var markdownString = typeof markdown === 'string' ? markdown || '' : '';
519-
var html = $window.marked(markdownString, RAML.Settings.marked);
518+
RAML.Directives.markdownString = function () {
519+
return {
520+
restrict: 'A',
521+
scope: {
522+
markdownString: '@'
523+
},
524+
controller: 'MarkdownStringController'
525+
};
526+
};
520527

521-
if (!allowUnsafeMarkdown) {
522-
html = $sanitize(html);
523-
}
528+
var watchMarkdown = function(expression, $scope, $window, $sanitize, $element) {
529+
$scope.$watch(expression, function (markdown) {
530+
var allowUnsafeMarkdown = $scope.$parent.allowUnsafeMarkdown;
531+
var markdownString = typeof markdown === 'string' ? markdown || '' : '';
532+
var html = $window.marked(markdownString, RAML.Settings.marked);
524533

525-
$element.html(html);
526-
});
527-
}]
528-
};
534+
if (!allowUnsafeMarkdown) {
535+
html = $sanitize(html);
536+
}
537+
538+
$element.html(html);
539+
});
529540
};
530541

542+
function controller($scope, $sanitize, $window, $element) {
543+
watchMarkdown('markdown', $scope, $window, $sanitize, $element);
544+
}
545+
546+
function stringController($scope, $sanitize, $window, $element) {
547+
watchMarkdown('markdownString', $scope, $window, $sanitize, $element);
548+
}
549+
531550
angular.module('RAML.Directives')
532-
.directive('markdown', RAML.Directives.markdown);
551+
.controller('MarkdownController', controller)
552+
.controller('MarkdownStringController', stringController)
553+
.directive('markdown', RAML.Directives.markdown)
554+
.directive('markdownString', RAML.Directives.markdownString);
533555
})();
534556

535557
(function () {
@@ -1780,7 +1802,7 @@
17801802
element.append(resourceHeadingElement(resource, currentId));
17811803
element.append(resourceTypeElement(resource));
17821804
element.append(resourceHeadingFlagElement($scope, resource));
1783-
element.append(resourceLevelDescriptionElement(resource));
1805+
element.append(resourceLevelDescriptionElement($scope, $compile, resource));
17841806
element.append(methodListElement($scope, resource, currentId, showResource, resourceId));
17851807
element.append(closeMethodButton($scope, resource, currentId, showResource, resourceId));
17861808

@@ -1804,9 +1826,12 @@
18041826
return '';
18051827
}
18061828

1807-
function resourceLevelDescriptionElement(resource) {
1829+
function resourceLevelDescriptionElement($scope, $compile, resource) {
18081830
var element = angular.element('<span class="raml-console-resource-level-description raml-console-marked-content"></span>');
1809-
element.append(angular.element('<p>' + resource.description + '</p>'));
1831+
element.attr('markdown-string', resource.description);
1832+
1833+
$compile(element)($scope);
1834+
18101835
return element;
18111836
}
18121837

src/app/directives/markdown.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,45 @@
77
scope: {
88
markdown: '='
99
},
10-
controller: ['$scope', '$sanitize', '$window', '$element', function($scope, $sanitize, $window, $element) {
11-
$scope.$watch('markdown', function (markdown) {
12-
var allowUnsafeMarkdown = $scope.$parent.allowUnsafeMarkdown;
10+
controller: 'MarkdownController'
11+
};
12+
};
13+
14+
RAML.Directives.markdownString = function () {
15+
return {
16+
restrict: 'A',
17+
scope: {
18+
markdownString: '@'
19+
},
20+
controller: 'MarkdownStringController'
21+
};
22+
};
1323

14-
var markdownString = typeof markdown === 'string' ? markdown || '' : '';
15-
var html = $window.marked(markdownString, RAML.Settings.marked);
24+
var watchMarkdown = function(expression, $scope, $window, $sanitize, $element) {
25+
$scope.$watch(expression, function (markdown) {
26+
var allowUnsafeMarkdown = $scope.$parent.allowUnsafeMarkdown;
27+
var markdownString = typeof markdown === 'string' ? markdown || '' : '';
28+
var html = $window.marked(markdownString, RAML.Settings.marked);
1629

17-
if (!allowUnsafeMarkdown) {
18-
html = $sanitize(html);
19-
}
30+
if (!allowUnsafeMarkdown) {
31+
html = $sanitize(html);
32+
}
2033

21-
$element.html(html);
22-
});
23-
}]
24-
};
34+
$element.html(html);
35+
});
2536
};
2637

38+
function controller($scope, $sanitize, $window, $element) {
39+
watchMarkdown('markdown', $scope, $window, $sanitize, $element);
40+
}
41+
42+
function stringController($scope, $sanitize, $window, $element) {
43+
watchMarkdown('markdownString', $scope, $window, $sanitize, $element);
44+
}
45+
2746
angular.module('RAML.Directives')
28-
.directive('markdown', RAML.Directives.markdown);
47+
.controller('MarkdownController', controller)
48+
.controller('MarkdownStringController', stringController)
49+
.directive('markdown', RAML.Directives.markdown)
50+
.directive('markdownString', RAML.Directives.markdownString);
2951
})();

src/app/directives/resource-tree/resource-list.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
element.append(resourceHeadingElement(resource, currentId));
4545
element.append(resourceTypeElement(resource));
4646
element.append(resourceHeadingFlagElement($scope, resource));
47-
element.append(resourceLevelDescriptionElement(resource));
47+
element.append(resourceLevelDescriptionElement($scope, $compile, resource));
4848
element.append(methodListElement($scope, resource, currentId, showResource, resourceId));
4949
element.append(closeMethodButton($scope, resource, currentId, showResource, resourceId));
5050

@@ -68,9 +68,12 @@
6868
return '';
6969
}
7070

71-
function resourceLevelDescriptionElement(resource) {
71+
function resourceLevelDescriptionElement($scope, $compile, resource) {
7272
var element = angular.element('<span class="raml-console-resource-level-description raml-console-marked-content"></span>');
73-
element.append(angular.element('<p>' + resource.description + '</p>'));
73+
element.attr('markdown-string', resource.description);
74+
75+
$compile(element)($scope);
76+
7477
return element;
7578
}
7679

test/regression/assertions/resource.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ function Resource (poName) {
215215
expect(resourceDescription.getText()).toContain(expectedDescription);
216216
};
217217

218+
this.ifDisplayingDescriptionUrl = function (resource, expectedDescription) {
219+
var url = this.po.getDescriptionUrl(resource);
220+
221+
expect(url).toContain(expectedDescription);
222+
};
223+
218224
this.ifDisplayingRootDescription = function (expectedDescription) {
219225
var rootDescription = this.po.getRootDescription();
220226

test/regression/assets/raml/descriptions.raml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ title: Product API
44
description: Product API
55

66
/product:
7-
description: Product
7+
description: Product. http://getproduct
88
get:
99
description: |
10-
Retrieve all the Products.
10+
Retrieve all the Products. http://getproduct
1111
/{id}:
12-
description: Get Product by ID
12+
description: Get Product by ID. http://getproductbyid
1313
get:
1414

1515
/product/info:
16-
description: Get Product Info
16+
description: Get Product Info. http://getproductinfo
1717
get:

test/regression/page_objects/resourcePO.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ function ResourcesPO () {
158158
.element(by.css('.raml-console-resource-level-description'));
159159
};
160160

161+
this.getDescriptionUrl = function (resource) {
162+
return this.resources.get(resource + 1)
163+
.element(by.css('.raml-console-resource-level-description'))
164+
.element(by.tagName('p'))
165+
.element(by.tagName('a'))
166+
.getAttribute('href');
167+
};
168+
161169
this.getRootDescription = function () {
162170
return element(by.css('.raml-console-root-description'));
163171
};

test/regression/standalone/directiveSpec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,19 @@ module.exports = function() {
373373
assert.ifDisplayingDescription(2, 'Get Product Info');
374374
});
375375

376+
it('should display urls in description for all resources', function () {
377+
// Arrange
378+
var assert = assertions.create('resource');
379+
380+
// Act
381+
browser.get('http://localhost:9000/descriptions.html');
382+
383+
//Assert
384+
assert.ifDisplayingDescriptionUrl(0, 'http://getproduct');
385+
assert.ifDisplayingDescriptionUrl(1, 'http://getproductbyid');
386+
assert.ifDisplayingDescriptionUrl(2, 'http://getproductinfo');
387+
});
388+
376389
it('should display root description', function () {
377390
// Arrange
378391
var assert = assertions.create('resource');

0 commit comments

Comments
 (0)