Parsing python docstring from javascript - javascript

I need to parse docstring from several python files and I need to do this with Javascript.
I couldn't find any reference for this, any ideas?
EDIT: I'm working with Titanium SDK and jquery. PyDoc is not the solution that I'm looking for because I don't want to include some process on the middle of the javascript and the python source code.
EDIT 2: SOLVED - Titanium can use python and javascript at the same time, so I can use python to parse the docstring from the python files.

Check out how the lexer of SyntaxHighlighter works. That should give you some idea on how to proceed. There are some other syntax highlighters to study as well in case this doesn't fit your purposes.

There is no "hard" enforced docstring format, but as with most of Python, only a "best practice" document. See the following PEP for the specification of how to use Docstrings and what they are, along with many Links for followup reading:
http://www.python.org/dev/peps/pep-0257/
You can also try looking at PyDoc, which is used internally by Python to display Docstrings. It can output HTML, but even if that is not sufficient, you should be able to transfer the Python source into JavaScript to write your own parser.

Related

Generate `avsc` files from `avdl` with pure JS

I know that it's possible to transform avdl to series of avsc files using java tools provided by Apache.
But despite the website lists plenty of implementations on different languages too, including JS, it seems to be that there is no support for avdl -> avsc conversion in these.
What would be your recommendation how to perform this conversion in pure JavaScript? Does such library even exists or we're forced to go through pure Java implementation always?
Java seems to be the only language that they implemented the compilation from avdl to avsc. The easiest route is probably just to have the avro-tools.jar somewhere and then have your JS code call out to that in some sub process to compile the schemas.
The other option would be to re-implement the IDL compiler in JS. I wouldn't do that, but the Java implementation is pretty much all contained within https://github.com/apache/avro/blob/master/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj if you wanted to take a look.

CoffeeScript-like language written in Python

Are there any languages targeting JavaScript (like CoffeeScript) and written in Python? I found Pyjamas, but it’s GWT of Python as I see. I want a language that doesn’t need heavy runtime library and is able to be compiled to JavaScript. I found Mascara also, and it very satisfies my requirements except it’s license. CoffeeScript is ideal for me except it’s written in CoffeeScript itself. I have to compile [CoffeeScript-like language] source codes into JavaScript statically in Python application.
You might want to have a look at pyjaco (python to javascript compiler).
Here's an example to get you started with manipulating the DOM in Python using jQuery:
https://github.com/chrivers/pyjaco/tree/devel/examples/jquery
Check this:
PyvaScript: http://www.allbuttonspressed.com/blog/django/2010/07/PyvaScript-Pythonic-syntax-for-your-browser
Pyjs: https://github.com/anandology/pyjs
Pyjamas: http://pyjs.org/
One part of Pyjamas is pyjs, which is decribed this way in the project overview:
pyjs translates Python code to Javascript by walking the Python abstract syntax tree and generating Javascript.
Sounds like it should fit the bill: no need to use the other parts of pyjamas you don't need.

Break up JavaScript file into more manageable, or using different IDE

I use Dreamweaver for development, mostly PHP, html, css, javascript. Is there anyway to break up JavaScript files? or maybe a better IDE that makes it easier to work with? It just becomes quickly difficult to read and find what I'm looking for.
Thank you!
Intellij and/or Webstorm by Jetbrains has the best JS tools I have found. It has very good (as good as it gets, for JS) intellisense (autocomplete for variables and methods) as well as refactoring for variables and methods. You can cmd+click into method definitions from anywhere, as well. Unfortunately you need to pay for them, but if you are using Dreamweaver you had to pay for that. If you are only doing html/css/javascript Webstorm is the way to go.
Yes, you should break up your javascript files into relevant parts just like you break up your php files into relevant parts. The one key factor here is they should be combined and minified before being served up to the browser so the user does not have to make several network calls to your server for each .js file.
Check out Google Minify for an easy solution to that issue.
Take a look at the JQuery source to see how they divvy up their files. Now look at their combined framework, and of course their minified framework. What is actually served up to the user looks nothing like the source.
Uh, Dreamweaver?
Definitely use a different IDE. Aptana won the poll here :)

Which library does GitHub use to beautify JavaScript code?

Which library does GitHub use to beautify JavaScript code?
I am looking for a good code prettify library.
http://help.github.com/troubleshooting-common-issues/
We use the excellent pygments library for our syntax highlighting. Check their list of supported languages and learn how to specify a lexer for yours. If you contribute a lexer back to pygments, let us know and we’ll make sure it’s made available here on GitHub.
Github do not appear to use any client side library to render code. You can see, using something like Chrome's Net tab, that the HTML views of code arrive from the server prewrapped with vast numbers of span elements.

Is there a Java byte code reader implemented in javascript?

I know there are lots of libraries that read byte codes that are written in Java. Does someone know of a byte code library that is implemented in Javascript?
Since javascript is typically run inside a browser, it generally cannot read the actual bytes out of files, which makes it less-than-ideal for reading java bytes. If you somehow got the byte codes encoded in a form that the javascript could read, what would you expect the library to do with it? Can you provide more details about what you're trying to do?
If you're looking to be able to write code in Java, and have it run inside a browser, take a look at GWT. It uses Java to recompile your byte-code into optimized javascript.
Edit
Based on your added comment, that you are hoping to "find out the classes and methods used in a jar file on my local disk":
Since javascript is unable to access files on a local disk (at least, without using ActiveX), the technology simply won't allow for this sort of thing. Is there a reason you wanted to use javascript for this, rather than java?
And please accept my apologies if it sounded like I was questioning your motives. I really just wanted to get enough information to be able to adequately answer your question.
Update:
It looks like the Japanese project I tried to link to below is long gone.
In any case, time has passed and now there are a couple of hits for "jvm in javascript" on Google. Namely:
Doppio
BicaVM
Look what I found:
http://ejohn.org/blog/running-java-in-javascript/
Does this help?
Edit: unfortunately it looks like the original project's site is dead.
You could try through the Web Archive, here (in Japanese, tried to Google translate it, but I guess it was too much indirection :))
For goodness sake, if you follow that link, run your download through an anti-virus.
I don't know if it's trustworhty.
There are compilers which can compile Java to JavaScript. As a last resort, you can use one of those compilers to take a JVML bytecode disassembler written in Java and compile it to JavaScript. One example of such a compiler is GWT.
Similarly, there are compilers which can compile JVML bytecode to JavaScript. Again, you can take one of the above JVML bytecode disassemblers written in Java, use any Java-to-JVML compiler (javac, ecj, gcj, …) to compile it to JVML (i.e. .class files), then compile those .class files to JavaScript.

Categories