@@ -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 : 'components/docs/docs.html' ,
107
126
resolve : {
108
127
methods : function ( $http , $sce ) {
109
128
return $http . get ( 'json/index.json' )
110
- . then ( filterDocJson ( $sce ) ) ;
129
+ . then ( filterDocJson ( $sce ) )
130
+ . then ( function ( methods ) {
131
+ // Prevent displaying permalinks.
132
+ // ** Can remove when PubSub api is documented **
133
+ methods . noPermalink = true ;
134
+ return methods ;
135
+ } ) ;
111
136
}
112
137
}
113
138
} )
@@ -126,11 +151,34 @@ angular
126
151
controller : 'DocsCtrl' ,
127
152
templateUrl : 'components/docs/docs.html' ,
128
153
resolve : {
129
- methods : function ( $q , $http , $route , $sce ) {
154
+ methods : function ( $q , $http , $route , $sce , $location ) {
130
155
var module = $route . current . params . module ;
131
156
var cl = $route . current . params . class ;
157
+ if ( MODULE_TO_CLASSES [ module ] . length > 0 ) {
158
+ return $http
159
+ . get ( 'json/' + module + '/' + cl + '.json' )
160
+ . then ( filterDocJson ( $sce ) ) ;
161
+ } else {
162
+ // This is not a class, this is the name of a method.
163
+ var method = cl ;
164
+ return $http . get ( 'json/' + module + '/index.json' )
165
+ . then ( filterDocJson ( $sce ) )
166
+ . then ( setMethod ( $location , method ) ) ;
167
+ }
168
+ }
169
+ }
170
+ } )
171
+ . when ( '/docs/:module/:class/:method' , {
172
+ controller : 'DocsCtrl' ,
173
+ templateUrl : 'components/docs/docs.html' ,
174
+ resolve : {
175
+ methods : function ( $q , $http , $route , $sce , $location ) {
176
+ var module = $route . current . params . module ;
177
+ var cl = $route . current . params . class ;
178
+ var method = $route . current . params . method ;
132
179
return $http . get ( 'json/' + module + '/' + cl + '.json' )
133
- . then ( filterDocJson ( $sce ) ) ;
180
+ . then ( filterDocJson ( $sce ) )
181
+ . then ( setMethod ( $location , method ) ) ;
134
182
}
135
183
}
136
184
} ) ;
@@ -139,13 +187,20 @@ angular
139
187
'use strict' ;
140
188
141
189
$scope . isActiveUrl = function ( url ) {
142
- return url . replace ( / ^ # / , '' ) === $location . path ( ) ;
190
+ var current = $location . path ( ) . replace ( '/' + methods . singleMethod , '' ) ;
191
+ var link = url
192
+ . replace ( / ^ # / , '' )
193
+ . replace ( '/' + methods . singleMethod , '' ) ;
194
+ return current === link ;
143
195
} ;
144
196
145
197
$scope . isActiveDoc = function ( doc ) {
146
198
return doc . toLowerCase ( ) === $routeParams . module ;
147
199
} ;
148
200
201
+ $scope . activeUrl = '#' + $location . path ( ) ;
202
+ $scope . singleMethod = methods . singleMethod ;
203
+ $scope . noPermalink = methods . singleMethod || methods . noPermalink ;
149
204
$scope . methods = methods ;
150
205
$scope . module = $routeParams . module ;
151
206
$scope . pages = [
0 commit comments