English 中文(简体)
Parsing Javascript files with phpDocumentor
原标题:

I ve been playing with phpDocumentor recently and found it quite suitable for my needs. I m largely working with PHP/HTML/JS/CSS codebases and would like phpDocumentor to parse my Javascript (and perhaps CSS) in order to keep it all together.

I ve managed to get phpdoc to parse javascript files contained throughout the codebase - however it rejects the page-level docblock - which results in it rejecting the various tags (see below). I ve found that by adding in a PHP open tag (with a JavaScript comment before it) to the top of the JavaScript file, I can get it to parse it just like a PHP file.

// <?php
/**
 * phpdoc goes here
 * @package
 * @todo
 *   - Todo 1
 *   - Todo 2
 */
function javascript(goes, here) {
}

I can think of a problem occurring should the webserver be setup to server .js files through PHP. Are there any other problems anyone can think of? Is there a better way to accomplish this?

Thanks

最佳回答

As far as potential problems, one that comes to mind is that since you re "tricking" phpDocumentor into parsing the docblock and the JS code, you re implicitly counting on the PHP tokenizer (which is how phpDocumentor parses PHP code internally) to successfully read your JS code and treat it as PHP code. When this succeeds, I think you ll have good results... your simple function example should probably succeed. However, if your JS code will not parse successfully as PHP code, then I bet phpDocumentor won t see it as a documentable code element, and therefore it will not appear in your docs.

问题回答

I think it s a bit naive assumption to think there is no similar tool for JavaScript.

There is a tool called JSDoc which is basically the same as phpdoc, but for JavaScript.


Update Friday, May 1, 2015:-

It seems like that the new project link is:-

https://github.com/jsdoc3/jsdoc

I am looking for the same thing. I found JSDoc and PhpDocumentor but considering the fact that 1 (ONE) application as a "Whole" contains both PHP and JavaScript making the base of the application I would prefer 1 approach to documenting the projects. It really sucks to have 2 documentation sets, 1 for php and 1 for JavaScript. That ole @see or inline @link does not work in the case of, @see this other function/class in this other langauge, via some other documentation program.... get my drift?





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签