Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

site: support permalinks. fixes #184 #188

Merged
merged 1 commit into from
Sep 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/components/docs/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ <h1>{{module[0].toUpperCase() + module.substr(1)}}</h1>
</article>
</article>

<article ng-repeat="method in methods" id="{{method.name}}">
<article
ng-repeat="method in methods"
ng-hide="singleMethod && method.name !== singleMethod">
<h2 ng-if="method.name[0].toUpperCase() === method.name[0]">
{{method.name}}
</h2>
<h3 ng-if="method.name[0].toUpperCase() !== method.name[0]">
<h3
class="method-heading"
ng-if="method.name[0].toUpperCase() !== method.name[0]">
<a
class="permalink"
ng-if="!noPermalink"
ng-href="{{activeUrl + '/' + method.name}}">#</a>
{{method.name}}
</h3>
<p ng-if="method.description" ng-bind-html="method.description"></p>
Expand Down
63 changes: 59 additions & 4 deletions docs/components/docs/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,39 @@ angular
};
}

function setMethod($location, methodName) {
return function(methods) {
var methodExists = methods.some(function(methodObj) {
return methodName === methodObj.name;
});
if (methodExists) {
methods.singleMethod = methodName;
return methods;
} else {
$location.path('/docs/' + module + '/' + cl);

This comment was marked as spam.

This comment was marked as spam.

}
};
}

var MODULE_TO_CLASSES = {
datastore: ['dataset', 'query'],
storage: []
};

$routeProvider
.when('/docs', {
controller: 'DocsCtrl',
templateUrl: 'components/docs/docs.html',
resolve: {
methods: function($http, $sce) {
return $http.get('json/index.json')
.then(filterDocJson($sce));
.then(filterDocJson($sce))
.then(function(methods) {
// Prevent displaying permalinks.
// ** Can remove when PubSub api is documented **
methods.noPermalink = true;
return methods;
});
}
}
})
Expand All @@ -126,11 +151,34 @@ angular
controller: 'DocsCtrl',
templateUrl: 'components/docs/docs.html',
resolve: {
methods: function($q, $http, $route, $sce) {
methods: function($q, $http, $route, $sce, $location) {
var module = $route.current.params.module;
var cl = $route.current.params.class;
if (MODULE_TO_CLASSES[module].length > 0) {
return $http
.get('json/' + module + '/' + cl + '.json')
.then(filterDocJson($sce));
} else {
// This is not a class, this is the name of a method.
var method = cl;
return $http.get('json/' + module + '/index.json')
.then(filterDocJson($sce))
.then(setMethod($location, method));
}
}
}
})
.when('/docs/:module/:class/:method', {
controller: 'DocsCtrl',
templateUrl: 'components/docs/docs.html',
resolve: {
methods: function($q, $http, $route, $sce, $location) {
var module = $route.current.params.module;
var cl = $route.current.params.class;
var method = $route.current.params.method;
return $http.get('json/' + module + '/' + cl + '.json')
.then(filterDocJson($sce));
.then(filterDocJson($sce))
.then(setMethod($location, method));
}
}
});
Expand All @@ -139,13 +187,20 @@ angular
'use strict';

$scope.isActiveUrl = function(url) {
return url.replace(/^#/, '') === $location.path();
var current = $location.path().replace('/' + methods.singleMethod, '');
var link = url
.replace(/^#/, '')
.replace('/' + methods.singleMethod, '');
return current === link;
};

$scope.isActiveDoc = function(doc) {
return doc.toLowerCase() === $routeParams.module;
};

$scope.activeUrl = '#' + $location.path();
$scope.singleMethod = methods.singleMethod;
$scope.noPermalink = methods.singleMethod || methods.noPermalink;
$scope.methods = methods;
$scope.module = $routeParams.module;
$scope.pages = [
Expand Down
22 changes: 22 additions & 0 deletions docs/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,28 @@ h1, h2, h3, h4, h5, h6 {
border-bottom: 1px solid rgba(0,0,0,0.05);
}

.method-heading {
position: relative;
}

.permalink {
display: none;
position: absolute;
padding: 0 7px;
left: -24px;
text-decoration: none;
color: #2b70e2;
}

.permalink:hover {
color: #4285f4;
display: block;
}

.method-heading:hover .permalink {
display: block;
}

/*
Page Title
*/
Expand Down
12 changes: 12 additions & 0 deletions docs/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@ angular
.when('/', {
templateUrl: 'home.html'
});
})
.run(function($rootScope, $location) {
'use strict';

$rootScope.$on('$routeChangeStart', function(event) {
var hash = $location.hash();
if (hash) {
event.preventDefault();
$location.hash('');
$location.replace().path($location.path() + '/' + hash);
}
});
});