From 94069c43ead315893ae602382fec4297a07124a8 Mon Sep 17 00:00:00 2001 From: rgieseke Date: Fri, 22 Apr 2011 17:39:51 +0200 Subject: [PATCH] Add Coffeescript version of direction.js. --- examples/direction.coffee | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/direction.coffee diff --git a/examples/direction.coffee b/examples/direction.coffee new file mode 100644 index 0000000000..34b23af8a1 --- /dev/null +++ b/examples/direction.coffee @@ -0,0 +1,28 @@ +# Get driving direction using Google Directions API. + +if phantom.state.length is 0 + if phantom.args.length < 2 + console.log 'Usage: direction.js origin destination' + console.log 'Example: direction.js "San Diego" "Palo Alto"' + phantom.exit(1) + origin = phantom.args[0] + dest = phantom.args[1] + phantom.state = origin + ' to ' + dest + phantom.open(encodeURI('http://maps.googleapis.com/maps/api/directions/xml?origin=' + origin + + '&destination=' + dest + '&units=imperial&mode=driving&sensor=false')) +else + if phantom.loadStatus is 'fail' + console.log 'Unable to access network' + else + steps = phantom.content.match(/(.*)<\/html_instructions>/ig); + if not steps + console.log 'No data available for ' + phantom.state + else + for ins in steps + ins = ins.replace(/\</ig, '<').replace(/\>/ig, '>'); + ins = ins.replace(/\
/g, ''); + console.log(ins); + console.log '' + console.log phantom.content.match(/.*<\/copyrights>/ig).join('').replace(/<.*?>/g, '') + phantom.exit()