Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
chore(website): organize the API TOC
Browse files Browse the repository at this point in the history
Closes #2169
  • Loading branch information
sjelin committed Jun 30, 2015
1 parent a8bfc4b commit 7e8d4fd
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 18 deletions.
22 changes: 22 additions & 0 deletions website/css/protractor.less
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,30 @@ a code {

.child {
color: @child-color;
}

.depth-1 {
margin-left: 20px;
}

.depth-2 {
margin-left: 40px;
}

.depth-3 {
margin-left: 60px;
}
}

.api-left-nav a, .mobile-menu a {
display: inline-block;
}

.api-left-nav .extension, .mobile-menu .extension {
&:before {
content: 'Inherited from ';
}
font-style: italic;
}

// The grid is too wide.
Expand Down
73 changes: 55 additions & 18 deletions website/js/api-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
});

self.setViewProperties(list);
var items = self.addTitleItems(list);

This comment has been minimized.

Copy link
@andresdominguez

andresdominguez Jul 1, 2015

Contributor

Can you add tests?

This comment has been minimized.

Copy link
@sjelin

sjelin Jul 7, 2015

Author Contributor
self.addExtends(list);
var items = self.organizeItems(list);

$scope.items = items;
$scope.version = data.version;
Expand All @@ -113,7 +114,6 @@
});
}

self.addExtends(list);
});
};

Expand All @@ -122,7 +122,7 @@
* @param list
*/
ApiCtrl.prototype.setViewProperties = function(list) {
var itemsByName = {};
var itemsByName = this.itemsByName = {};

var getTitle = function(item) {
if (item.alias) {
Expand Down Expand Up @@ -189,31 +189,64 @@
};

/**
* Add the title rows to the list.
* @param list
* @return {Array}
* Organize items according to class & inheritance, note every item's depth,
* and add file name items to the list.
*
* @param list The list of items
* @return {Array} A modified, reorganized list
*/
ApiCtrl.prototype.addTitleItems = function(list) {
var itemsPlusTitles = [],
prevFileName = null;
ApiCtrl.prototype.organizeItems = function(list) {
var newList = [];
var self = this;

list.forEach(function(item) {
if (prevFileName !== item.fileName) {
prevFileName = item.fileName;
itemsPlusTitles.push({
displayName: item.fileName,
isTitle: true,
type: 'title'
var addItemToList = function(item, depth) {
if (item.inList) {
console.log(item.name);
return;
}
item.treeClasses = 'depth-' + depth;
if (item.extension) {
item.treeClasses += ' extension';
depth--; // For the children
}
item.inList = true;
newList.push(item);
if (item.children) {
item.children.forEach(function(child) {
addItemToList(child, depth + 1);
});
}
if (item.extends) {
console.log(item.base.name);
var parent = self.itemsByName[item.base.name];
if (parent != null) {
addItemToList(parent, depth + 1);
}
}
};

var prevFileName;
list.forEach(function(item) {
if ((item.type !== 'child') && !item.extension) {
if (prevFileName !== item.fileName) {
prevFileName = item.fileName;
newList.push({
displayName: item.fileName,
isTitle: true,
type: 'title',
treeClasses: 'depth-0'
});
}

itemsPlusTitles.push(item);
addItemToList(item, 0);
}
});

return itemsPlusTitles;
return newList;
};

ApiCtrl.prototype.addExtends = function(list) {
var self = this;
list.forEach(function(item) {
if (!item.extends) {
return;
Expand All @@ -230,6 +263,10 @@
return item.name && item.name.match(nameExpr);
})
};

if (self.itemsByName[parentName]) {
self.itemsByName[parentName].extension = true;
}
});
};

Expand Down
6 changes: 6 additions & 0 deletions website/partials/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ <h3 id="title">Protractor API <small>{{::version}}</small></h3>
ng-switch="item.type">
<div ng-switch-when="title"
class="title"
ng-class="item.treeClasses"
ng-bind="item.displayName">
</div>
<span ng-switch-when="child">
<a href="#/api?view={{item.name}}"
class="child"
ng-class="item.treeClasses"
ng-bind="item.displayName"></a>
</span>
<div ng-switch-default class="parent">
<a href="#/api?view={{item.name}}"
ng-class="item.treeClasses"
ng-bind="item.title"></a>
</div>
</span>
Expand All @@ -57,15 +60,18 @@ <h3 id="title">Protractor API <small>{{::version}}</small></h3>
ng-switch="item.type">
<span ng-switch-when="title"
class="title"
ng-class="item.treeClasses"
ng-bind="item.displayName">
</span>
<a ng-switch-when="child"
href="#/api?view={{item.name}}"
class="child"
ng-class="item.treeClasses"
ng-bind="item.displayName">
</a>
<a ng-switch-default
href="#/api?view={{item.name}}"
ng-class="item.treeClasses"
ng-bind="item.title"></a>
</li>
</ul>
Expand Down

0 comments on commit 7e8d4fd

Please sign in to comment.