ruby-jquery 
ruby-jquery is a jQuery expression generator.
Synopsis
require 'jquery'
jQuery() #=> jQuery()
jQuery('a') #=> jQuery("a")
jQuery(:document) #=> jQuery(document)
jQuery('a').text() #=> jQuery("a").text()
jQuery('a').text('aaa') #=> jQuery("a").text("aaa")
jQuery('a').foo(['a', 'b']) #=> jQuery("a").foo(["a","b"])
jQuery('a').foo({'a' => 'b'}) #=> jQuery("a").foo({"a":"b"})
jQuery('a').click(->(f) { f.e 'return true' }) #=> jQuery("a").click(function (e) { return true })
jQuery('#content').show().on('click', 'a', ->(f) { f.e 'return true' })
#=> jQuery("#content").show().on("click","a",function (e) { return true })
With Selenium Driver
You can use this library with Selenium Driver for Ruby like below:
driver.execute_script(
"return " << jQuery('#content a').attr('href')
)
Installation
Add this line to your application's Gemfile:
gem 'ruby-jquery'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ruby-jquery
TODO
- Support property access (e.g.
jQuery.ajax(...)
andjQuery('a').length
). But can I do it with Ruby?
See Also
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request