3

ternJS have several. JSON files defs which contains the definition of librarys. Can someone explain to me how I can best generate my own to my javascript libraries / or only definition objects?

I can not see that there is no common procedure for this?

eriksv88
  • 3,482
  • 3
  • 31
  • 50

2 Answers2

10

There's a tool for this included in Tern. See condense at http://ternjs.net/doc/manual.html#utils . It runs Tern on your file and tries to output the types that it finds. It's far from flawless, but for simple programs it works well. For files with a complicated structure or interface, you'll often have to hand-write the definitions.

Marijn
  • 8,691
  • 2
  • 34
  • 37
4

There are three ways I have thought about to solve your problem:

Using Abstract Syntax Tree Parser and Visitor

One way to solve your problem would be to use abstract syntax tree parser and visitor in order to automate the task of scanning through the code and documenting it.

The resources here will be of help:

-http://ramkulkarni.com/blog/understanding-ast-created-by-mozilla-rhino-parser/ -What is JavaScript AST, how to play with it?

You usually use a parser to retrieve a tree, and then use a visitor to visit all the nodes and do your work within there.

You will essentially have a tree representing the specific library and then you must write the code to store this in the def format you link to.

Getting a Documentation Generator and Modifying

Another idea is to download the source code for a documentation generator, e.g. https://github.com/yui/yuidoc/

By modifying the styling/output format you can generate "documentation" in the appropriate json format.

Converting Existing Documentation (HTML doc) into JSON

You can make a parser that takes a standard documentation format (I'm sure as Javadoc is one for java there should be one for javascript), and write a converter that exctracts the relevant information and stores in a JSON definition.

Community
  • 1
  • 1
Menelaos
  • 23,508
  • 18
  • 90
  • 155
  • I counted at least that they had not written defs manually xD hehe – eriksv88 Sep 24 '13 at 10:58
  • 1
    Maybe ask them? :) ... I noticed they also include URLs to documentation within the defs which points also that they scrapped/crawled or manually entered data. I also suspect if they maybe generated the defs from crawling through the docs. I've updated my answer with 2 more options. – Menelaos Sep 24 '13 at 11:00
  • Thx, Learned a lot from this here :)! Thank you. +1. But I think doing it the way it is supposed from tern :) – eriksv88 Sep 24 '13 at 11:38