added translate.js and translate.coffee samples
Showing
4 changed files
with
52 additions
and
1 deletions
... | @@ -35,6 +35,7 @@ casper.evaluate(function(a, b) { | ... | @@ -35,6 +35,7 @@ casper.evaluate(function(a, b) { |
35 | - added [`Tester.assertTextDoesntExist()`](http://casperjs.org/api.html#tester.assertTextDoesntExist) | 35 | - added [`Tester.assertTextDoesntExist()`](http://casperjs.org/api.html#tester.assertTextDoesntExist) |
36 | - added `Tester.assertFalse()` as an alias of `Tester.assertNot()` | 36 | - added `Tester.assertFalse()` as an alias of `Tester.assertNot()` |
37 | - added `page.resource.requested` and `page.resource.received` events | 37 | - added `page.resource.requested` and `page.resource.received` events |
38 | - added [`translate.js`](https://github.com/n1k0/casperjs/tree/master/samples/translate.js) and [`translate.coffee`](https://github.com/n1k0/casperjs/tree/master/samples/translate.coffee) samples | ||
38 | 39 | ||
39 | 2012-10-31, v1.0.0-RC4 | 40 | 2012-10-31, v1.0.0-RC4 |
40 | ---------------------- | 41 | ---------------------- | ... | ... |
samples/translate.coffee
0 → 100644
1 | ### | ||
2 | Translation using the Google Translate Service. | ||
3 | |||
4 | Usage: | ||
5 | |||
6 | $ casperjs translate.coffee --target=fr "hello world" | ||
7 | bonjour tout le monde | ||
8 | ### | ||
9 | system = require("system") | ||
10 | casper = require("casper").create() | ||
11 | format = require("utils").format | ||
12 | source = casper.cli.get("source") or "auto" | ||
13 | target = casper.cli.get("target") | ||
14 | text = casper.cli.get(0) | ||
15 | result = undefined | ||
16 | |||
17 | casper.warn("The --target option is mandatory.").exit 1 unless target | ||
18 | |||
19 | casper.start(format("http://translate.google.com/#%s/%s/%s", source, target, text), -> | ||
20 | @fill "form#gt-form", text: text | ||
21 | ).waitForSelector "span.hps", -> @echo @fetchText("#result_box") | ||
22 | |||
23 | casper.run() |
samples/translate.js
0 → 100644
1 | /** | ||
2 | * Translation using the Google Translate Service. | ||
3 | * | ||
4 | * Usage: | ||
5 | * | ||
6 | * $ casperjs translate.js --target=fr "hello world" | ||
7 | * bonjour tout le monde | ||
8 | */ | ||
9 | var system = require('system'), | ||
10 | casper = require('casper').create(), | ||
11 | format = require('utils').format, | ||
12 | source = casper.cli.get('source') || 'auto', | ||
13 | target = casper.cli.get('target'), | ||
14 | text = casper.cli.get(0), | ||
15 | result; | ||
16 | |||
17 | if (!target) { | ||
18 | casper.warn('The --target option is mandatory.').exit(1); | ||
19 | } | ||
20 | |||
21 | casper.start(format('http://translate.google.com/#%s/%s/%s', source, target, text), function() { | ||
22 | this.fill('form#gt-form', {text: text}); | ||
23 | }).waitForSelector('span.hps', function() { | ||
24 | this.echo(this.fetchText("#result_box")); | ||
25 | }); | ||
26 | |||
27 | casper.run(); |
-
Please register or sign in to post a comment