dgeni-packages
Advanced tools
Comparing version 0.8.3 to 0.9.0
104
CHANGELOG.md
@@ -1,7 +0,105 @@ | ||
## v0.8.3 04/23/2014 | ||
## v0.9.0 05/01/2014 | ||
This is a major refactoring release which is compatible with Dgeni v0.3.x. There | ||
are many breaking changes. | ||
### New Packages | ||
The packages have been refactored into smaller more focussed sets of processors. | ||
* base - The minimal set of processors to get started with Dgeni | ||
* jsdoc - Tag parsing and extracting | ||
* nunjucks - The nunjucks template rendering engine. No longer in jsdoc - you must add this | ||
explicitly to your config or you will get | ||
`Error: No provider for "templateEngine"! (Resolving: templateEngine)` | ||
* ngdoc - The angular.js specific tag-defs, processors and templates. This loads the jsdoc and | ||
nunjucks packages for you. | ||
* examples - Processors to support the runnable examples feature in the angular.js docs site. | ||
### New Processor Exports | ||
With Dgeni 0.3.0 processors can declaratively export services to be injected into processors' | ||
`process()` method. This release take full advantage of this, refactoring the structure of the | ||
dependencies of various processors to simplify and enable more flexibility. | ||
### New Tag Definition Transforms | ||
Previously processing of tags was somewhat distributed between the tagParser and the tagExtractor, | ||
with various features rather hard-coded, such as `canHaveType` and `canHaveName`. This has all been | ||
moved into **tag definition transforms**, which provide a much more flexible and powerful way to | ||
define how to transform the simple text "parsed" from the tag into a rich object that can be | ||
attached to the document. | ||
### Detailed List of Changes | ||
**Features** | ||
* feat(jsdoc/tag-defs): add `@type` tag 904aa00b | ||
* feat(jsdoc/tag-defs): add `@method` tag 6fc99313 | ||
* feat(jsdoc file-reader): add more code metadata 7820317a | ||
* feat(jsdoc/name-from-code): extract the name of the doc from the code 1115c431 | ||
**Refactorings** | ||
* refact(ngdoc/tag-defs): use new tagExtractor syntax b0848557 | ||
* refact(jsdoc/tag-defs): use new tagExtractor syntax 0048547e | ||
* refact(extract-tags processor): rename and use tagExtractor d2ef2237 | ||
* refact(tagExtractor): major reworking to use 'transformFns' a90734ae | ||
* refact(parse-tags): simplify using tagParser 02cc093d | ||
* refact(tagParser): move into its own processor 1d2e689e | ||
* refact(tagDefinitions): move into its own processor d2d916ef | ||
* refact(defaultTagTransforms): move into its own processor 354a9489 | ||
* refact(tag-def/transforms): convert "tagProcessors" into tag "transforms" d4ca4e94 | ||
* refact(nunjucks): move basic filters and tags to nunjucks package 5547409c | ||
* refact(dash-case): change name to change-case 39ab9be1 | ||
* refact(walk): remove unused code 66f86a50 | ||
* refact(marked): remove unused code 4591bd90 | ||
* refact(doc-writer): remove unused code 41c0cd12 | ||
* refact(dash-case): remove unused code 8f9dd805 | ||
* refact(check-property): remove unused code 6e39ba70 | ||
* refact(code-name): move to jsdoc package 4061e64f | ||
* refact(packages): align with renames and moves of processors a21f804e | ||
* refact(doc-extractor): complete rename to read-files 8bc760bf | ||
* refact(escaped-comments): rename to unescape-comments d030ca95 | ||
* refact(rendering): move nunjucks stuff out 0b36e95a | ||
* refact(code-name): rename 6e312504 | ||
* refact(doc-extractor): rename to read-files 60ac908c | ||
* refact(partial-names processor): remove `init` and provide `exports` 0de2680a | ||
* refact(component-groups-generate processor): remove `init` and provide `exports` 61ba9cb1 | ||
* refact(api-docs processor): remove `init` and provide `exports` 34d05b1f | ||
* refact(jsdoc processors): remove `init` and provide `exports` 3188ff14 | ||
* refact(examples-parse): remove `init` and provide `exports` 5cbcbab6 | ||
* refact(examples-generate): remove `init` and provide `exports` 0c006bb4 | ||
* refact(nunjucks-renderer): remove `init` and provide `exports` f4b42dd6 | ||
* refact(doc-extractor): remove `init` and provide `exports` fce833c9 | ||
* refact(*): update due to utils move 0245eb22 | ||
* refact(utils): moved here from dgeni 1f04843d | ||
* refact(jsdoc): moved stuff to base package 5f2ec6be | ||
**Bug Fixes** | ||
* fix(ngdoc): don't show first param in filter syntax 9c5a7f26 | ||
* fix(jsdoc): fix typo in error message b1e7dd08 | ||
* fix(tagExtractor): invalid injectable parameter name 6c8790f3 | ||
* fix(jsdoc): add defaultTagTransforms and tagExtractor processors 12ac7aa0 | ||
* fix(jsdoc): tag-extractor processor was renamed 1931f4d4 | ||
* fix(tagExtractor): accidental global vars 5de56780 | ||
* fix(extract-type transform): ensure tag.description gets updated 0f911d8a | ||
* fix(extract-name transform): ensure tag.description gets updated e347c847 | ||
* fix(tagDefinitions): throw error if tag definitions are missing from the config 4777ec79 | ||
* fix(nunjucks): correctly load up the template engine processor 071e52c7 | ||
* fix(base processors): minor fixes to get the tests working efd3e35f | ||
* fix(link inline tag): parse newlines in link's title b2ebb415 | ||
* fix(ngdoc): don't show first param in filter syntax 4f2ccf52 | ||
* fix(walk): hack ancestor to kind of do what I want f19b6940 | ||
* fix(compute-path): ensure it runs early enough fe1e0bd7 | ||
* fix(jsdoc package): actually append processors to config f2020d47 | ||
* fix(marked tag): fix path to trim-indentation module 1206f8fe | ||
* fix(nunjucks-renderer): `env` changed to `templateEngine` e4a756e0 | ||
* fix(base package): load change-case filter locally a74f2ee4 | ||
* fix(compute-paths): ensure it is run before rendering b50baa99 | ||
* fix(jsdoc/tag-defs): Allow multiple `@see` tags d73a842f | ||
* fix(tag-parser): don't overwrite default tag processors collection 9fc7f58e | ||
* fix(code): fix path to utilities 26c26e70 | ||
* fix(examples-parse): fix path to utilities 1f9d1488 | ||
* fix(jsdoc/tag-defs): missing comma 293ffde2 | ||
* fix(jsdoc): fix typo in error message b1e7dd08 | ||
@@ -8,0 +106,0 @@ |
@@ -108,3 +108,3 @@ var _ = require('lodash'); | ||
runBefore: ['extra-docs-added'], | ||
init: function(config, injectables) { | ||
process: function(docs, examples, config) { | ||
@@ -117,4 +117,3 @@ deployments = config.get('deployment.environments'); | ||
templateFolder = config.get('processing.examples.templateFolder', 'examples'); | ||
}, | ||
process: function(docs, examples) { | ||
_.forOwn(examples, function(example) { | ||
@@ -121,0 +120,0 @@ |
var _ = require('lodash'); | ||
var log = require('winston'); | ||
var path = require('canonical-path'); | ||
var trimIndentation = require('dgeni/lib/utils/trim-indentation'); | ||
var marked = require('dgeni/lib/utils/marked'); | ||
var trimIndentation = require('../../utils/trim-indentation'); | ||
var marked = require('marked'); | ||
@@ -11,4 +11,2 @@ var EXAMPLE_REGEX = /<example([^>]*)>([\S\s]+?)<\/example>/g; | ||
// A holder for all the examples that have been found in the document | ||
var outputFolder; | ||
@@ -57,14 +55,11 @@ function extractAttributes(attributeText) { | ||
description: 'Search the documentation for examples that need to be extracted', | ||
runAfter: ['files-loaded'], | ||
runAfter: ['files-read'], | ||
runBefore: ['parsing-tags'], | ||
init: function(config, injectables) { | ||
// Reset the unique name map | ||
examples = Object.create(null); | ||
exports: { | ||
examples: ['value', Object.create(null) ] | ||
}, | ||
process: function(docs, examples, config) { | ||
injectables.value('examples', examples); | ||
var outputFolder = config.get('processing.examples.outputFolder', 'examples'); | ||
outputFolder = config.get('processing.examples.outputFolder', 'examples'); | ||
}, | ||
process: function(docs, examples) { | ||
_.forEach(docs, function(doc) { | ||
@@ -79,3 +74,3 @@ doc.content = doc.content.replace(EXAMPLE_REGEX, function processExample(match, attributeText, exampleText) { | ||
example.outputFolder = path.join(outputFolder, example.id); | ||
// store the example information for later | ||
@@ -82,0 +77,0 @@ log.debug('Storing example', id); |
var plugin = require('../../processors/examples-generate'); | ||
var Config = require('dgeni/lib/utils/config').Config; | ||
var Config = require('dgeni').Config; | ||
var _ = require('lodash'); | ||
describe("examples-generate processor", function() { | ||
var docs, examples; | ||
var docs, examples, config; | ||
beforeEach(function() { | ||
var config = _.extend(Config); | ||
config.set('processing.examples.templateFolder', 'examples'); | ||
config.set('deployment.environments', [ | ||
{ | ||
name: 'default', | ||
config = new Config({ | ||
processing: { | ||
examples: { | ||
commonFiles: [], | ||
dependencyPath: '.' | ||
}, | ||
templateFolder: 'examples' | ||
} | ||
}, | ||
deployment: { | ||
environments: [ | ||
{ | ||
name: 'default', | ||
examples: { | ||
commonFiles: [], | ||
dependencyPath: '.' | ||
}, | ||
}, | ||
{ | ||
name: 'other', | ||
examples: { | ||
commonFiles: { | ||
scripts: [ 'someFile.js', 'someOtherFile.js' ], | ||
}, | ||
dependencyPath: '..' | ||
} | ||
{ | ||
name: 'other', | ||
examples: { | ||
commonFiles: { | ||
scripts: [ 'someFile.js', 'someOtherFile.js' ], | ||
}, | ||
dependencyPath: '..' | ||
} | ||
} | ||
] | ||
} | ||
]); | ||
}); | ||
plugin.init(config, { value: function() { }}); | ||
docs = [ | ||
@@ -50,3 +56,3 @@ { file: 'a.b.js' } | ||
plugin.process(docs, examples); | ||
plugin.process(docs, examples, config); | ||
@@ -57,3 +63,3 @@ }); | ||
expect(exampleDocs.length).toBe(2); | ||
expect(exampleDocs[0]).toEqual( | ||
@@ -60,0 +66,0 @@ jasmine.objectContaining({ docType: 'example', id:'a.b.c', template: 'examples/index.template.html'}) |
var rewire = require('rewire'); | ||
var plugin = rewire('../../processors/examples-parse'); | ||
var Config = require('dgeni/lib/utils/config').Config; | ||
var Config = require('dgeni').Config; | ||
var log = require('winston'); | ||
@@ -8,8 +8,7 @@ var _ = require('lodash'); | ||
describe("examples-parse doc processor", function() { | ||
var config; | ||
beforeEach(function() { | ||
var config = _.extend(Config); | ||
var injectables = { value: function() { } }; | ||
config = new Config(); | ||
log.level = 'error'; | ||
plugin.init(config, injectables); | ||
}); | ||
@@ -24,13 +23,15 @@ | ||
var examples = {}; | ||
plugin.process([ | ||
{ | ||
content: 'a b c <example name="bar" moo1="nar1">some example content 1</example> x y z\n' + | ||
'a b c <example name="bar" moo2="nar2">some example content 2</example> x y z' | ||
}, | ||
{ | ||
content: 'j k l \n<example name="value">some content \n with newlines</example> j k l' | ||
}, | ||
{ | ||
content: '<example name="with-files"><file name="app.js">aaa</file><file name="app.spec.js" type="spec">bbb</file></example>' | ||
}], examples); | ||
var docs = [ | ||
{ | ||
content: 'a b c <example name="bar" moo1="nar1">some example content 1</example> x y z\n' + | ||
'a b c <example name="bar" moo2="nar2">some example content 2</example> x y z' | ||
}, | ||
{ | ||
content: 'j k l \n<example name="value">some content \n with newlines</example> j k l' | ||
}, | ||
{ | ||
content: '<example name="with-files"><file name="app.js">aaa</file><file name="app.spec.js" type="spec">bbb</file></example>' | ||
} | ||
]; | ||
plugin.process(docs, examples, config); | ||
expect(examples['example-bar']).toEqual(jasmine.objectContaining({ name:'bar', moo1:'nar1', id: 'example-bar'})); | ||
@@ -53,6 +54,7 @@ expect(examples['example-bar1']).toEqual(jasmine.objectContaining({ name:'bar', moo2:'nar2', id: 'example-bar1'})); | ||
var examples = []; | ||
plugin.process([{ | ||
var docs = [{ | ||
content: '<example name="bar">some example content 1</example>\n' + | ||
'<example name="bar">some example content 2</example>' | ||
}], examples); | ||
}]; | ||
plugin.process(docs, examples, config); | ||
expect(examples['example-bar'].id).toEqual('example-bar'); | ||
@@ -67,3 +69,3 @@ expect(examples['example-bar1'].id).toEqual('example-bar1'); | ||
plugin.process([doc], []); | ||
plugin.process([doc], [], config); | ||
@@ -70,0 +72,0 @@ expect(doc.content).toEqual('Some content before {@runnableExample example-bar} and some after'); |
module.exports = function(config) { | ||
config.append('source.extractors', require('./extractors/jsdoc')); | ||
require('../base')(config); | ||
config.append('source.fileReaders', require('./file-readers/jsdoc')); | ||
config.append('processing.processors', [ | ||
require('./processors/doc-extractor'), | ||
require('./processors/tag-parser'), | ||
require('./processors/tag-extractor'), | ||
{ name: 'parsing-tags', runAfter: ['files-read'], runBefore: ['processing-docs'] }, | ||
{ name: 'tags-parsed', runAfter: ['parsing-tags'], runBefore: ['processing-docs'] }, | ||
{ name: 'extracting-tags', runAfter: ['tags-parsed'], runBefore: ['processing-docs'] }, | ||
{ name: 'tags-extracted', runAfter: ['extracting-tags'], runBefore: ['processing-docs'] } | ||
]); | ||
config.append('processing.processors', [ | ||
require('./processors/code-name'), | ||
require('./processors/tagDefinitions'), | ||
require('./processors/tagParser'), | ||
require('./processors/tagExtractor'), | ||
require('./processors/defaultTagTransforms'), | ||
require('./processors/parse-tags'), | ||
require('./processors/extract-tags'), | ||
require('./processors/compute-path'), | ||
require('./processors/nunjucks-renderer'), | ||
require('./processors/escaped-comments'), | ||
require('./processors/inline-tags'), | ||
require('./processors/write-files') | ||
require('./processors/inline-tags') | ||
]); | ||
config.append('processing.tagDefinitions', require('./tag-defs')); | ||
config.append('rendering.filters', [ | ||
require('./rendering/filters/dash-case'), | ||
require('./rendering/filters/first-line'), | ||
require('./rendering/filters/first-paragraph'), | ||
require('./rendering/filters/json'), | ||
require('./rendering/filters/marked') | ||
]); | ||
config.append('rendering.tags', [ | ||
require('./rendering/tags/marked') | ||
]); | ||
return config; | ||
}; |
@@ -40,17 +40,27 @@ // Taken from Marijn Haverbeke's Acorn Parser Walk Utility | ||
// An ancestor walk builds up an array of ancestor nodes (including | ||
// the current node) and passes them to the callback as the state parameter. | ||
exports.ancestor = function(node, visitors, base, state) { | ||
// An ancestor walk builds up an array of ancestor nodes | ||
exports.ancestor = function(root, node, base) { | ||
if (!base) base = exports.base; | ||
if (!state) state = []; | ||
function c(node, st, override) { | ||
var type = override || node.type, found = visitors[type]; | ||
if (node != st[st.length - 1]) { | ||
st = st.slice(); | ||
st.push(node); | ||
function c(currentNode, ancestors, override) { | ||
var type = override || currentNode.type; | ||
// Make a copy of the ancestors array | ||
ancestors = ancestors.slice(); | ||
// Push the current node on to this array | ||
ancestors.push(currentNode); | ||
// If we have hit the node we want then break out | ||
if (currentNode === node) { | ||
throw ancestors; | ||
} | ||
base[type](node, st, c); | ||
if (found) found(node, st); | ||
// Otherwise traverse down-down-down | ||
base[type](currentNode, ancestors, c); | ||
} | ||
c(node, state); | ||
try { | ||
c(root, []); | ||
} catch(ancestors) { | ||
return ancestors; | ||
} | ||
}; | ||
@@ -57,0 +67,0 @@ |
var _ = require('lodash'); | ||
var log = require('winston'); | ||
var path = require('canonical-path'); | ||
var contentsFolder; | ||
module.exports = { | ||
name: 'compute-path', | ||
description: 'Compute the path and outputPath for docs that do not already have them', | ||
runAfter: ['tags-extracted'], | ||
init: function(config) { | ||
contentsFolder = config.get('rendering.contentsFolder'); | ||
runAfter: ['docs-processed'], | ||
runBefore: ['rendering-docs'], | ||
process: function(docs, config) { | ||
var contentsFolder = config.get('rendering.contentsFolder'); | ||
if ( !contentsFolder ) { | ||
throw new Error('Invalid configuration. You must provide config.rendering.contentsFolder'); | ||
} | ||
}, | ||
process: function(docs) { | ||
_.forEach(docs, function(doc) { | ||
doc.path = doc.path || doc.name || doc.codeName; | ||
if ( !doc.path ) { | ||
@@ -20,0 +22,0 @@ doc.path = path.join(path.dirname(doc.file)); |
@@ -5,4 +5,2 @@ var _ = require('lodash'); | ||
var inlineTagDefinitions; | ||
// We add InlineTagHandler onto the end of the tag name to help prevent naming collisions | ||
@@ -19,3 +17,3 @@ // in the injector | ||
runBefore: ['writing-files'], | ||
init: function(config) { | ||
process: function(docs, config, injector) { | ||
@@ -31,5 +29,3 @@ // A collection of inline tag definitions. Each should have, as minimum `name` and `handlerFactory` | ||
// } | ||
inlineTagDefinitions = config.get('processing.inlineTagDefinitions', []); | ||
}, | ||
process: function(docs, injector) { | ||
var inlineTagDefinitions = config.get('processing.inlineTagDefinitions', []); | ||
@@ -45,6 +41,6 @@ var handlerFactories = {}; | ||
} | ||
// Add the | ||
// Add the | ||
handlerFactories[handlerId(definition.name)] = ['factory', definition.handlerFactory]; | ||
_.forEach(definition.aliases, function(alias) { | ||
@@ -61,3 +57,3 @@ handlerFactories[handlerId(alias)] = ['factory', definition.handlerFactory]; | ||
if ( doc.renderedContent ) { | ||
// Replace any inline tags found in the rendered content | ||
@@ -67,3 +63,3 @@ doc.renderedContent = doc.renderedContent.replace(INLINE_TAG, function(match, tagName, tagDescription) { | ||
if ( handlerFactories[handlerId(tagName)] ) { | ||
// Get the handler for this tag from the injector | ||
@@ -89,3 +85,3 @@ var handler = injector.get(handlerId(tagName)); | ||
} | ||
} else { | ||
@@ -92,0 +88,0 @@ log.warn('No handler provided for inline tag "' + match + '" for "' + doc.id + '" in file "' + doc.file + '" at line ' + doc.startingLine); |
@@ -0,1 +1,2 @@ | ||
var _ = require('lodash'); | ||
var TagCollection = require('../../lib/TagCollection'); | ||
@@ -14,3 +15,4 @@ var Tag = require('../../lib/Tag'); | ||
expect(tags.badTags).toEqual([]); | ||
expect(tags.tagsByName).toEqual({}); | ||
// We clone so that toEqual works with our "bare" object | ||
expect(_.clone(tags.tagsByName)).toEqual({}); | ||
expect(tags.description).toEqual(''); | ||
@@ -23,3 +25,3 @@ }); | ||
expect(TagCollection.prototype.addTag).toHaveBeenCalled(); | ||
expect(TagCollection.prototype.addTag.calls.length).toEqual(3); | ||
expect(TagCollection.prototype.addTag.calls.count()).toEqual(3); | ||
}); | ||
@@ -26,0 +28,0 @@ |
var processor = require('../../processors/compute-path'); | ||
var _ = require('lodash'); | ||
var Config = require('dgeni/lib/utils/config').Config; | ||
var config; | ||
var Config = require('dgeni').Config; | ||
describe("compute-path doc processor", function() { | ||
var config; | ||
beforeEach(function() { | ||
config = _.extend(Config); | ||
config = new Config(); | ||
config.set('rendering.contentsFolder', 'partials'); | ||
processor.init(config); | ||
}); | ||
@@ -24,3 +24,3 @@ | ||
processor.process([doc1, doc2]); | ||
processor.process([doc1, doc2], config); | ||
@@ -40,4 +40,4 @@ expect(doc1.path).toEqual('a/b/c/foo'); | ||
processor.process([doc]); | ||
processor.process([doc], config); | ||
expect(doc.path).toEqual('a/b/c'); | ||
@@ -55,3 +55,3 @@ expect(doc.outputPath).toEqual('partials/a/b/c.html'); | ||
processor.process([doc]); | ||
processor.process([doc], config); | ||
@@ -58,0 +58,0 @@ expect(doc.path).toEqual('x/y/z'); |
@@ -1,2 +0,2 @@ | ||
var config = require('dgeni/lib/utils/config').Config; | ||
var Config = require('dgeni').Config; | ||
var processor = require('../../processors/inline-tags'); | ||
@@ -7,8 +7,13 @@ var di = require('di'); | ||
describe("inline-tags processor", function() { | ||
var config; | ||
beforeEach(function() { | ||
config = new Config(); | ||
}); | ||
it("should be called 'inline-tags'", function() { | ||
expect(processor.name).toEqual('inline-tags'); | ||
}); | ||
it("should run after docs are rendered and before writing files", function() { | ||
@@ -57,11 +62,10 @@ expect(processor.runAfter).toEqual(['docs-rendered']); | ||
// Run the processor | ||
processor.init(config); | ||
var results = processor.process(docs, injector); | ||
var results = processor.process(docs, config, injector); | ||
// This processor should not return anything. All its work is done on the docs, in place | ||
expect(results).toBeUndefined(); | ||
// We expect the unhandled tag to be reported | ||
expect(log.warn).toHaveBeenCalled(); | ||
expect(log.warn.calls[0].args[0]).toMatch(/No handler provided for inline tag "\{@unhandledTag some description\}"/); | ||
expect(log.warn.calls.argsFor(0)[0]).toMatch(/No handler provided for inline tag "\{@unhandledTag some description\}"/); | ||
@@ -68,0 +72,0 @@ // We expect the handler to have been invoked for the handledTag |
var _ = require('lodash'); | ||
var logger = require('winston'); | ||
var tagDefs = require('../../tag-defs'); | ||
var tagParser = require('../../processors/tag-parser'); | ||
var config = require('dgeni/lib/utils/config').Config; | ||
describe('tag definitions', function() { | ||
var TagCollection = require('../../lib/TagCollection'); | ||
var Tag = require('../../lib/Tag'); | ||
function parseDoc(content) { | ||
var doc; | ||
config.set('processing.tagDefinitions', tagDefs); | ||
tagParser.init(config); | ||
var tagDefs = require('../../tag-defs'); | ||
var tagDefMap = require('../../processors/tagDefinitions').exports.tagDefMap[1](tagDefs); | ||
if ( _.isString(content) ) { | ||
doc = { | ||
basePath: '.', | ||
file: 'src/some.js', | ||
fileType: 'js' | ||
}; | ||
doc.content = content; | ||
} else { | ||
doc = content; | ||
} | ||
tagParser.process([doc]); | ||
return doc; | ||
} | ||
var tagExtractorFactory = require('../../processors/tagExtractor').exports.tagExtractor[1]; | ||
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); | ||
} | ||
describe('tag definitions', function() { | ||
function doDefault(doc, name) { | ||
var tagDef = _.find(tagDefs, { name: name }); | ||
return tagDef.defaultFn(doc); | ||
} | ||
var tagExtractor; | ||
beforeEach(function() { | ||
tagExtractor = tagExtractorFactory(tagDefs); | ||
}); | ||
@@ -55,22 +23,25 @@ describe("memberof", function() { | ||
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'); | ||
var tag = new Tag(tagDefMap['memberof'], 'memberof', 'container', 123); | ||
var doc = createDoc(tag); | ||
expect(function() { | ||
tag.tagDef.transformFn(doc, tag); | ||
}).toThrow(); | ||
tagExtractor(doc); | ||
}).toThrowError(); | ||
}); | ||
it("should throw an exception if the tag doesn't exist and docType is 'event', 'method' or 'property'", function() { | ||
var doc = parseDoc("empty content"); | ||
var doc = createDoc([]); | ||
expect(function() { | ||
doc.docType = 'event'; | ||
doDefault(doc, 'memberof'); | ||
tagExtractor(doc); | ||
}).toThrow(); | ||
expect(function() { | ||
doc.docType = 'property'; | ||
doDefault(doc, 'memberof'); | ||
tagExtractor(doc); | ||
}).toThrow(); | ||
expect(function() { | ||
doc.docType = 'method'; | ||
doDefault(doc, 'memberof'); | ||
tagExtractor(doc); | ||
}).toThrow(); | ||
@@ -81,28 +52,18 @@ }); | ||
describe("param", function() { | ||
it("should add param tags to a params array on the doc", function() { | ||
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" | ||
); | ||
var tag1 = new Tag(tagDefMap['param'], 'param', '{string} paramName description of param', 123); | ||
var tag2 = new Tag(tagDefMap['param'], 'param', '{string=} optionalParam description of optional param', 123); | ||
var tag3 = new Tag(tagDefMap['param'], 'param', '{string} [optionalParam2] description of optional param', 123); | ||
var tag4 = new Tag(tagDefMap['param'], 'param', '{string} [paramWithDefault=xyz] description of param with default', 123); | ||
var tag5 = new Tag(tagDefMap['param'], 'param', '{string} paramName|alias description of param with alias', 123); | ||
var doc = createDoc([tag1, tag2, tag3, tag4, tag5]); | ||
var paramTags = doc.tags.getTags('param'); | ||
tagExtractor(doc); | ||
var param = doTransform(doc, paramTags[0]); | ||
checkProperty(param, 'paramName', 'description of param', ['string']); | ||
param = doTransform(doc, paramTags[1]); | ||
checkProperty(param, 'optionalParam', 'description of optional param', ['string'], true); | ||
param = doTransform(doc, paramTags[2]); | ||
checkProperty(param, 'optionalParam2', 'description of optional param', ['string'], true); | ||
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'); | ||
checkProperty(doc.params[0], 'paramName', 'description of param', ['string']); | ||
checkProperty(doc.params[1], 'optionalParam', 'description of optional param', ['string'], true); | ||
checkProperty(doc.params[2], 'optionalParam2', 'description of optional param', ['string'], true); | ||
checkProperty(doc.params[3], 'paramWithDefault', 'description of param with default', ['string'], true, 'xyz'); | ||
checkProperty(doc.params[4], 'paramName', 'description of param with alias', ['string'], false, undefined, 'alias'); | ||
}); | ||
@@ -115,6 +76,6 @@ }); | ||
it("should transform into a property object", function() { | ||
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']); | ||
var tag = new Tag(tagDefMap['property'], 'property', '{string} propertyName description of property', 123); | ||
var doc = createDoc(tag); | ||
tagExtractor(doc); | ||
checkProperty(doc.properties[0], 'propertyName', 'description of property', ['string']); | ||
}); | ||
@@ -124,10 +85,20 @@ | ||
describe("type", function() { | ||
it("should transform into a type object", function() { | ||
var tag = new Tag(tagDefMap['type'], 'type', '{string}'); | ||
var doc = createDoc(tag); | ||
tagExtractor(doc); | ||
checkProperty(doc.type, undefined, '', ['string']); | ||
}); | ||
}); | ||
describe("returns/return", function() { | ||
it("should transform into a returns object", function() { | ||
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']); | ||
var tag = new Tag(tagDefMap['returns'], 'returns', '{string} description of returns'); | ||
var doc = createDoc(tag); | ||
tagExtractor(doc); | ||
checkProperty(doc.returns, undefined, 'description of returns', ['string']); | ||
}); | ||
@@ -139,1 +110,21 @@ | ||
}); | ||
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 createDoc(tags) { | ||
if ( !_.isArray(tags)) { tags = [tags]; } | ||
return { | ||
tags: new TagCollection(tags) | ||
}; | ||
} |
@@ -1,4 +0,6 @@ | ||
var checkProperty = require('dgeni/lib/utils/check-property'); | ||
var path = require('canonical-path'); | ||
var _ = require('lodash'); | ||
var extractName = require('./transforms/extract-name'); | ||
var extractType = require('./transforms/extract-type'); | ||
var wholeTag = require('./transforms/whole-tag'); | ||
@@ -9,4 +11,4 @@ module.exports = [ | ||
}, | ||
{ | ||
@@ -19,6 +21,7 @@ name: 'memberof', | ||
}, | ||
transformFn: function(doc, tag) { | ||
transforms: function(doc, tag, value) { | ||
if ( !(doc.docType === 'event' || doc.docType === 'property' || doc.docType === 'method') ) { | ||
throw new Error('"@'+ tag.name +'" tag found on non-'+ doc.docType +' document in file "' + doc.file + '" at line ' + doc.startingLine); | ||
} | ||
return value; | ||
} | ||
@@ -32,7 +35,3 @@ }, | ||
docProperty: 'params', | ||
canHaveName: true, | ||
canHaveType: true, | ||
transformFn: function(doc, tag) { | ||
return tag; | ||
} | ||
transforms: [ extractType, extractName, wholeTag ] | ||
}, | ||
@@ -45,7 +44,3 @@ | ||
docProperty: 'properties', | ||
canHaveName: true, | ||
canHaveType: true, | ||
transformFn: function(doc, tag) { | ||
return tag; | ||
} | ||
transforms: [ extractType, extractName, wholeTag ] | ||
}, | ||
@@ -57,9 +52,11 @@ | ||
aliases: ['return'], | ||
canHaveType: true, | ||
transformFn: function(doc, tag) { | ||
return tag; | ||
} | ||
transforms: [ extractType, wholeTag ] | ||
}, | ||
{ | ||
name: 'type', | ||
transforms: [ extractType, wholeTag ] | ||
}, | ||
{ | ||
name: 'requires', | ||
@@ -73,3 +70,3 @@ multi: true | ||
{ name: 'private' }, | ||
{ name: 'see'}, | ||
{ name: 'see', multi: true }, | ||
{ name: 'usage' }, | ||
@@ -83,3 +80,4 @@ { name: 'animations' }, | ||
{ name: 'kind' }, | ||
{ name: 'function' } | ||
{ name: 'function' }, | ||
{ name: 'method' } | ||
]; |
var path = require('canonical-path'); | ||
var packagePath = __dirname; | ||
var basePackage = require('../jsdoc'); | ||
module.exports = function(config) { | ||
require('../jsdoc')(config); | ||
require('../nunjucks')(config); | ||
config.merge('rendering.nunjucks.config.tags', { | ||
@@ -11,6 +13,5 @@ variableStart: '{$', | ||
}); | ||
config = basePackage(config); | ||
config.append('source.extractors', require('./extractors/ngdoc')); | ||
config.append('source.fileReaders', require('./file-readers/ngdoc')); | ||
config.append('processing.tagDefinitions', require('./tag-defs')); | ||
@@ -17,0 +18,0 @@ config.append('processing.inlineTagDefinitions', [ |
@@ -1,2 +0,2 @@ | ||
var INLINE_LINK = /(\S+)(?:\s+(.+))?/; | ||
var INLINE_LINK = /(\S+)(?:\s+([\s\S]+))?/; | ||
@@ -3,0 +3,0 @@ module.exports = { |
var _ = require('lodash'); | ||
var log = require('winston'); | ||
var path = require('canonical-path'); | ||
var partialsPath; | ||
var options; | ||
@@ -12,9 +10,14 @@ module.exports = { | ||
runBefore: ['compute-path'], | ||
init: function(config, injectables) { | ||
injectables.value('moduleMap', Object.create(null)); | ||
partialsPath = config.get('rendering.contentsFolder'); | ||
exports: { | ||
moduleMap: ['value', Object.create(null)] | ||
}, | ||
process: function(docs, config, partialNames, moduleMap) { | ||
var parts; | ||
var partialsPath = config.get('rendering.contentsFolder'); | ||
if ( !partialsPath ) { | ||
throw new Error('Invalid configuration. You must provide config.rendering.contentsFolder'); | ||
} | ||
options = _.assign({ | ||
var options = _.assign({ | ||
outputPath: '${area}/${module}/${docType}/${name}.html', | ||
@@ -25,7 +28,3 @@ path: '${area}/${module}/${docType}/${name}', | ||
}, config.get('processing.api-docs', {})); | ||
}, | ||
process: function(docs, partialNames, moduleMap) { | ||
var parts; | ||
// Compute some extra fields for docs in the API area | ||
@@ -32,0 +31,0 @@ _.forEach(docs, function(doc) { |
var _ = require('lodash'); | ||
var path = require('canonical-path'); | ||
var partialsPath; | ||
@@ -10,9 +9,9 @@ module.exports = { | ||
runBefore: ['extra-docs-added'], | ||
init: function(config) { | ||
partialsPath = config.get('rendering.contentsFolder'); | ||
process: function(docs, config, moduleMap) { | ||
var partialsPath = config.get('rendering.contentsFolder'); | ||
if ( !partialsPath ) { | ||
throw new Error('Invalid configuration. You must provide config.rendering.contentsFolder'); | ||
} | ||
}, | ||
process: function(docs, moduleMap) { | ||
_.forEach(moduleMap, function(module) { | ||
@@ -19,0 +18,0 @@ |
@@ -8,4 +8,4 @@ var PartialNames = require('../utils/partial-names').PartialNames; | ||
runAfter: ['compute-id'], | ||
init: function(config, injectables) { | ||
injectables.value('partialNames', new PartialNames()); | ||
exports: { | ||
partialNames: ['factory', function() { return new PartialNames(); }] | ||
}, | ||
@@ -12,0 +12,0 @@ process: function(docs, partialNames) { |
@@ -1,2 +0,2 @@ | ||
var code = require('dgeni/lib/utils/code'); | ||
var code = require('../../../utils/code'); | ||
module.exports = { | ||
@@ -3,0 +3,0 @@ name: 'code', |
@@ -1,3 +0,3 @@ | ||
var trimIndentation = require('dgeni/lib/utils/trim-indentation'); | ||
var code = require('dgeni/lib/utils/code'); | ||
var trimIndentation = require('../../../utils/trim-indentation'); | ||
var code = require('../../../utils/code'); | ||
@@ -4,0 +4,0 @@ module.exports = { |
@@ -28,2 +28,3 @@ var _ = require('lodash'); | ||
renderedContent: "Some text with a {@link some/url link} to somewhere\n" + | ||
"Another text with a {@link another/url that spans\n two lines}\n" + | ||
"Some example with a code link: {@link module:ngOther.directive:ngDirective}\n" + | ||
@@ -47,2 +48,6 @@ "A link to reachable code: {@link ngInclude}" | ||
it("should parse empty space within a link's title", function() { | ||
expect(linkHandler(doc, 'link', 'another/url link that spans\n two lines')).toEqual('<a href="another/url">link that spans\n two lines</a>'); | ||
}); | ||
it("should convert code links to anchors with formatted code", function() { | ||
@@ -55,4 +60,4 @@ expect(linkHandler(doc, 'link', 'ngInclude')).toEqual('<a href="api/ng/directive/ngInclude"><code>ngInclude</code></a>'); | ||
linkHandler(doc, 'link', 'module:ngOther.directive:ngDirective'); | ||
}).toThrow('Invalid link (does not match any doc): "module:ngOther.directive:ngDirective"'); | ||
}).toThrowError(/Invalid link \(does not match any doc\): "module:ngOther\.directive:ngDirective"/); | ||
}); | ||
}); |
var rewire = require('rewire'); | ||
var processor = rewire('../../processors/api-docs'); | ||
var PartialNames = require('../../utils/partial-names').PartialNames; | ||
var Config = require('dgeni/lib/utils/config').Config; | ||
var Config = require('dgeni').Config; | ||
var di = require('di'); | ||
var _ = require('lodash'); | ||
describe("api-docs config", function() { | ||
it("should provide defaults for its options", function() { | ||
var config = _.extend(Config); | ||
config.set('rendering.contentsFolder', 'partials'); | ||
processor.init(config, new di.Module()); | ||
expect(processor.__get__('options')).toEqual({ | ||
outputPath: '${area}/${module}/${docType}/${name}.html', | ||
path: '${area}/${module}/${docType}/${name}', | ||
moduleOutputPath: '${area}/${name}/index.html', | ||
modulePath: '${area}/${name}' | ||
}); | ||
}); | ||
it("should let us override the options", function() { | ||
var config = _.extend(Config); | ||
config.set('rendering.contentsFolder', 'partials'); | ||
config.set('processing.api-docs.path', 'XXX'); | ||
processor.init(config, new di.Module()); | ||
expect(processor.__get__('options.path')).toEqual('XXX'); | ||
expect(processor.__get__('options.moduleOutputPath')).toEqual('${area}/${name}/index.html'); | ||
}); | ||
}); | ||
describe("api-docs processor", function() { | ||
@@ -39,5 +13,4 @@ var config; | ||
beforeEach(function() { | ||
config = _.extend(Config); | ||
config = new Config(); | ||
config.set('rendering.contentsFolder', 'partials'); | ||
processor.init(config, new di.Module()); | ||
}); | ||
@@ -57,3 +30,3 @@ | ||
var moduleMap = {}; | ||
processor.process([doc1,doc2], new PartialNames(), moduleMap); | ||
processor.process([doc1,doc2], config, new PartialNames(), moduleMap); | ||
expect(moduleMap).toEqual({ | ||
@@ -64,3 +37,3 @@ 'ng': doc1, | ||
}); | ||
it("should extract the container and member from the name if it is a memberOf type", function() { | ||
@@ -75,3 +48,3 @@ var doc = { | ||
processor.process([doc], new PartialNames()); | ||
processor.process([doc], config, new PartialNames()); | ||
@@ -94,3 +67,3 @@ expect(doc.name).toEqual('get'); | ||
}; | ||
processor.process([doc], new PartialNames(), moduleMap); | ||
processor.process([doc], config, new PartialNames(), moduleMap); | ||
@@ -97,0 +70,0 @@ expect(moduleMap['ng'].components[0]).toBe(doc); |
var _ = require('lodash'); | ||
var processor = require('../../processors/component-groups-generate'); | ||
var Config = require('dgeni/lib/utils/config').Config; | ||
var Config = require('dgeni').Config; | ||
@@ -21,6 +21,5 @@ describe("component-groups processor", function() { | ||
config = _.extend(Config); | ||
config = new Config(); | ||
config.set('rendering.contentsFolder', 'partials'); | ||
processor.init(config); | ||
processor.process(docs, modules); | ||
processor.process(docs, config, modules); | ||
@@ -27,0 +26,0 @@ expect(docs.length).toEqual(2); |
var _ = require('lodash'); | ||
var logger = require('winston'); | ||
var TagCollection = require('../../../jsdoc/lib/TagCollection'); | ||
var Tag = require('../../../jsdoc/lib/Tag'); | ||
var tagDefs = require('../../tag-defs'); | ||
var tagParser = require('../../../jsdoc/processors/tag-parser'); | ||
var config = require('dgeni/lib/utils/config').Config; | ||
var tagDefMap = require('../../../jsdoc/processors/tagDefinitions').exports.tagDefMap[1](tagDefs); | ||
var tagExtractorFactory = require('../../../jsdoc/processors/tagExtractor').exports.tagExtractor[1]; | ||
describe('tag definitions', function() { | ||
function parseDoc(content) { | ||
var doc; | ||
config.set('processing.tagDefinitions', tagDefs); | ||
tagParser.init(config); | ||
var tagExtractor, nameTag, ngdocTag; | ||
if ( _.isString(content) ) { | ||
doc = { | ||
basePath: '.', | ||
file: 'src/some.js', | ||
fileType: 'js' | ||
}; | ||
doc.content = content; | ||
} else { | ||
doc = content; | ||
} | ||
tagParser.process([doc]); | ||
return doc; | ||
} | ||
beforeEach(function() { | ||
tagExtractor = tagExtractorFactory(tagDefs); | ||
nameTag = new Tag(tagDefMap['name'], 'name', 'some-name', 123); | ||
ngdocTag = new Tag(tagDefMap['ngdoc'], 'ngdoc', 'directive', 123); | ||
}); | ||
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() { | ||
it("should throw an error if the tag is missing", function() { | ||
var doc = { | ||
content: '' | ||
}; | ||
doc = parseDoc(doc, 0); | ||
var doc = createDoc([ngdocTag]); | ||
expect(function() { | ||
doDefault(doc); | ||
tagExtractor(doc); | ||
}).toThrow(); | ||
}); | ||
it("should throw error if the docType is 'input' and the name is not a valid format", function() { | ||
var doc = { | ||
docType: 'input', | ||
content: '@name input[checkbox]' | ||
}; | ||
doc = parseDoc(doc, 0); | ||
expect(doTransform(doc, 'name')).toEqual('input[checkbox]'); | ||
it("should update the inputType if docType is input", function() { | ||
nameTag.description = 'input[checkbox]'; | ||
ngdocTag.description = 'input'; | ||
var doc = createDoc([nameTag, ngdocTag]); | ||
tagExtractor(doc); | ||
expect(doc.name).toEqual('input[checkbox]'); | ||
expect(doc.inputType).toEqual('checkbox'); | ||
}); | ||
doc = { | ||
docType: 'directive', | ||
content: '@name input[checkbox]' | ||
}; | ||
doc = parseDoc(doc, 0); | ||
expect(doTransform(doc, 'name')).toEqual('input[checkbox]'); | ||
it("should not update the inputType if docType is not input", function() { | ||
nameTag.description = 'input[checkbox]'; | ||
ngdocTag.description = 'directive'; | ||
var doc = createDoc([nameTag, ngdocTag]); | ||
tagExtractor(doc); | ||
expect(doc.name).toEqual('input[checkbox]'); | ||
expect(doc.inputType).toBeUndefined(); | ||
doc = { | ||
docType: 'input', | ||
content: '@name invalidInputName' | ||
}; | ||
doc = parseDoc(doc, 0); | ||
}); | ||
it("should throw error if the docType is 'input' and the name is not a valid format", function() { | ||
nameTag.description = 'invalidInputName'; | ||
ngdocTag.description = 'input'; | ||
var doc = createDoc([nameTag, ngdocTag]); | ||
expect(function() { | ||
doTransform(doc, 'name'); | ||
tagExtractor(doc); | ||
}).toThrow(); | ||
}); | ||
@@ -99,16 +67,12 @@ | ||
it("should be 'api' if the fileType is js", function() { | ||
var doc = { | ||
content: '', | ||
fileType: 'js' | ||
}; | ||
expect(doDefault(doc, 'area')).toEqual('api'); | ||
var doc = createDoc([nameTag, ngdocTag]); | ||
tagExtractor(doc); | ||
expect(doc.area).toEqual('api'); | ||
}); | ||
it("should compute the area from the file name", function() { | ||
var doc = { | ||
content: '', | ||
fileType: 'ngdoc', | ||
file: 'guide/scope/binding.ngdoc' | ||
}; | ||
expect(doDefault(doc, 'area')).toEqual('guide'); | ||
var doc = createDoc([nameTag, ngdocTag], 'guide/scope/binding.ngdoc', 'ngdoc'); | ||
tagExtractor(doc); | ||
expect(doc.area).toEqual('guide'); | ||
}); | ||
@@ -120,8 +84,5 @@ }); | ||
it("extracts the module from the file name if it is from the api area", function() { | ||
var doc = { | ||
area: 'api', | ||
file: 'src/ng/compile.js', | ||
content: '' | ||
}; | ||
expect(doDefault(doc, 'module')).toEqual('ng'); | ||
var doc = createDoc([nameTag, ngdocTag]); | ||
tagExtractor(doc); | ||
expect(doc.module).toEqual('ng'); | ||
}); | ||
@@ -135,15 +96,29 @@ }); | ||
expect(doTransform(parseDoc('@restrict A'), 'restrict')) | ||
var restrictTag = new Tag(tagDefMap['restrict'], 'restrict', '', 123); | ||
var doc = createDoc([nameTag, ngdocTag, restrictTag]); | ||
restrictTag.description = 'A'; | ||
tagExtractor(doc); | ||
expect(doc.restrict) | ||
.toEqual({ element: false, attribute: true, cssClass: false, comment: false }); | ||
expect(doTransform(parseDoc('@restrict C'), 'restrict')) | ||
restrictTag.description = 'C'; | ||
tagExtractor(doc); | ||
expect(doc.restrict) | ||
.toEqual({ element: false, attribute: false, cssClass: true, comment: false }); | ||
expect(doTransform(parseDoc('@restrict E'), 'restrict')) | ||
restrictTag.description = 'E'; | ||
tagExtractor(doc); | ||
expect(doc.restrict) | ||
.toEqual({ element: true, attribute: false, cssClass: false, comment: false }); | ||
expect(doTransform(parseDoc('@restrict M'), 'restrict')) | ||
restrictTag.description = 'M'; | ||
tagExtractor(doc); | ||
expect(doc.restrict) | ||
.toEqual({ element: false, attribute: false, cssClass: false, comment: true }); | ||
expect(doTransform(parseDoc('@restrict ACEM'), 'restrict')) | ||
restrictTag.description = 'ACEM'; | ||
tagExtractor(doc); | ||
expect(doc.restrict) | ||
.toEqual({ element: true, attribute: true, cssClass: true, comment: true }); | ||
@@ -153,3 +128,5 @@ }); | ||
it("should default to restricting to an attribute if no tag is found and the doc is for a directive", function() { | ||
expect(doDefault({ docType: 'directive' }, 'restrict')) | ||
var doc = createDoc([nameTag, ngdocTag]); | ||
tagExtractor(doc); | ||
expect(doc.restrict) | ||
.toEqual({ element: false, attribute: true, cssClass: false, comment: false }); | ||
@@ -159,3 +136,6 @@ }); | ||
it("should not add a restrict property if the docType is not 'directive'", function() { | ||
expect(doDefault({ docType: 'other' }, 'restrict')).toBeUndefined(); | ||
var doc = createDoc([nameTag, ngdocTag]); | ||
ngdocTag.description = 'other'; | ||
tagExtractor(doc); | ||
expect(doc.restrict).toBeUndefined(); | ||
}); | ||
@@ -168,4 +148,6 @@ }); | ||
it("should add an eventTarget property to the doc and return the event type", function() { | ||
var doc = parseDoc('@eventType broadcast on module:ng.directive:ngInclude'); | ||
expect(doTransform(doc, 'eventType')).toEqual('broadcast'); | ||
var eventTag = new Tag(tagDefMap['eventType'], 'eventType', 'broadcast on module:ng.directive:ngInclude', 123); | ||
var doc = createDoc([nameTag, ngdocTag, eventTag]); | ||
tagExtractor(doc); | ||
expect(doc.eventType).toEqual('broadcast'); | ||
expect(doc.eventTarget).toEqual('module:ng.directive:ngInclude'); | ||
@@ -179,5 +161,15 @@ }); | ||
it("should default to ANY if the document is a directive", function() { | ||
expect(doDefault({ docType: 'directive' }, 'element')).toEqual('ANY'); | ||
expect(doDefault({ docType: 'filter' }, 'element')).toBeUndefined(); | ||
var doc = createDoc([nameTag, ngdocTag]); | ||
ngdocTag.description = 'directive'; | ||
tagExtractor(doc); | ||
expect(doc.element).toEqual('ANY'); | ||
}); | ||
it("should be undefined if the document is not a directive", function() { | ||
var doc = createDoc([nameTag, ngdocTag]); | ||
ngdocTag.description = 'filter'; | ||
tagExtractor(doc); | ||
expect(doc.element).toBeUndefined(); | ||
}); | ||
}); | ||
@@ -187,1 +179,23 @@ | ||
}); | ||
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 createDoc(tags, file, fileType) { | ||
if ( !_.isArray(tags)) { tags = [tags]; } | ||
return { | ||
tags: new TagCollection(tags), | ||
file: file || 'src/ng/compile.js', | ||
fileType: fileType || 'js' | ||
}; | ||
} |
@@ -0,1 +1,2 @@ | ||
var _ = require('lodash'); | ||
var util = require('../../utils/partial-names'); | ||
@@ -10,3 +11,3 @@ | ||
partialNames.addDoc(doc); | ||
expect(partialNames.map).toEqual({ | ||
expect(_.clone(partialNames.map)).toEqual({ | ||
'$http#get': doc, | ||
@@ -31,3 +32,3 @@ 'service:$http#get': doc, | ||
expect(partialNames.map).toEqual({ | ||
expect(_.clone(partialNames.map)).toEqual({ | ||
'$log': [doc1, doc2], | ||
@@ -47,3 +48,3 @@ 'service:$log': [doc1, doc2], | ||
expect(partialNames.map).toEqual({ | ||
expect(_.clone(partialNames.map)).toEqual({ | ||
'$log': doc2, | ||
@@ -50,0 +51,0 @@ 'service:$log': doc2, |
@@ -1,2 +0,1 @@ | ||
var checkProperty = require('dgeni/lib/utils/check-property'); | ||
var path = require('canonical-path'); | ||
@@ -16,17 +15,16 @@ var _ = require('lodash'); | ||
required: true, | ||
transformFn: function(doc, tag) { | ||
transforms: function(doc, tag, value) { | ||
var INPUT_TYPE = /input\[(.+)\]/; | ||
var name = tag['description']; | ||
if ( doc.docType === 'input' ) { | ||
var match = INPUT_TYPE.exec(name); | ||
var match = INPUT_TYPE.exec(value); | ||
if ( !match ) { | ||
throw new Error('Invalid input directive name. It should be of the form: "input[inputType]" but was "' + doc.name + '"'); | ||
throw new Error('Invalid input directive name. It should be of the form: "input[inputType]" but was "' + value + '"'); | ||
} | ||
doc.inputType = match[1]; | ||
} | ||
return name; | ||
return value; | ||
} | ||
}, | ||
{ | ||
@@ -46,3 +44,2 @@ name: 'area', | ||
if ( doc.area === 'api' ) { | ||
checkProperty(doc, 'file'); | ||
// Calculate the module from the second segment of the file path | ||
@@ -66,8 +63,8 @@ // (the first being the area) | ||
}, | ||
transformFn: function(doc, tag) { | ||
transforms: function(doc, tag, value) { | ||
return { | ||
element: _.contains(tag.description, 'E'), | ||
attribute: _.contains(tag.description, 'A'), | ||
cssClass: _.contains(tag.description, 'C'), | ||
comment: _.contains(tag.description, 'M') | ||
element: _.contains(value, 'E'), | ||
attribute: _.contains(value, 'A'), | ||
cssClass: _.contains(value, 'C'), | ||
comment: _.contains(value, 'M') | ||
}; | ||
@@ -80,5 +77,5 @@ } | ||
name: 'eventType', | ||
transformFn: function(doc, tag) { | ||
transforms: function(doc, tag, value) { | ||
var EVENTTYPE_REGEX = /^([^\s]*)\s+on\s+([\S\s]*)/; | ||
var match = EVENTTYPE_REGEX.exec(tag.description); | ||
var match = EVENTTYPE_REGEX.exec(value); | ||
// Attach the target to the doc | ||
@@ -111,6 +108,6 @@ doc.eventTarget = match[2]; | ||
}, | ||
{ | ||
name: 'scope', | ||
transformFn: function(doc, tag) { return true; } | ||
transforms: function(doc, tag) { return true; } | ||
}, | ||
@@ -122,3 +119,3 @@ | ||
}, | ||
{ name: 'title' }, | ||
@@ -125,0 +122,0 @@ { name: 'parent' }, |
var _ = require('lodash'); | ||
var path = require('canonical-path'); | ||
var code = require('dgeni/lib/utils/code.js'); | ||
var code = require('../../utils/code.js'); | ||
var log = require('winston'); | ||
@@ -103,5 +103,5 @@ | ||
// Try to get a list of docs that match this partialName | ||
// Try to get a list of docs that match this partialName | ||
var matchedDocs = map[partialName]; | ||
if ( !matchedDocs ) { | ||
@@ -112,3 +112,3 @@ // This partial name is not yet used - add it to the map | ||
} else { | ||
if ( _.isArray(matchedDocs) ) { | ||
@@ -137,3 +137,3 @@ // There are already more than one docs associated with this partialName - add this one too | ||
var matchedDocs = map[partialName]; | ||
if ( matchedDocs === doc ) { | ||
@@ -140,0 +140,0 @@ // There is only one doc and it is the one we want to remove |
{ | ||
"name": "dgeni-packages", | ||
"version": "0.8.3", | ||
"version": "0.9.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", | ||
"cover": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node -- ngdoc/spec jsdoc/spec examples/spec" | ||
"test": "node ./node_modules/jasmine-node/bin/jasmine-node */spec", | ||
"cover": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node -- */spec" | ||
}, | ||
@@ -33,3 +33,3 @@ "repository": { | ||
"dependencies": { | ||
"dgeni": "~0.2.1", | ||
"dgeni": "~0.3.0", | ||
"canonical-path": "0.0.2", | ||
@@ -44,10 +44,13 @@ "lodash": "~2.4.1", | ||
"catharsis": "^0.7.0", | ||
"esprima": "^1.0.4" | ||
"esprima": "^1.0.4", | ||
"change-case": "^2.1.0", | ||
"marked": "~0.2.10", | ||
"node-html-encoder": "0.0.2" | ||
}, | ||
"peerDependencies": { | ||
"dgeni": "~0.2.1" | ||
"dgeni": "~0.3.0" | ||
}, | ||
"devDependencies": { | ||
"rewire": "~2.0.0", | ||
"jasmine-node": "~1.13.1", | ||
"jasmine-node": "~2.0.0", | ||
"di": "~0.0.1" | ||
@@ -60,4 +63,7 @@ }, | ||
"Kevin Rowe <kevinrowe@outlook.com>", | ||
"Pascal Precht <pascal.precht@googlemail.com>" | ||
"Pascal Precht <pascal.precht@googlemail.com>", | ||
"Konstantinos Rousis <rousisk@gmail.com>", | ||
"Stéphane Reynaud <forresst@voila.fr>", | ||
"Matthew Harris <ftmomatt@gmail.com>" | ||
] | ||
} |
@@ -25,3 +25,3 @@ # Dgeni Packages | ||
following tags: `name`, `memberof`, `param`, `property`, `returns`, `module`, `description`, `usage`, | ||
`animations`, `constructor`, `class`, `classdesc`, `global`, `namespace` and `kind`. | ||
`animations`, `constructor`, `class`, `classdesc`, `global`, `namespace`, `method`, `type` and `kind`. | ||
* `nunjucks-renderer` - uses the Nunjucks template library to render the documents into files, such | ||
@@ -28,0 +28,0 @@ as HTML or JS, based on templates. |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
199516
141
4362
15
1
8
+ Addedchange-case@^2.1.0
+ Addedmarked@~0.2.10
+ Addednode-html-encoder@0.0.2
+ Addedcamel-case@1.2.2(transitive)
+ Addedchange-case@2.3.1(transitive)
+ Addedconstant-case@1.1.2(transitive)
+ Addeddgeni@0.3.0(transitive)
+ Addeddot-case@1.1.2(transitive)
+ Addedis-lower-case@1.1.3(transitive)
+ Addedis-upper-case@1.1.2(transitive)
+ Addedlower-case@1.1.4(transitive)
+ Addedlower-case-first@1.0.2(transitive)
+ Addedparam-case@1.1.2(transitive)
+ Addedpascal-case@1.1.2(transitive)
+ Addedpath-case@1.1.2(transitive)
+ Addedsentence-case@1.1.3(transitive)
+ Addedsnake-case@1.1.2(transitive)
+ Addedswap-case@1.1.2(transitive)
+ Addedtitle-case@1.1.2(transitive)
+ Addedupper-case@1.1.3(transitive)
+ Addedupper-case-first@1.1.2(transitive)
- Removeddgeni@0.2.2(transitive)
Updateddgeni@~0.3.0