angular / dgeni-packages

A collection of dgeni packages for generating documentation from source code.
MIT License
142 stars 101 forks source link

Using preprocessors for file content before getting docs #74

Closed maksimr closed 9 years ago

maksimr commented 10 years ago

For example. We have jsx with jsdoc comments. Before passing file content to jsdocFileReader we should before pass file content through jsx preprocessor.

Now solution look like, create jsxFileReader which will be use jsdocFileReader. But more sophisticated solution will be something like (IMHO):

readFilesProcessor.sourceFiles = [{
   include: 'js/**/*.jsx',
   fileReader: ['jsxFileReader', 'jsdocFileReader']
}];

What do you think about this?

petebacondarwin commented 10 years ago

I am guessing that your preprocessor converts jsx files into js? While I can see that there is common functionality in the jsdoc file reader, I am not sure that providing a "pipeline" of file readers is that intuitive as it stands, since fileReaders take a fileInfo object and return a doc object. It wouldn't make sense to pass the doc into a second fileReader.

Instead I think it would be more profitable to factor out the jsdoc processing (i.e. the esprima parsing, etc) into its own service that can then be used by the jsdoc fileReader and any other such as your jsx fileReader.

Alternatively, how about providing an explicit preprocessor property on the sourceFile object:

readFilesProcessor.sourceFiles = [
  includeL 'js/**/*.jsx',
  preprocessors: ['jsxPreprocessor'],
  fileReader: 'jsdocFileReader'
];

These preprocessors could modify the content before it gets to the fileReader. What do you think?

maksimr commented 10 years ago

I am guessing that your preprocessor converts jsx files into js?

yep

Alternatively, how about providing an explicit preprocessor property on the sourceFile object:

I agree that it's more clear

petebacondarwin commented 10 years ago

Would you like to make a pull request?

gbbr commented 8 years ago

@petebacondarwin @maksimr any luck putting this together by now? I am having a hard time figuring it out. We also have JSX files that we would like to use with dgeni.

petebacondarwin commented 8 years ago

@gbbr I don't have time right now to work on this. But if you don't want to try to create a general PR that adds preprocessing, you could look into making your own custom file reader that is a copy of https://github.com/angular/dgeni-packages/blob/master/jsdoc/file-readers/jsdoc.js but with additional jsx parsing before it gets sent to the jsParser service.

gbbr commented 8 years ago

Thanks! I'll make a PR if I manage to work it out...