Reputation: 963
I'm newbie with coffescript and I'm trying use coffee instead javascript for this example:
http://blog.nodejitsu.com/jsdom-jquery-in-5-lines-on-nodejs
var request = require('request'),
jsdom = require('jsdom');
request({ uri:'http://www.google.com' }, function (error, response, body) {
if (error && response.statusCode !== 200) {
console.log('Error when contacting google.com')
}
jsdom.env({
html: body,
scripts: [
'http://code.jquery.com/jquery-1.5.min.js'
]
}, function (err, window) {
var $ = window.jQuery;
// jQuery is now loaded on the jsdom window created from 'agent.body'
console.log($('body').html());
});
});
my coffee code is this:
request = require 'request'
sys = require 'sys'
jsdom = require 'jsdom'
request uri: 'http://www.google.com' , (error,response,body) ->
console.log "hay un error al conectar" if error && response.statusCode !=200
#sys.puts(body)
jsdom.env html : body , scripts : ['http://code.jquery.com/jquery-1.5.min.js'], (err, window) ->
$ = window.JQuery
console.log( $('body').html())
when compile and run it..this does nothing...I've inspected the compile code and for me it's ok and I've used the converter from http://jashkenas.github.com/coffee-script/ and the generated code is almost exactly to my js code...
In this code I have omitted several brackets but I've tried with these too and didn't work neither I don't know where is the mistake
thanks for read and help :D
Upvotes: 1
Views: 318
Reputation: 46569
I ran your code thru http://js2coffee.org/ and got this. There are some small differences but the capital J in JQuery is the most likely culprit.
request = require("request")
jsdom = require("jsdom")
request
uri: "http://www.google.com"
, (error, response, body) ->
console.log "Error when contacting google.com" if error and response.statusCode isnt 200
jsdom.env
html: body
scripts: ["http://code.jquery.com/jquery-1.5.min.js"]
, (err, window) ->
$ = window.jQuery
# jQuery is now loaded on the jsdom window created from 'agent.body'
console.log $("body").html()
Upvotes: 1