Skip to content

Commit

Permalink
Merge pull request #180 from SassDoc/add-prop-annotation
Browse files Browse the repository at this point in the history
Implement #25
  • Loading branch information
valeriangalliat committed Aug 24, 2014
2 parents dd07edd + b532e59 commit 893b3d3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/annotation/annotations/prop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var reqRegEx = /\s*(?:\{(.*)\})?\s*(?:(\$?[^\s]+))?\s*(?:\(([^\)]*)\))?\s*(?:-?\s*(.*?))\s*$/;

module.exports = {

parse: function (text) {
var match = reqRegEx.exec(text.trim());

var obj = {
type: match[1] || 'Map'
};

if (match[2]){
obj.name = match[2];
}

if (match[3]){
obj.default = match[3];
}

if (match[4]){
obj.description = match[4];
}

return obj;
}

};
41 changes: 41 additions & 0 deletions test/annotations/prop.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* global describe, it */
'use strict';

var assert = require('assert');

describe('#prop', function () {
var prop = require('../../src/annotation').prop;

it('should parse the prop annotation', function () {
assert.deepEqual(prop.parse('base'), {
type : 'Map',
name : 'base'
});

assert.deepEqual(prop.parse('{Function} base.default'), {
type : 'Function',
name : 'base.default'
});

assert.deepEqual(prop.parse('{Function} base.default - description'), {
type : 'Function',
name : 'base.default',
description : 'description'
});

assert.deepEqual(prop.parse('{Function} base.default (default) - description'), {
type : 'Function',
name : 'base.default',
default : 'default',
description : 'description'
});

assert.deepEqual(prop.parse('{Function} base.default (default) - description (with parens)'), {
type : 'Function',
name : 'base.default',
default : 'default',
description : 'description (with parens)'
});

});
});

0 comments on commit 893b3d3

Please sign in to comment.