Skip to content

Commit 961210f

Browse files
site: support permalinks. fixes googleapis#184
1 parent b2721e0 commit 961210f

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

docs/components/docs/docs.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ <h1>{{module[0].toUpperCase() + module.substr(1)}}</h1>
4848
</article>
4949
</article>
5050

51-
<article ng-repeat="method in methods" id="{{method.name}}">
51+
<article
52+
ng-repeat="method in methods"
53+
ng-hide="singleMethod && method.name !== singleMethod">
5254
<h2 ng-if="method.name[0].toUpperCase() === method.name[0]">
5355
{{method.name}}
5456
</h2>
5557
<h3 ng-if="method.name[0].toUpperCase() !== method.name[0]">
56-
{{method.name}}
58+
<a ng-if="!singleMethod" ng-href="{{activeUrl + '/' + method.name}}">
59+
{{method.name}}
60+
</a>
61+
<span ng-if="singleMethod">{{method.name}}</span>
5762
</h3>
5863
<p ng-if="method.description" ng-bind-html="method.description"></p>
5964
<h4 ng-show="method.params">Parameters</h4>

docs/components/docs/docs.js

+26
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,30 @@ angular
133133
.then(filterDocJson($sce));
134134
}
135135
}
136+
})
137+
.when('/docs/:module/:class/:method', {
138+
controller: 'DocsCtrl',
139+
templateUrl: '/gcloud-node/components/docs/docs.html',
140+
resolve: {
141+
methods: function($q, $http, $route, $sce, $location) {
142+
var module = $route.current.params.module;
143+
var cl = $route.current.params.class;
144+
var method = $route.current.params.method;
145+
return $http.get('/gcloud-node/json/' + module + '/' + cl + '.json')
146+
.then(filterDocJson($sce))
147+
.then(function(methods) {
148+
var methodExists = methods.some(function(methodObj) {
149+
return method === methodObj.name;
150+
});
151+
if (methodExists) {
152+
methods.singleMethod = method;
153+
return methods;
154+
} else {
155+
$location.path('/docs/' + module + '/' + cl);
156+
}
157+
});
158+
}
159+
}
136160
});
137161
})
138162
.controller('DocsCtrl', function($location, $scope, $routeParams, methods) {
@@ -146,6 +170,8 @@ angular
146170
return doc.toLowerCase() === $routeParams.module;
147171
};
148172

173+
$scope.activeUrl = '/gcloud-node/#' + $location.path();
174+
$scope.singleMethod = methods.singleMethod;
149175
$scope.methods = methods;
150176
$scope.module = $routeParams.module;
151177
$scope.pages = [

docs/home.js

+10
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,14 @@ angular
77
.when('/', {
88
templateUrl: '/gcloud-node/home.html'
99
});
10+
})
11+
.run(function($rootScope, $location) {
12+
$rootScope.$on('$routeChangeStart', function(event) {
13+
var hash = $location.hash();
14+
if (hash) {
15+
event.preventDefault();
16+
$location.hash('');
17+
$location.replace().path($location.path() + '/' + hash);
18+
}
19+
});
1020
});

0 commit comments

Comments
 (0)