Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8fe77b6

Browse files
committed
refactor(docs): improved the visual rendering of the documentation pages
1 parent 1cc6bee commit 8fe77b6

File tree

5 files changed

+104
-39
lines changed

5 files changed

+104
-39
lines changed

docs/src/dom.js

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ DOM.prototype = {
7474
});
7575
},
7676

77+
div: function(attr, text) {
78+
this.tag('div', attr, text);
79+
},
80+
7781
h: function(heading, content, fn){
7882
if (content==undefined || (content instanceof Array && content.length == 0)) return;
7983
this.headingDepth++;

docs/src/ngdoc.js

+53-36
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,12 @@ Doc.prototype = {
222222
if (!match) {
223223
throw new Error("Not a valid 'property' format: " + text);
224224
}
225-
var property = {
225+
var property = new Doc({
226226
type: match[1],
227227
name: match[2],
228+
shortName: match[2],
228229
description: self.markdown(text.replace(match[0], match[4]))
229-
};
230+
});
230231
self.properties.push(property);
231232
} else if(atName == 'eventType') {
232233
match = text.match(/^([^\s]*)\s+on\s+([\S\s]*)/);
@@ -482,44 +483,60 @@ Doc.prototype = {
482483

483484
method_properties_events: function(dom) {
484485
var self = this;
485-
dom.h('Methods', this.methods, function(method){
486-
var signature = (method.param || []).map(property('name'));
487-
dom.h(method.shortName + '(' + signature.join(', ') + ')', method, function() {
488-
dom.html(method.description);
489-
method.html_usage_parameters(dom);
490-
self.html_usage_this(dom);
491-
method.html_usage_returns(dom);
492-
493-
dom.h('Example', method.example, dom.html);
494-
});
495-
});
496-
dom.h('Properties', this.properties, function(property){
497-
dom.h(property.shortName, function() {
498-
dom.html(property.description);
499-
dom.h('Example', property.example, dom.html);
500-
});
501-
});
502-
dom.h('Events', this.events, function(event){
503-
dom.h(event.shortName, event, function() {
504-
dom.html(event.description);
505-
if (event.type == 'listen') {
506-
dom.tag('div', {class:'inline'}, function() {
507-
dom.h('Listen on:', event.target);
508-
});
509-
} else {
510-
dom.tag('div', {class:'inline'}, function() {
511-
dom.h('Type:', event.type);
486+
if (self.methods.length) {
487+
dom.div({class:'member method'}, function(){
488+
dom.h('Methods', self.methods, function(method){
489+
var signature = (method.param || []).map(property('name'));
490+
dom.h(method.shortName + '(' + signature.join(', ') + ')', method, function() {
491+
dom.html(method.description);
492+
method.html_usage_parameters(dom);
493+
self.html_usage_this(dom);
494+
method.html_usage_returns(dom);
495+
496+
dom.h('Example', method.example, dom.html);
512497
});
513-
dom.tag('div', {class:'inline'}, function() {
514-
dom.h('Target:', event.target);
498+
});
499+
});
500+
}
501+
if (self.properties.length) {
502+
dom.div({class:'member property'}, function(){
503+
dom.h('Properties', self.properties, function(property){
504+
dom.h(property.shortName, function() {
505+
dom.html(property.description);
506+
if (!property.html_usage_returns) {
507+
console.log(property);
508+
}
509+
property.html_usage_returns(dom);
510+
dom.h('Example', property.example, dom.html);
515511
});
516-
}
517-
event.html_usage_parameters(dom);
518-
self.html_usage_this(dom);
512+
});
513+
});
514+
}
515+
if (self.events.length) {
516+
dom.div({class:'member event'}, function(){
517+
dom.h('Events', self.events, function(event){
518+
dom.h(event.shortName, event, function() {
519+
dom.html(event.description);
520+
if (event.type == 'listen') {
521+
dom.tag('div', {class:'inline'}, function() {
522+
dom.h('Listen on:', event.target);
523+
});
524+
} else {
525+
dom.tag('div', {class:'inline'}, function() {
526+
dom.h('Type:', event.type);
527+
});
528+
dom.tag('div', {class:'inline'}, function() {
529+
dom.h('Target:', event.target);
530+
});
531+
}
532+
event.html_usage_parameters(dom);
533+
self.html_usage_this(dom);
519534

520-
dom.h('Example', event.example, dom.html);
535+
dom.h('Example', event.example, dom.html);
536+
});
537+
});
521538
});
522-
});
539+
}
523540
},
524541

525542
parameters: function(dom, separator, skipFirst, prefix) {

docs/src/templates/docs.css

+36
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,42 @@ li {
5353
border: 1px solid red;
5454
}
5555

56+
.member {
57+
border: 1px solid gray;
58+
margin: 2em 0;
59+
}
60+
61+
.member p {
62+
padding: 0;
63+
}
64+
65+
.member>h2 {
66+
background-color: lightgray;
67+
padding: .2em .4em;
68+
margin: 0;
69+
border-bottom: 1px solid gray;
70+
}
71+
72+
.member>ul {
73+
list-style: none;
74+
padding: 0;
75+
}
76+
77+
.member>ul>li {
78+
border: 1px solid lightgray;
79+
margin: 1em;
80+
81+
}
82+
.member>ul>li>h3 {
83+
background-color: #EEE;
84+
padding: .2em .4em;
85+
margin: 0;
86+
font-family: monospace;
87+
border-bottom: 1px solid lightgray;
88+
}
89+
.member>ul>li>div {
90+
padding: 1em;
91+
}
5692

5793
/*----- Upgrade IE Prompt -----*/
5894

docs/src/templates/docs.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ function TutorialInstructionsCtrl($cookieStore) {
152152
window.angular = window.angular || {};
153153
angular.module = angular.module || {};
154154

155-
angular.module.ngdocs = function($locationProvider) {
155+
angular.module.ngdocs = function($locationProvider, $filterProvider) {
156156
$locationProvider.html5Mode(true).hashPrefix('!');
157+
158+
$filterProvider.register('title', function(){
159+
return function(text) {
160+
return text && text.replace(/^angular\.module\.([^\.]+)(\.(.*))?$/, function(_, module, _0, name){
161+
return 'Module ' + module + (name ? ' - ' + name : '');
162+
});
163+
}
164+
});
157165
};

docs/src/templates/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<head>
77
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
88
<meta name="fragment" content="!">
9-
<title ng:bind-template="AngularJS: {{partialTitle}}">AngularJS</title>
9+
<title ng:bind-template="AngularJS: {{partialTitle | title}}">AngularJS</title>
1010
<script type="text/javascript">
1111
// dynamically add base tag as well as css and javascript files.
1212
// we can't add css/js the usual way, because some browsers (FF) eagerly prefetch resources
@@ -115,7 +115,7 @@
115115

116116

117117
<div class="content-panel">
118-
<h2 ng:bind="partialTitle"></h2>
118+
<h2 ng:bind="partialTitle | title"></h2>
119119
<ng:include id="content"
120120
class="content-panel-content"
121121
src="getCurrentPartial()"

0 commit comments

Comments
 (0)