Skip to content

Commit

Permalink
Fixed bug with names["quoted"]. Tweaks to default template.
Browse files Browse the repository at this point in the history
  • Loading branch information
micmath committed Jan 3, 2011
1 parent 1d18f39 commit 6d4c1e6
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 43 deletions.
26 changes: 19 additions & 7 deletions modules/jsdoc/docset.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@
}

DocSet.prototype.getByLongname = function(longname) {
var found = [];
for (var i = 0, l = this.doclets.length; i < l; i++) {
if (this.doclets[i].longname === longname) {
found.push(this.doclets[i]);
}
}
return found;
return this.doclets.filter(function(doclet) {
return doclet.longname === longname;
});
}

DocSet.prototype.getByMemberof = function(memberof) {
return this.doclets.filter(function(doclet) {
return doclet.memberof === memberof;
});
}

DocSet.prototype.sortByLongname = function() {
this.doclets.sort(function(a, b) {
if(a.longname == b.longname) {
return 0;
}

return (a.longname < b.longname)? -1 : 1;
});
}

})();
12 changes: 9 additions & 3 deletions modules/jsdoc/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@
exports.shorten = function(longname) {
//// quoted strings in a longname are atomic, convert to tokens
var atoms = [], token;
longname = longname.replace(/(".*?")/g, function($) {

// handle quoted names like foo["bar"]
longname = longname.replace(/(\[?".*?"\]?)/g, function($) {
$ = $.replace(/^\[/g, '.').replace(/\]$/g, '');

token = '@{' + atoms.length + '}@';
atoms.push($);
return token;
Expand All @@ -107,11 +111,13 @@
//// restore quoted strings back again
var i = atoms.length;
while (i--) {
longname = longname.replace('@{'+i+'}@', atoms[i]);
memberof = memberof.replace('@{'+i+'}@', atoms[i]);
name = name.replace('@{'+i+'}@', atoms[i]);
scope = scope.replace('@{'+i+'}@', atoms[i]);
name = name.replace('@{'+i+'}@', atoms[i]);
}
////

return {longname: longname, memberof: memberof, scope: scope, name: name};
}
})();
15 changes: 13 additions & 2 deletions modules/jsdoc/tag/dictionary/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
});

dictionary.defineTag('file', {
keepsWhitespace: true,
mustHaveValue: true,
onTagged: function(doclet, tag) {
setNameToFile(doclet, tag);
setDocletKindToTitle(doclet, tag);
applyNamespace(doclet, tag);
setDocletDescriptionToValue(doclet, tag);

doclet.preserveName = true;

Expand Down Expand Up @@ -175,7 +175,12 @@
});

dictionary.defineTag('private', {
mustNotHaveValue: true
mustNotHaveValue: true,
onTagged: function(doclet, tag) {
doclet.access = 'private';

return true;
}
});

dictionary.defineTag('property', {
Expand Down Expand Up @@ -224,6 +229,12 @@
}
}

function setDocletDescriptionToValue(doclet, tag) {
if (tag.value) {
doclet.addTag( 'description', tag.value );
}
}

function setNameToFile(doclet, tag) {
if (doclet.meta.filename) { doclet.addTag( 'name', 'file:'+doclet.meta.filename ); }
}
Expand Down
2 changes: 2 additions & 0 deletions templates/default/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
return !doclet.undocumented;
});

docSet.sortByLongname();

