|
153 | 153 | return { |
154 | 154 | restrict: 'E', |
155 | 155 | templateUrl: 'directives/documentation.tpl.html', |
156 | | - controller: ['$scope', function($scope) { |
| 156 | + controller: ['$scope', 'idGenerator', function($scope, idGenerator) { |
157 | 157 | $scope.markedOptions = RAML.Settings.marked; |
158 | 158 |
|
159 | 159 | $scope.$watch('securitySchemes', function() { |
|
393 | 393 | }; |
394 | 394 |
|
395 | 395 | $scope.getBodyId = function (bodyType) { |
396 | | - return jQuery.trim(bodyType.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_'); |
| 396 | + return idGenerator(bodyType.toString()); |
397 | 397 | }; |
398 | 398 |
|
399 | 399 | $scope.bodySelected = function (value) { |
|
1660 | 1660 | .directive('resourcePanel', RAML.Directives.resourcePanel); |
1661 | 1661 | })(); |
1662 | 1662 |
|
| 1663 | +(function () { |
| 1664 | + 'use strict'; |
| 1665 | + |
| 1666 | + angular.module('RAML.Directives') |
| 1667 | + .factory('idGenerator', [function idGenerator() { |
| 1668 | + return function(value) { |
| 1669 | + var id = jQuery.trim(value.replace(/\W/g, ' ')).replace(/\s+/g, '_'); |
| 1670 | + return id === '' ? '-' : id; |
| 1671 | + }; |
| 1672 | + }]); |
| 1673 | +})(); |
| 1674 | + |
1663 | 1675 | (function () { |
1664 | 1676 | 'use strict'; |
1665 | 1677 |
|
|
1699 | 1711 | 'use strict'; |
1700 | 1712 |
|
1701 | 1713 | angular.module('RAML.Directives') |
1702 | | - .factory('resourceId', [function resourceId() { |
| 1714 | + .factory('resourceId', ['idGenerator', function resourceId(idGenerator) { |
1703 | 1715 | return function(resource) { |
1704 | | - return jQuery.trim(resource.pathSegments.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_'); |
| 1716 | + return idGenerator(resource.pathSegments.toString()); |
1705 | 1717 | }; |
1706 | 1718 | }]); |
1707 | 1719 | })(); |
|
2132 | 2144 | restrict: 'E', |
2133 | 2145 | templateUrl: 'directives/root-documentation.tpl.html', |
2134 | 2146 | replace: true, |
2135 | | - controller: ['$scope', '$timeout', function($scope, $timeout) { |
| 2147 | + controller: ['$scope', '$timeout', 'idGenerator', function($scope, $timeout, idGenerator) { |
2136 | 2148 | $scope.markedOptions = RAML.Settings.marked; |
2137 | 2149 | $scope.selectedSection = 'all'; |
2138 | 2150 |
|
|
2145 | 2157 | }; |
2146 | 2158 |
|
2147 | 2159 | $scope.generateDocId = function (path) { |
2148 | | - return jQuery.trim(path.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_').toLowerCase(); |
| 2160 | + return idGenerator(path.toString()); |
2149 | 2161 | }; |
2150 | 2162 |
|
2151 | 2163 | $scope.toggleSection = function ($event, key, section) { |
|
0 commit comments