Is there a way to compile CoffeeScript to JavaScript code using JavaScript?
User writes CoffeeScript code to a textarea (or a codemirror editor..), and I want to compile the coffee code to js and execute it.
I know how to compile coffee to js with php, or other server side languages but I want to do it on client side.
Go to the CoffeeScript site and read the "text/coffeescript Script Tags" paragraph.
In fact, the little bit of glue script that runs "Try CoffeeScript" above, as well as the jQuery for the menu, is implemented in just this way. View source and look at the bottom of the page to see the example. Including the script also gives you access to CoffeeScript.compile() so you can pop open Firebug and try compiling some strings.
Don't forget the bare option, or else the compiled code will be wrapped
CoffeeScript.compile('alert "hello"', { bare: 'on' })
This project called js2coffee looks exactly what you need
Related
I'm taking over a flask project where the previous dev wrote quite a bit of their javascript/jquery in inline script tags in template files instead of separate js files in a static folder.
There's an issue with table cell highlight occuring after a long delay and I can't find the source in firefox/chrome debugger to step through the code. All the javascript I see is from the base template(can't see this either in chrome).
How do I view this injected template html and internal javascript in the debugger or is there another way to debug this without reworking the entire template and moving the javascript to another file?
I did not see in firefox debugger a javascript file that I placed in the static folder and referred from *.html file.After following this tutorial I saw that it is possible. I started commenting out parts from my application, hoping to find which part is causing this issue.In the end, I found out that my javascript file contained wrong syntax in one of the "if" conditions:
if foo() {
instead of
if (foo()) {
I would like to use this library (https://github.com/riichard/boolean-parser-js) (which is really just a function?) in my own project.
My project is contained in a single html file. In one of the functions, I've tried including the following:
var parser = require('boolean-parser');
I get the following error when I include this.
Uncaught ReferenceError: require is not defined
I have installed the library via the terminal, using "npm install boolean-parser". At the same level as my project, I see a file called "node_modules", which contains "boolean-parser".
I'm not sure if this is the right method of referring to the library...
I'm also not sure how to find out what it.
If possible, please explain terminology in your answer(s)-- I have limited background knowledge in this area, as this is essentially my first real web project!
Happy to include code upon request. Feel free to suggest tag additions!
P.S. Could it be a file path problem? Do I need to use something like Browserify?
P.P.S. If I include
<script src="node_modules/boolean-parser/index.js"></script>
then it seems like the library is working, but then I get an error from within it:
index.js:295 Uncaught ReferenceError: module is not defined
at index.js:295
It is because you are making client side project. Here is related question link
Listen, i created simple html page with 2 script tags. First contains src="index.js" which is in the same folder and edited as i said before. Second script tags is:
<script>
console.log(window.module):
</script>
And everything works. Check yourself again.
https://github.com/jamiebuilds/the-super-tiny-compiler
I've imported this project in Eclipse. When I compile and run "the-super-tiny-compiler.js", it gets terminated instantly. Why doesn't it asks us to input the source code, and why doesn't it show the compiled output? Is something missing in this code?
There's no "main" code in there or any code to read a source file (or read from stdin). Only a function that takes the source as a string.
So it looks like it's meant as a library and you'll have to write your own IO code if you want to turn it into a command line application.
Alternatively you could use it from an HTML page and get the source from a textarea.
I am trying to get the current working directory path using JavaScript.
When I execute from ubuntu: $root#ubuntu:/var/test/geek# firefox /var/www/application/test.html
I get /var/www/application in my alert box instead of /var/test/geek in my alert box.
I used the JavaScript code
var path=window.location.pathname
alert(path);
The above code gives the path of test.html
Editing: Is it possible to use a Perl script? Perl-CGI?
After knowing that it is not possible from JavaScript, tried to use a Perl script:
my $pwd=cwd();
and running the Perl script from HTML.
Executing from ubuntu: $root#ubuntu:/var/test/geek# firefox /var/www/application/test.html
I still get /var/www/application in page instead of /var/test/geek.
Is it possible from Perl?
I suggest not to rely on this. The pathname you got might not be the actual path. Most of the time, developers use the routing to hide the actual path.
The actual directory structure might be something like "D:\Test\Test\Test.html", but you will be getting something different due to routing.
Javascript in SoapUI How to's?
In SoapUI, you are allowed to write Groovy Scripts !
but since even javascript is also supported in SoapUI
how can we write a javascript in SoapUI Is there a simple example which would explain this in much detail.Is there any simple code for automating the process of testing using javascript.
To switch a project to JavaScript, click on the project, travel to the window in the bottom left hand corner. Select the script language field and update it to JavaScript.
As far as what you can do with it, you can really do anything. You can create a script step or assertion. Some examples would include creating a script to create variables or looping through a response to verify information. I didn't find much on using JavaScript with soapUI either, and ended up sticking with Groovy. I found it to be powerful and extendable via Java if needed.
If you want a specific example on how to do something. I'd recommend asking a more specific question with what you have tried so far.
So far I've got...
function myFunction() {
log.info('Hello');
}
myFunction();
Output shows up in script log, when I work out how to loop tests etc, will post…
I've not tried JavaScript, but I have developed my own java classes which I use for complex response checks.
You don't have to change the scripting language in SoapUI. To call Java class, I have a groovy step in my test, which instantiates an object from my java class and I then invoke a key method on the object. You can pass in the objects that SoapUI passes into the groovy script so you can then process the response.
The java scripts themselves live in the bin/scripts folder under SoapUI.
When working on a java class, I use an external editor like Brackets. When I save the change, SoapUI detects that change and recompiles the java class, so yup don't need to restart SoapUI after every tweak to your class.
The smart bear site and other places have tutorials to get you up and running.