// apply template
out = Mustache.to_html(
templates.index,
Expand Down
36 changes: 31 additions & 5 deletions templates/default/tmpl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,45 @@
<head>
<meta charset="utf-8">
<title>JSDoc Index</title>
<style type="text/css">
.kind { font-style: italic; }
.constructor
{
font-weight: bold;
color: #780000;
}

.namespace { color: #780000; }
.property { color: #999; }
.function { color: #999; }

.access { color: #999; }

dt
{
margin-top: 8px;
margin-bottom: 4px;
border-top: 1px solid #ccc;
font-size: 110%;
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Verdana, Tahoma, sans-serif;
}
</style>
</head>

<body>

<h1>All Symbols</h1>

<ul>
<dl>
{{#docs}}
<li class="symbol">
<i>{{kind}}</i> {{longname}}{{#description}} - {{#summarize}}{{{description}}}{{/summarize}}{{/description}}
</li>
<dt class="symbol">
{{#kind}}<span class="kind {{kind}}">{{kind}}</span> {{/kind}}{{#access}}<span class="access {{access}}">&lt;{{access}}></span> {{/access}}{{longname}}
</dt>
{{#description}}<dd>
{{#summarize}}{{{description}}}{{/summarize}}
</dd>{{/description}}
{{/docs}}
</ul>
</dl>

</body>
</html>
17 changes: 17 additions & 0 deletions test/cases/quotename.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
@namespace
@name chat."#channel"
*/
chat["#channel"] = {};


/**
@property
@type {boolean}
@name chat."#channel".open
*/
chat["#channel"].open = true;

/**
@event chat."#channel"."op:announce-motd"
*/
51 changes: 25 additions & 26 deletions test/samples/jsdoc_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @fileoverview This file is to be used for testing the JSDoc parser
* @fileoverview This file is to be used for testing the JSDoc parser.
* It is not intended to be an example of good JavaScript OO-programming,
* nor is it intended to fulfill any specific purpose apart from
* demonstrating the functionality of the
Expand Down Expand Up @@ -58,8 +58,8 @@ geometry.util.ShapeFactory.prototype = {
geometry.Shape = function(template){

/**
* This is an example of a function that is not given as a property
* of a prototype, but instead it is assigned within a constructor.
* This is an example of a function that is a `this` property.
* Not of a prototype, instead it is assigned within a constructor.
* For inner functions like this to be picked up by the parser, the
* function that acts as a constructor *must* be denoted with
* the `@constructor` tag in its comment.
Expand All @@ -71,7 +71,7 @@ geometry.Shape = function(template){
}

/**
* This is an inner method, just used here as an example
* This is an inner method, just used here as an example.
* @private
* @since version 0.5
* @author Sue Smart
Expand Down Expand Up @@ -102,7 +102,7 @@ geometry.Hexagon = function(sideLength) {


/**
* This is an unattached (static) function that adds two integers together using {@link geometry.Shape#getClassName}.
* This is a global function that adds two integers together using {@link geometry.Shape#getClassName}.
* @function
* @param {int} One The first number to add
* @param {int} Two The second number to add
Expand All @@ -115,7 +115,7 @@ function Add(One, Two){


/**
* The color of this shape
* The color of this shape.
* @property
* @type {string|Color}
*/
Expand Down Expand Up @@ -179,7 +179,7 @@ geometry.Shape.prototype.setColor = function(color){
}

/**
* Clone this shape
* Clone this shape.
* @method
* @returns A copy of this shape
* @type geometry.Shape
Expand Down Expand Up @@ -222,14 +222,14 @@ geometry.Rectangle.prototype = new geometry.Shape();
* @private
* @type int
*/
geometry.Rectangle.prototype.width = 0;
geometry.Rectangle.prototype._width = 0;

/**
* Value to represent the height of the Rectangle
* Value to represent the height of the Rectangle.
* @private
* @type int
*/
geometry.Rectangle.prototype.height = 0;
geometry.Rectangle.prototype._height = 0;

/**
* Get the type of this object.
Expand All @@ -240,7 +240,7 @@ geometry.Rectangle.prototype.getClassName= function(){
}

/**
* Get the value of the width for the Rectangle
* Get the value of the width for the Rectangle.
* @type int
* @see geometry.Rectangle#setWidth
*/
Expand Down Expand Up @@ -279,7 +279,7 @@ geometry.Rectangle.prototype.setHeight = function(height){
}

/**
* Get the value for the total area of this Rectangle
* Get the value for the total area of this Rectangle.
* @return total area of this Rectangle
* @type int
*/
Expand Down Expand Up @@ -318,7 +318,7 @@ geometry.Square.prototype.setWidth = function(width){
}

/**
* Set the height value for this Shape
* Set the height value for this Shape.
* Sets the {@link geometry.Rectangle#height} attribute in the Rectangle.
* @param {int} height The height value to be set
*/
Expand Down Expand Up @@ -349,21 +349,21 @@ geometry.Circle = function(radius){
geometry.Circle.prototype = new geometry.Shape();

/**
* The radius value for this Circle
* The radius value for this Circle.
* @private
* @type int
*/
geometry.Circle.prototype.radius = 0;

/**
* A very simple class (static) field that is also a constant
* A field that is also a constant.
* @const
* @type float
*/
geometry.Circle.PI = 3.14;

/**
* Get the radius value for this Circle
* Get the radius value for this Circle.
* @type int
* @see #setRadius
*/
Expand All @@ -372,7 +372,7 @@ geometry.Circle.prototype.getRadius = function(){
}

/**
* Set the radius value for this Circle
* Set the radius value for this Circle.
* @param {int} radius The {@link geometry.Circle#radius} value to set
* @see #getRadius
*/
Expand All @@ -386,8 +386,8 @@ geometry.Circle.prototype.setRadius = function(radius){
geometry.Circle.prototype.setDiameter = geometry.Square.prototype.setWidth;

/**
* An example of a class (static) method that acts as a factory for Circle
* objects. Given a radius value, this method creates a new Circle.
* An example of a class (static) method that acts as a factory for Circle objects.
* Given a radius value, this method creates a new Circle.
* @param {int} radius The radius value to use for the new Circle.
* @type geometry.Circle
*/
Expand All @@ -412,15 +412,15 @@ geometry.Coordinate = function(x, y){
}

/**
* The x portion of the Coordinate
* The x portion of the Coordinate.
* @type {int}
* @see #getX
* @see #setX
*/
geometry.Coordinate.prototype.x = 0;

/**
* The y portion of the Coordinate
* The y portion of the Coordinate.
* @type int
* @see #getY
* @see #setY
Expand Down Expand Up @@ -464,14 +464,14 @@ geometry.Coordinate.prototype.setY = function(y){
}

/**
* An example of a singleton class
* An example of a singleton class.
* @param ... Arguments represent {@link coordinate}s in the shape.
* @constructor
*/
MySingletonShapeFactory = function(){

/**
* Get the next {@link geometry.Shape}
* Get the next {@link geometry.Shape}.
* @type geometry.Shape
* @return A new {@link geometry.Shape}
*/
Expand All @@ -490,8 +490,7 @@ MySingletonShapeFactory = function(){
function Foo(){}

/**
* Nested class
* @public
* Nested class.
* @constructor
*/
Foo.Bar = function(){
Expand All @@ -507,7 +506,7 @@ Foo.Bar.prototype.y = '3';
* @private
* @this {geometry.Circle}
*/
function getArea() {
function _getArea() {
}

// see http://www.integralist.co.uk/javascript/implementing-interfaces-in-javascript/
Expand Down

0 comments on commit 6d4c1e6

Please sign in to comment.