Harmony
=======
.,ad88888888baa,
,d8P""" ""9888ba.
.a8" ,ad88888888888a
aP' ,88888888888888888a
,8" ,88888888888888888888,
,8' (888888888( )888888888,
,8' `8888888888888888888888
8) `888888888888888888888,
8 "8888888888888888888)
8 `888888888888888888)
8) "8888888888888888
(b "88888888888888'
`8, (8) 8888888888888)
"8a ,888888888888)
V8, d88888888888"
`8b, ,d8888888888P'
`V8a, ,ad8888888888P'
""88888888888888888P"
""""""""""""
Summary
-------
Harmony provides a simple DSL to execute javascript + DOM code within ruby.
Examples
--------
### Simple Javascript Parsing
require 'harmony'
page = Harmony::Page.new(<<-HTML)
Foo
HTML
page.execute_js("1+1") #=> 2
page.execute_js("document.title") #=> "Foo"
The Page object's `#execute_js` method (aliased as `#x` for convenience) takes a
string of javascript code, executes it and returns the last statement's value
(just like a ruby method).
### Javascript Unit Tests
One interesting use of Harmony is to test your javascript code within your ruby
application's own tests (test/unit, minitest, RSpec, nanotest, etc). Which
consequently means that you can now run browser-less, fully command-line
based, DOM-javascript tests.
require 'test/unit'
require 'harmony'
class JavascriptTest < Test::Unit::TestCase
def setup
@page = Harmony::Page.new
@page.load('public/javascripts/foo.js')
end
def test_foo
assert_equal "world", @page.execute_js(<<-JS)
foo = new Foo;
foo.hello();
JS
end
end
### DOM Handling
Don't be affraid to throw in your favorite client-side js framework, like
JQuery or Prototype. And notice that scripts linked to in `
ohaie