dgeni-packages
Advanced tools
Comparing version 0.2.4 to 0.3.0
var _ = require('lodash'); | ||
var log = require('winston'); | ||
var path = require('canonical-path'); | ||
var trimIndentation = require('dgeni/lib/utils/trim-indentation'); | ||
var code = require('dgeni/lib/utils/code'); | ||
var templateFolder, deployments; | ||
@@ -77,3 +75,3 @@ | ||
init: function(config, injectables) { | ||
exampleNames = {}; | ||
exampleNames = Object.create(null); | ||
@@ -80,0 +78,0 @@ deployments = config.get('deployment.environments'); |
@@ -5,3 +5,3 @@ var _ = require('lodash'); | ||
var trimIndentation = require('dgeni/lib/utils/trim-indentation'); | ||
var code = require('dgeni/lib/utils/code'); | ||
var marked = require('dgeni/lib/utils/marked'); | ||
@@ -16,3 +16,3 @@ var EXAMPLE_REGEX = /<example([^>]*)>([\S\s]+?)<\/example>/g; | ||
function extractAttributes(attributeText) { | ||
var attributes = {}; | ||
var attributes = Object.create(null); | ||
attributeText.replace(ATTRIBUTE_REGEX, function(match, prop, val1, val2){ | ||
@@ -25,3 +25,3 @@ attributes[prop] = val1 || val2; | ||
function extractFiles(exampleText) { | ||
var files = {}; | ||
var files = Object.create(null); | ||
exampleText.replace(FILE_REGEX, function(match, attributesText, contents) { | ||
@@ -74,9 +74,15 @@ var file = extractAttributes(attributesText); | ||
_.forEach(example.files, function(file) { | ||
html += ' <div class="runnable-example-file"'; | ||
html += '<div class="runnable-example-file"'; | ||
_.forEach(_.omit(file, ['fileContents']), function(value, key) { | ||
html += ' ' + key + '="' + value + '"'; | ||
}); | ||
html += '>\n'; | ||
html += code(file.fileContents, false, file.language) + '\n'; | ||
html += ' </div>\n'; | ||
html += '>\n\n'; | ||
// We need to convert the code as markdown to ensure that it is HTML encoded | ||
var code = '```' + (file.language || '') + '\n' + file.fileContents + '\n```\n\n'; | ||
// We must wrap the rendered HTML code in a div to ensure that it doesn't get parsed as markdown | ||
// a second time later. | ||
html += '\n\n<div>\n' + marked(code) + '\n</div>\n\n'; | ||
html += '</div>\n'; | ||
}); | ||
@@ -103,3 +109,3 @@ | ||
// Reset the unique name map | ||
exampleNames = {}; | ||
exampleNames = Object.create(null); | ||
@@ -106,0 +112,0 @@ injectables.value('examples', []); |
@@ -7,9 +7,10 @@ module.exports = function(config) { | ||
require('./processors/doc-extractor'), | ||
require('./processors/doctrine-tag-parser'), | ||
require('./processors/doctrine-tag-extractor'), | ||
require('./processors/tag-parser'), | ||
require('./processors/tag-extractor'), | ||
require('./processors/nunjucks-renderer'), | ||
require('./processors/escaped-comments'), | ||
require('./processors/write-files') | ||
]); | ||
config.append('processing.tagDefinitions', require('./tag-defs')); | ||
config.append('rendering.filters', [ | ||
@@ -16,0 +17,0 @@ require('./rendering/filters/dash-case'), |
@@ -49,3 +49,3 @@ var _ = require('lodash'); | ||
// Extract any extra helper functions/data from the config | ||
helpers = _.defaults({}, config.rendering.helpers); | ||
helpers = _.defaults(Object.create(null), config.rendering.helpers); | ||
}, | ||
@@ -63,3 +63,3 @@ /** | ||
try { | ||
data = _.defaults({}, { doc: doc, docs: docs }, extraData, helpers); | ||
data = _.defaults(Object.create(null), { doc: doc, docs: docs }, extraData, helpers); | ||
var templateFile = templateFinder(data.doc); | ||
@@ -66,0 +66,0 @@ doc.renderedContent = env.render(templateFile, data); |
var _ = require('lodash'); | ||
var logger = require('winston'); | ||
var tagDefs = require('../../tag-defs'); | ||
var MockTags = require('../mockTags.js'); | ||
var tagParser = require('../../processors/tag-parser'); | ||
var config = require('dgeni/lib/utils/config').Config; | ||
describe('tag definitions', function() { | ||
var doc, tags, tagDef; | ||
var getTagDef = function(name) { | ||
return _.find(tagDefs, { name: name }); | ||
}; | ||
function parseDoc(content) { | ||
var doc; | ||
config.set('processing.tagDefinitions', tagDefs); | ||
tagParser.init(config); | ||
beforeEach(function() { | ||
tags = new MockTags({ | ||
name: { title: 'name', description: 'someComponent' } | ||
}); | ||
doc = { | ||
basePath: '.', | ||
file: 'src/some.js', | ||
fileType: 'js', | ||
tags: tags | ||
}; | ||
}); | ||
if ( _.isString(content) ) { | ||
doc = { | ||
basePath: '.', | ||
file: 'src/some.js', | ||
fileType: 'js' | ||
}; | ||
doc.content = content; | ||
} else { | ||
doc = content; | ||
} | ||
tagParser.process([doc]); | ||
return doc; | ||
} | ||
function checkProperty(prop, name, description, typeList, isOptional, defaultValue, alias) { | ||
expect(prop.name).toEqual(name); | ||
expect(prop.description).toEqual(description); | ||
expect(prop.typeList).toEqual(typeList); | ||
if ( isOptional ) { | ||
expect(prop.optional).toBeTruthy(); | ||
} else { | ||
expect(prop.optional).toBeFalsy(); | ||
} | ||
expect(prop.defaultValue).toEqual(defaultValue); | ||
expect(prop.alias).toEqual(alias); | ||
} | ||
function doTransform(doc, tag) { | ||
var tagDef = tag.tagDef; | ||
return tagDef.transformFn(doc, tag); | ||
} | ||
function doDefault(doc, name) { | ||
var tagDef = _.find(tagDefs, { name: name }); | ||
return tagDef.defaultFn(doc); | ||
} | ||
describe("memberof", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('memberof'); | ||
}); | ||
it("should throw an exception if the tag exists and docType is not 'event', 'method' or 'property'", function() { | ||
var doc = parseDoc("@memberof container"); | ||
var tag = doc.tags.getTag('memberof'); | ||
expect(function() { | ||
tagDef.transformFn(doc, {}); | ||
tag.tagDef.transformFn(doc, tag); | ||
}).toThrow(); | ||
@@ -38,13 +63,14 @@ }); | ||
it("should throw an exception if the tag doesn't exist and docType is 'event', 'method' or 'property'", function() { | ||
var doc = parseDoc("empty content"); | ||
expect(function() { | ||
doc.docType = 'event'; | ||
tagDef.defaultFn(doc, {}); | ||
doDefault(doc, 'memberof'); | ||
}).toThrow(); | ||
expect(function() { | ||
doc.docType = 'property'; | ||
tagDef.defaultFn(doc, {}); | ||
doDefault(doc, 'memberof'); | ||
}).toThrow(); | ||
expect(function() { | ||
doc.docType = 'method'; | ||
tagDef.defaultFn(doc, {}); | ||
doDefault(doc, 'memberof'); | ||
}).toThrow(); | ||
@@ -55,49 +81,28 @@ }); | ||
describe("param", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('param'); | ||
}); | ||
it("should add param tags to a params array on the doc", function() { | ||
var param; | ||
var doc = parseDoc( | ||
"@param {string} paramName description of param\n" + | ||
"@param {string=} optionalParam description of optional param\n" + | ||
"@param {string} [optionalParam2] description of optional param\n" + | ||
"@param {string} [paramWithDefault=xyz] description of param with default\n" + | ||
"@param {string} paramName|alias description of param with alias\n" | ||
); | ||
doc.tags = new MockTags([ | ||
{ title: 'param', name: 'paramName', description: 'description of param', type: { description: 'string', optional: false, typeList: ['string'] } }, | ||
{ title: 'param', name: 'optionalParam', description: 'description of optional param', type: { description: 'string', optional: true, typeList: ['string'] } }, | ||
{ title: 'param', name: 'paramWithDefault', description: 'description of param with default', default: 'xyz', type: { description: 'string', optional: true, typeList: ['string'] } }, | ||
{ title: 'param', name: 'paramName', description: '|alias description of param with alias', type: { description: 'string', optional: false, typeList: ['string'] } } | ||
]); | ||
var paramTags = doc.tags.getTags('param'); | ||
param = tagDef.transformFn(doc, doc.tags.tags[0]); | ||
expect(param).toEqual( | ||
{ | ||
name: 'paramName', | ||
description: 'description of param', | ||
type: { description: 'string', optional: false, typeList: ['string'] } | ||
}); | ||
var param = doTransform(doc, paramTags[0]); | ||
checkProperty(param, 'paramName', 'description of param', ['string']); | ||
param = tagDef.transformFn(doc, doc.tags.tags[1]); | ||
expect(param).toEqual( | ||
{ | ||
name: 'optionalParam', | ||
description: 'description of optional param', | ||
type: { description: 'string', optional: true, typeList: ['string'] } | ||
}); | ||
param = doTransform(doc, paramTags[1]); | ||
checkProperty(param, 'optionalParam', 'description of optional param', ['string'], true); | ||
param = tagDef.transformFn(doc, doc.tags.tags[2]); | ||
expect(param).toEqual( | ||
{ | ||
name: 'paramWithDefault', | ||
description: 'description of param with default', | ||
type: { description: 'string', optional: true, typeList: ['string'] }, | ||
default: 'xyz' | ||
}); | ||
param = doTransform(doc, paramTags[2]); | ||
checkProperty(param, 'optionalParam2', 'description of optional param', ['string'], true); | ||
param = tagDef.transformFn(doc, doc.tags.tags[3]); | ||
expect(param).toEqual( | ||
{ | ||
name: 'paramName', | ||
description: 'description of param with alias', | ||
type: { description: 'string', optional: false, typeList: ['string'] }, | ||
alias: 'alias' | ||
}); | ||
param = doTransform(doc, paramTags[3]); | ||
checkProperty(param, 'paramWithDefault', 'description of param with default', ['string'], true, 'xyz'); | ||
param = doTransform(doc, paramTags[4]); | ||
checkProperty(param, 'paramName', 'description of param with alias', ['string'], false, undefined, 'alias'); | ||
}); | ||
@@ -108,19 +113,8 @@ }); | ||
describe("property", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('property'); | ||
}); | ||
it("should transform into a property object", function() { | ||
var tag = { | ||
title: 'property', | ||
name: 'propertyName', | ||
description: 'description of property', | ||
type: { description: 'string', optional: false, typeList: ['string'] } | ||
}; | ||
expect(tagDef.transformFn(doc, tag)).toEqual({ | ||
type: { description: 'string', optional: false, typeList: ['string'] }, | ||
name: 'propertyName', | ||
description: 'description of property' | ||
}); | ||
var doc = parseDoc("@property {string} propertyName description of property"); | ||
var tag = doc.tags.getTag('property'); | ||
var property = doTransform(doc, tag); | ||
checkProperty(property, 'propertyName', 'description of property', ['string']); | ||
}); | ||
@@ -132,17 +126,8 @@ | ||
describe("returns/return", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('returns'); | ||
}); | ||
it("should transform into a returns object", function() { | ||
expect(tagDef.transformFn(doc, { | ||
title: 'returns', | ||
type: { description: 'string', optional: false, typeList: ['string'] }, | ||
description: 'description of returns' | ||
})) | ||
.toEqual({ | ||
type: { description: 'string', optional: false, typeList: ['string'] }, | ||
description: 'description of returns' | ||
}); | ||
var doc = parseDoc("@returns {string} description of returns"); | ||
var tag = doc.tags.getTag('returns'); | ||
var returns = doTransform(doc, tag); | ||
checkProperty(returns, undefined, 'description of returns', ['string']); | ||
}); | ||
@@ -149,0 +134,0 @@ |
@@ -31,19 +31,6 @@ var checkProperty = require('dgeni/lib/utils/check-property'); | ||
docProperty: 'params', | ||
canHaveName: true, | ||
canHaveType: true, | ||
transformFn: function(doc, tag) { | ||
// doctrine doesn't support param name aliases | ||
var match = /^(?:\|(\S+)\s)?([\s\S]*)/.exec(tag.description); | ||
var alias = match[1]; | ||
var description = match[2]; | ||
var param = { | ||
name: tag.name, | ||
description: description, | ||
type: doc.tags.getType(tag), | ||
}; | ||
if (tag.default) { | ||
param.default = tag.default; | ||
} | ||
if (alias) { | ||
param.alias = alias; | ||
} | ||
return param; | ||
return tag; | ||
} | ||
@@ -57,8 +44,6 @@ }, | ||
docProperty: 'properties', | ||
canHaveName: true, | ||
canHaveType: true, | ||
transformFn: function(doc, tag) { | ||
return { | ||
type: doc.tags.getType(tag), | ||
name: tag.name, | ||
description: tag.description | ||
}; | ||
return tag; | ||
} | ||
@@ -71,10 +56,12 @@ }, | ||
aliases: ['return'], | ||
canHaveType: true, | ||
transformFn: function(doc, tag) { | ||
return { | ||
type: doc.tags.getType(tag), | ||
description: tag.description | ||
}; | ||
return tag; | ||
} | ||
}, | ||
{ | ||
name: 'requires', | ||
multi: true | ||
}, | ||
@@ -90,3 +77,4 @@ { name: 'module' }, | ||
{ name: 'namespace' }, | ||
{ name: 'kind' } | ||
{ name: 'kind' }, | ||
{ name: 'function' } | ||
]; |
@@ -11,3 +11,3 @@ var path = require('canonical-path'); | ||
config.set('processing.tagDefinitions', require('./tag-defs')); | ||
config.append('processing.tagDefinitions', require('./tag-defs')); | ||
@@ -14,0 +14,0 @@ config.append('processing.processors', [ |
@@ -9,3 +9,3 @@ var _ = require('lodash'); | ||
init: function(config, injectables) { | ||
injectables.value('moduleMap', {}); | ||
injectables.value('moduleMap', Object.create(null)); | ||
}, | ||
@@ -52,3 +52,3 @@ process: function(docs, partialNames, moduleMap) { | ||
containerDoc = partialNames.getDoc(doc.memberof); | ||
var containerDoc = partialNames.getDoc(doc.memberof); | ||
@@ -55,0 +55,0 @@ if ( !containerDoc ) { |
var plugin = require('../../processors/filter-ngdocs'); | ||
var MockTags = require('../MockTags'); | ||
var TagCollection = require('../../../jsdoc/lib/TagCollection'); | ||
var Tag = require('../../../jsdoc/lib/Tag'); | ||
function addTag(doc, name, description) { | ||
doc.tags.addTag({ tagDef: {name: name}, name: name, description: description}); | ||
} | ||
describe("filter-ngdocs doc-processor plugin", function() { | ||
it("should only return docs that have the ngdoc tag", function() { | ||
var docs = [ | ||
{ tags: new MockTags({ ngdoc: 'a' }) }, | ||
{ tags: new MockTags({ other: 'b' }) }, | ||
{ tags: new MockTags({ ngdoc: 'c' , other: 'd' }) }, | ||
{ tags: new MockTags([]) } | ||
]; | ||
var doc1 = { tags: new TagCollection() }; | ||
addTag(doc1, 'ngdoc', 'a'); | ||
var doc2 = { tags: new TagCollection() }; | ||
addTag(doc2, 'other', 'b'); | ||
var doc3 = { tags: new TagCollection() }; | ||
addTag(doc3, 'ngdoc', 'c'); | ||
addTag(doc3, 'other', 'd'); | ||
var doc4 = { tags: new TagCollection() }; | ||
var docs = [ doc1, doc2, doc3, doc4 ]; | ||
var filteredDocs = plugin.process(docs); | ||
expect(filteredDocs).toEqual([ | ||
{ tags: new MockTags({ ngdoc: 'a' }) }, | ||
{ tags: new MockTags({ ngdoc: 'c' , other: 'd' }) } | ||
]); | ||
expect(filteredDocs).toEqual([doc1, doc3]); | ||
}); | ||
}); |
var _ = require('lodash'); | ||
var logger = require('winston'); | ||
var tagDefs = require('../../tag-defs'); | ||
var MockTags = require('../mockTags.js'); | ||
var tagParser = require('../../../jsdoc/processors/tag-parser'); | ||
var config = require('dgeni/lib/utils/config').Config; | ||
describe('tag definitions', function() { | ||
var doc, tags, tagDef; | ||
var getTagDef = function(name) { | ||
return _.find(tagDefs, { name: name }); | ||
}; | ||
function parseDoc(content) { | ||
var doc; | ||
config.set('processing.tagDefinitions', tagDefs); | ||
tagParser.init(config); | ||
beforeEach(function() { | ||
tags = new MockTags({ | ||
ngdoc: { title: 'ngdoc', description: 'directive' }, | ||
name: { title: 'name', description: 'ngView' } | ||
}); | ||
doc = { | ||
basePath: '.', | ||
file: 'src/ngRoute/directive/ngView.js', | ||
fileType: 'js', | ||
tags: tags | ||
}; | ||
}); | ||
if ( _.isString(content) ) { | ||
doc = { | ||
basePath: '.', | ||
file: 'src/some.js', | ||
fileType: 'js' | ||
}; | ||
doc.content = content; | ||
} else { | ||
doc = content; | ||
} | ||
tagParser.process([doc]); | ||
return doc; | ||
} | ||
function checkProperty(prop, name, description, typeList, isOptional, defaultValue, alias) { | ||
expect(prop.name).toEqual(name); | ||
expect(prop.description).toEqual(description); | ||
expect(prop.typeList).toEqual(typeList); | ||
if ( isOptional ) { | ||
expect(prop.optional).toBeTruthy(); | ||
} else { | ||
expect(prop.optional).toBeFalsy(); | ||
} | ||
expect(prop.defaultValue).toEqual(defaultValue); | ||
expect(prop.alias).toEqual(alias); | ||
} | ||
function doTransform(doc, name) { | ||
var tag = doc.tags.getTag(name); | ||
var tagDef = tag.tagDef; | ||
return tagDef.transformFn(doc, tag); | ||
} | ||
function doDefault(doc, name) { | ||
var tagDef = _.find(tagDefs, { name: name }); | ||
return tagDef.defaultFn(doc); | ||
} | ||
describe("name", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('name'); | ||
}); | ||
it("should throw an error if the tag is missing", function() { | ||
var doc = { | ||
content: '' | ||
}; | ||
doc = parseDoc(doc, 0); | ||
expect(function() { | ||
tagDef.defaultFn(doc); | ||
doDefault(doc); | ||
}).toThrow(); | ||
@@ -39,15 +66,25 @@ }); | ||
it("should throw error if the docType is 'input' and the name is not a valid format", function() { | ||
var doc = { docType: 'input' }; | ||
var tag = { title: 'name', description: 'input[checkbox]' }; | ||
expect(tagDef.transformFn(doc, tag)).toEqual('input[checkbox]'); | ||
var doc = { | ||
docType: 'input', | ||
content: '@name input[checkbox]' | ||
}; | ||
doc = parseDoc(doc, 0); | ||
expect(doTransform(doc, 'name')).toEqual('input[checkbox]'); | ||
expect(doc.inputType).toEqual('checkbox'); | ||
doc = { docType: 'directive' }; | ||
tagDef.transformFn(doc, tag); | ||
doc = { | ||
docType: 'directive', | ||
content: '@name input[checkbox]' | ||
}; | ||
doc = parseDoc(doc, 0); | ||
expect(doTransform(doc, 'name')).toEqual('input[checkbox]'); | ||
expect(doc.inputType).toBeUndefined(); | ||
doc = { docType: 'input'}; | ||
tag = { title: 'name', description: 'invalidInputName' }; | ||
doc = { | ||
docType: 'input', | ||
content: '@name invalidInputName' | ||
}; | ||
doc = parseDoc(doc, 0); | ||
expect(function() { | ||
tagDef.transformFn(doc, tag); | ||
doTransform(doc, 'name'); | ||
}).toThrow(); | ||
@@ -61,14 +98,18 @@ | ||
describe("area", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('area'); | ||
}); | ||
it("should be 'api' if the fileType is js", function() { | ||
expect(tagDef.defaultFn(doc)).toEqual('api'); | ||
var doc = { | ||
content: '', | ||
fileType: 'js' | ||
}; | ||
expect(doDefault(doc, 'area')).toEqual('api'); | ||
}); | ||
it("should compute the area from the file name", function() { | ||
doc.fileType = 'ngdoc'; | ||
doc.file ='guide/scope/binding.ngdoc'; | ||
expect(tagDef.defaultFn(doc)).toEqual('guide'); | ||
var doc = { | ||
content: '', | ||
fileType: 'ngdoc', | ||
file: 'guide/scope/binding.ngdoc' | ||
}; | ||
expect(doDefault(doc, 'area')).toEqual('guide'); | ||
}); | ||
@@ -79,10 +120,9 @@ }); | ||
describe("module", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('module'); | ||
}); | ||
it("extracts the module from the file name if it is from the api area", function() { | ||
doc.area = 'api'; | ||
doc.file = 'src/ng/compile.js'; | ||
expect(tagDef.defaultFn(doc)).toEqual('ng'); | ||
var doc = { | ||
area: 'api', | ||
file: 'src/ng/compile.js', | ||
content: '' | ||
}; | ||
expect(doDefault(doc, 'module')).toEqual('ng'); | ||
}); | ||
@@ -92,22 +132,23 @@ }); | ||
describe("id", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('id'); | ||
}); | ||
describe("(for api docs)", function() { | ||
it("should compute the id from other properties", function() { | ||
doc.docType = 'service'; | ||
doc.name = '$http'; | ||
doc.area = 'api'; | ||
doc.module = 'ngRoute'; | ||
expect(tagDef.defaultFn(doc)).toEqual('module:ngRoute.service:$http'); | ||
var doc = { | ||
docType: 'service', | ||
name: '$http', | ||
area: 'api', | ||
module: 'ngRoute' | ||
}; | ||
expect(doDefault(doc, 'id')).toEqual('module:ngRoute.service:$http'); | ||
}); | ||
it("should extract the container and member from the name if it is a memberOf type", function() { | ||
doc.docType = 'method'; | ||
doc.name = '$http#get'; | ||
doc.area = 'api'; | ||
doc.module = 'ng'; | ||
var doc = { | ||
docType: 'method', | ||
name: '$http#get', | ||
area: 'api', | ||
module: 'ng' | ||
}; | ||
expect(tagDef.defaultFn(doc)).toEqual('$http#get'); | ||
expect(doDefault(doc, 'id')).toEqual('$http#get'); | ||
expect(doc.name).toEqual('get'); | ||
@@ -121,98 +162,21 @@ expect(doc.memberof).toEqual('$http'); | ||
describe("param", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('param'); | ||
}); | ||
it("should add param tags to a params array on the doc", function() { | ||
var param; | ||
doc.tags = new MockTags([ | ||
{ title: 'param', name: 'paramName', description: 'description of param', type: { description: 'string', optional: false, typeList: ['string'] } }, | ||
{ title: 'param', name: 'optionalParam', description: 'description of optional param', type: { description: 'string', optional: true, typeList: ['string'] } }, | ||
{ title: 'param', name: 'paramWithDefault', description: 'description of param with default', default: 'xyz', type: { description: 'string', optional: true, typeList: ['string'] } }, | ||
{ title: 'param', name: 'paramName', description: '|alias description of param with alias', type: { description: 'string', optional: false, typeList: ['string'] } } | ||
]); | ||
param = tagDef.transformFn(doc, doc.tags.tags[0]); | ||
expect(param).toEqual( | ||
{ | ||
name: 'paramName', | ||
description: 'description of param', | ||
type: { description: 'string', optional: false, typeList: ['string'] } | ||
}); | ||
param = tagDef.transformFn(doc, doc.tags.tags[1]); | ||
expect(param).toEqual( | ||
{ | ||
name: 'optionalParam', | ||
description: 'description of optional param', | ||
type: { description: 'string', optional: true, typeList: ['string'] } | ||
}); | ||
param = tagDef.transformFn(doc, doc.tags.tags[2]); | ||
expect(param).toEqual( | ||
{ | ||
name: 'paramWithDefault', | ||
description: 'description of param with default', | ||
type: { description: 'string', optional: true, typeList: ['string'] }, | ||
default: 'xyz' | ||
}); | ||
param = tagDef.transformFn(doc, doc.tags.tags[3]); | ||
expect(param).toEqual( | ||
{ | ||
name: 'paramName', | ||
description: 'description of param with alias', | ||
type: { description: 'string', optional: false, typeList: ['string'] }, | ||
alias: 'alias' | ||
}); | ||
}); | ||
}); | ||
describe("property", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('property'); | ||
}); | ||
it("should transform into a property object", function() { | ||
var tag = { | ||
title: 'property', | ||
name: 'propertyName', | ||
description: 'description of property', | ||
type: { description: 'string', optional: false, typeList: ['string'] } | ||
}; | ||
expect(tagDef.transformFn(doc, tag)).toEqual({ | ||
type: { description: 'string', optional: false, typeList: ['string'] }, | ||
name: 'propertyName', | ||
description: 'description of property' | ||
}); | ||
}); | ||
}); | ||
describe("restrict", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('restrict'); | ||
}); | ||
it("should convert a restrict tag text to an object", function() { | ||
expect(tagDef.transformFn(doc, { title: 'restrict', description: 'A' })) | ||
expect(doTransform(parseDoc('@restrict A'), 'restrict')) | ||
.toEqual({ element: false, attribute: true, cssClass: false, comment: false }); | ||
expect(tagDef.transformFn(doc, { title: 'restrict', description: 'C' })) | ||
expect(doTransform(parseDoc('@restrict C'), 'restrict')) | ||
.toEqual({ element: false, attribute: false, cssClass: true, comment: false }); | ||
expect(tagDef.transformFn(doc, { title: 'restrict', description: 'E' })) | ||
expect(doTransform(parseDoc('@restrict E'), 'restrict')) | ||
.toEqual({ element: true, attribute: false, cssClass: false, comment: false }); | ||
expect(tagDef.transformFn(doc, { title: 'restrict', description: 'M' })) | ||
expect(doTransform(parseDoc('@restrict M'), 'restrict')) | ||
.toEqual({ element: false, attribute: false, cssClass: false, comment: true }); | ||
expect(tagDef.transformFn(doc, { title: 'restrict', description: 'ACEM' })) | ||
expect(doTransform(parseDoc('@restrict ACEM'), 'restrict')) | ||
.toEqual({ element: true, attribute: true, cssClass: true, comment: true }); | ||
@@ -222,9 +186,8 @@ }); | ||
it("should default to restricting to an attribute if no tag is found and the doc is for a directive", function() { | ||
doc.docType = 'directive'; | ||
expect(tagDef.defaultFn(doc)).toEqual({ element: false, attribute: true, cssClass: false, comment: false }); | ||
expect(doDefault({ docType: 'directive' }, 'restrict')) | ||
.toEqual({ element: false, attribute: true, cssClass: false, comment: false }); | ||
}); | ||
it("should not add a restrict property if the doc is not a directive", function() { | ||
doc.docType = ''; | ||
expect(doc.restrict).toBeUndefined(); | ||
it("should not add a restrict property if the docType is not 'directive'", function() { | ||
expect(doDefault({ docType: 'other' }, 'restrict')).toBeUndefined(); | ||
}); | ||
@@ -234,32 +197,7 @@ }); | ||
describe("returns/return", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('returns'); | ||
}); | ||
it("should transform into a returns object", function() { | ||
expect(tagDef.transformFn(doc, { | ||
title: 'returns', | ||
type: { description: 'string', optional: false, typeList: ['string'] }, | ||
description: 'description of returns' | ||
})) | ||
.toEqual({ | ||
type: { description: 'string', optional: false, typeList: ['string'] }, | ||
description: 'description of returns' | ||
}); | ||
}); | ||
}); | ||
describe("eventType", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('eventType'); | ||
}); | ||
it("should add an eventTarget property to the doc and return the event type", function() { | ||
var tag = { title: 'eventType', description: 'broadcast on module:ng.directive:ngInclude' }; | ||
expect(tagDef.transformFn(doc, tag)).toEqual('broadcast'); | ||
var doc = parseDoc('@eventType broadcast on module:ng.directive:ngInclude'); | ||
expect(doTransform(doc, 'eventType')).toEqual('broadcast'); | ||
expect(doc.eventTarget).toEqual('module:ng.directive:ngInclude'); | ||
@@ -271,12 +209,6 @@ }); | ||
describe("element", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('element'); | ||
}); | ||
it("should default to ANY if the document is a directive", function() { | ||
doc.docType = 'directive'; | ||
expect(tagDef.defaultFn(doc)).toEqual('ANY'); | ||
doc.docType = 'filter'; | ||
expect(tagDef.defaultFn(doc)).toBeUndefined(); | ||
expect(doDefault({ docType: 'directive' }, 'element')).toEqual('ANY'); | ||
expect(doDefault({ docType: 'filter' }, 'element')).toBeUndefined(); | ||
}); | ||
@@ -286,9 +218,2 @@ }); | ||
describe("requires", function() { | ||
beforeEach(function() { | ||
tagDef = getTagDef('requires'); | ||
}); | ||
}); | ||
}); |
@@ -105,41 +105,2 @@ var checkProperty = require('dgeni/lib/utils/check-property'); | ||
{ | ||
name: 'param', | ||
multi: true, | ||
docProperty: 'params', | ||
transformFn: function(doc, tag) { | ||
// doctrine doesn't support param name aliases | ||
var match = /^(?:\|(\S+)\s)?([\s\S]*)/.exec(tag.description); | ||
var alias = match[1]; | ||
var description = match[2]; | ||
var param = { | ||
name: tag.name, | ||
description: description, | ||
type: doc.tags.getType(tag), | ||
}; | ||
if (tag.default) { | ||
param.default = tag.default; | ||
} | ||
if (alias) { | ||
param.alias = alias; | ||
} | ||
return param; | ||
} | ||
}, | ||
{ | ||
name: 'property', | ||
multi: true, | ||
docProperty: 'properties', | ||
transformFn: function(doc, tag) { | ||
return { | ||
type: doc.tags.getType(tag), | ||
name: tag.name, | ||
description: tag.description | ||
}; | ||
} | ||
}, | ||
{ | ||
name: 'restrict', | ||
@@ -163,14 +124,2 @@ defaultFn: function(doc) { | ||
{ | ||
name: 'returns', | ||
aliases: ['return'], | ||
transformFn: function(doc, tag) { | ||
return { | ||
type: doc.tags.getType(tag), | ||
description: tag.description | ||
}; | ||
} | ||
}, | ||
{ | ||
name: 'eventType', | ||
@@ -209,7 +158,2 @@ transformFn: function(doc, tag) { | ||
{ | ||
name: 'requires', | ||
multi: true | ||
}, | ||
{ | ||
name: 'scope', | ||
@@ -227,12 +171,2 @@ transformFn: function(doc, tag) { return true; } | ||
{ name: 'description' }, | ||
{ name: 'usage' }, | ||
{ name: 'animations' }, | ||
{ name: 'constructor' }, | ||
{ name: 'class' }, | ||
{ name: 'classdesc' }, | ||
{ name: 'global' }, | ||
{ name: 'namespace' }, | ||
{ name: 'kind' } | ||
]; |
@@ -82,3 +82,3 @@ var _ = require('lodash'); | ||
function PartialNames(docs) { | ||
this.map = {}; | ||
this.map = Object.create(null); | ||
that = this; | ||
@@ -85,0 +85,0 @@ _.forEach(docs, function(doc) { |
{ | ||
"name": "dgeni-packages", | ||
"version": "0.2.4", | ||
"version": "0.3.0", | ||
"description": "A collection of dgeni packages for generating documentation from source code", | ||
"scripts": { | ||
"test": "node ./node_modules/jasmine-node/bin/jasmine-node ngdoc/spec jsdoc/spec examples/spec" | ||
"test": "node ./node_modules/jasmine-node/bin/jasmine-node ngdoc/spec jsdoc/spec examples/spec", | ||
"cover": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node -- ngdoc/spec jsdoc/spec examples/spec" | ||
}, | ||
@@ -34,5 +35,3 @@ "repository": { | ||
"lodash": "~2.4.1", | ||
"dgeni": "~0.1.0", | ||
"winston": "~0.7.2", | ||
"doctrine": "~0.3.0", | ||
"graceful-fs": "~2.0.1", | ||
@@ -42,4 +41,8 @@ "q": "~1.0.0", | ||
"q-io": "~1.10.9", | ||
"nunjucks": "~1.0.1" | ||
"nunjucks": "~1.0.1", | ||
"catharsis": "^0.7.0" | ||
}, | ||
"peerDependencies": { | ||
"dgeni": "~0.2.0" | ||
}, | ||
"devDependencies": { | ||
@@ -46,0 +49,0 @@ "rewire": "~2.0.0", |
@@ -21,4 +21,4 @@ # Dgeni Packages | ||
from jsdoc style comments in files. | ||
* `doctrine-tag-parser` - uses the Doctrine library to parse the jsdoc tags in the extracted documents. | ||
* `doctrine-tag-extractor` - extracts the tags information and converts it to specific properties on | ||
* `tag-parser` - parses the jsdoc tags in the extracted documents. | ||
* `tag-extractor` - extracts the tags information and converts it to specific properties on | ||
the documents, based on a set of tag-definitions. The `jsdoc` package contains definitions for the | ||
@@ -25,0 +25,0 @@ following tags: `name`, `memberof`, `param`, `property`, `returns`, `module`, `description`, `usage`, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
136993
106
3070
+ Addedcatharsis@^0.7.0
+ Addedcatharsis@0.7.1(transitive)
+ Addeddgeni@0.2.2(transitive)
- Removeddgeni@~0.1.0
- Removeddoctrine@~0.3.0
- Removeddgeni@0.1.1(transitive)
- Removeddoctrine@0.3.0(transitive)