@@ -100,14 +100,39 @@ angular
100
100
} ;
101
101
}
102
102
103
+ function setMethod ( $location , methodName ) {
104
+ return function ( methods ) {
105
+ var methodExists = methods . some ( function ( methodObj ) {
106
+ return methodName === methodObj . name ;
107
+ } ) ;
108
+ if ( methodExists ) {
109
+ methods . singleMethod = methodName ;
110
+ return methods ;
111
+ } else {
112
+ $location . path ( '/docs/' + module + '/' + cl ) ;
113
+ }
114
+ } ;
115
+ }
116
+
117
+ var MODULE_TO_CLASSES = {
118
+ datastore : [ 'dataset' , 'query' ] ,
119
+ storage : [ ]
120
+ } ;
121
+
103
122
$routeProvider
104
123
. when ( '/docs' , {
105
124
controller : 'DocsCtrl' ,
106
125
templateUrl : '/gcloud-node/components/docs/docs.html' ,
107
126
resolve : {
108
127
methods : function ( $http , $sce ) {
109
128
return $http . get ( '/gcloud-node/json/index.json' )
110
- . then ( filterDocJson ( $sce ) ) ;
129
+ . then ( filterDocJson ( $sce ) )
130
+ . then ( function ( methods ) {
131
+ // Prevent headings from turning into links.
132
+ // ** Can remove when PubSub api is documented **
133
+ methods . noHeadingLink = true ;
134
+ return methods ;
135
+ } ) ;
111
136
}
112
137
}
113
138
} )
@@ -117,6 +142,9 @@ angular
117
142
resolve : {
118
143
methods : function ( $http , $route , $sce ) {
119
144
var module = $route . current . params . module ;
145
+ if ( ! MODULE_TO_CLASSES [ module ] ) {
146
+ return [ ] ;
147
+ }
120
148
return $http . get ( '/gcloud-node/json/' + module + '/index.json' )
121
149
. then ( filterDocJson ( $sce ) ) ;
122
150
}
@@ -126,11 +154,33 @@ angular
126
154
controller : 'DocsCtrl' ,
127
155
templateUrl : '/gcloud-node/components/docs/docs.html' ,
128
156
resolve : {
129
- methods : function ( $q , $http , $route , $sce ) {
157
+ methods : function ( $q , $http , $route , $sce , $location ) {
130
158
var module = $route . current . params . module ;
131
159
var cl = $route . current . params . class ;
160
+ if ( MODULE_TO_CLASSES [ module ] . length > 0 ) {
161
+ return $http
162
+ . get ( '/gcloud-node/json/' + module + '/' + cl + '.json' )
163
+ . then ( filterDocJson ( $sce ) ) ;
164
+ } else {
165
+ var method = cl ;
166
+ return $http . get ( '/gcloud-node/json/' + module + '/index.json' )
167
+ . then ( filterDocJson ( $sce ) )
168
+ . then ( setMethod ( $location , method ) ) ;
169
+ }
170
+ }
171
+ }
172
+ } )
173
+ . when ( '/docs/:module/:class/:method' , {
174
+ controller : 'DocsCtrl' ,
175
+ templateUrl : '/gcloud-node/components/docs/docs.html' ,
176
+ resolve : {
177
+ methods : function ( $q , $http , $route , $sce , $location ) {
178
+ var module = $route . current . params . module ;
179
+ var cl = $route . current . params . class ;
180
+ var method = $route . current . params . method ;
132
181
return $http . get ( '/gcloud-node/json/' + module + '/' + cl + '.json' )
133
- . then ( filterDocJson ( $sce ) ) ;
182
+ . then ( filterDocJson ( $sce ) )
183
+ . then ( setMethod ( $location , method ) ) ;
134
184
}
135
185
}
136
186
} ) ;
@@ -139,13 +189,20 @@ angular
139
189
'use strict' ;
140
190
141
191
$scope . isActiveUrl = function ( url ) {
142
- return url . replace ( / ^ \/ g c l o u d - n o d e \/ # / , '' ) === $location . path ( ) ;
192
+ var current = $location . path ( ) . replace ( '/' + methods . singleMethod , '' ) ;
193
+ var link = url
194
+ . replace ( / ^ \/ g c l o u d - n o d e \/ # / , '' )
195
+ . replace ( '/' + methods . singleMethod , '' ) ;
196
+ return current === link ;
143
197
} ;
144
198
145
199
$scope . isActiveDoc = function ( doc ) {
146
200
return doc . toLowerCase ( ) === $routeParams . module ;
147
201
} ;
148
202
203
+ $scope . activeUrl = '/gcloud-node/#' + $location . path ( ) ;
204
+ $scope . singleMethod = methods . singleMethod ;
205
+ $scope . noHeadingLink = methods . singleMethod || methods . noHeadingLink ;
149
206
$scope . methods = methods ;
150
207
$scope . module = $routeParams . module ;
151
208
$scope . pages = [
0 commit comments