-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from SassDoc/add-prop-annotation
Implement #25
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)' | ||
}); | ||
|
||
}); | ||
}); |