Skip to content

Just playing around with a DOM/JS implementation for Ruby using TheRubyRacer and Taka.

Notifications You must be signed in to change notification settings

Zapotek/dom-js-experiment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DOM/JS Ruby experiment

This repo holds a few simple experiments I do on my spare time to see how easy it is to create a DOM/JS environment with/for Ruby. The code is based on Taka and the V8 JS engine as provided by TheRubyRacer.

It goes without saying that the lib is far from usable.

Dependencies

To install all dependencies run: bundle install

Examples

See the tests and examples directory for examples.

Here's a quickie:

require_relative 'init'

html = <<EOHTML
<html>
    <head>
        <title>My title!</title>
    </head>

    <body>
        <div>
            <script type="text/javascript">
                document.write( '<h1>Hello</h1>' );
            </script>
        </div>
    </body>
</html>
EOHTML

window = DOM::Window.new( html )

# you'll see the updated HTML code
puts window.document.to_html

puts '-' * 80

# grab the automatically added element
h1 = window.eval( 'document.getElementsByTagName( "h1" )[0]' )
puts 'The first H1 is: ' + h1

answer = ( h1 == window.document.getElementsByTagName( 'h1' )[0] ) ? 'Yes' : 'No'
puts 'Does it work both ways? ' + answer

Author

Tasos "Zapotek" Laskos -- [email protected]

About

Just playing around with a DOM/JS implementation for Ruby using TheRubyRacer and Taka.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages