Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
H

harmony

> 编程语言
Open source

Javascript + DOM in your ruby, the simple way

444 stars0 likes2 views
WebsiteGitHub

About

Javascript + DOM in your ruby, the simple way

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(
    
      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 
    
      

    
  
HTML

page.execute_js("$('#widget').innerHTML") #=> "ohaie"

Fetching Documents

Use Harmony::Page.fetch(uri) to create a page from a remote document.

require 'harmony'

page = Harmony::Page.fetch('http://example.com')
page.execute_js('document.title') #=> "Example Web Page"

fetch also accepts "file://" uris.

Install

# There's a gem dependency bug in rubygems currently, so we'll have to
# install some dependencies manually. This will be fixed soon.
gem install stackdeck
gem install johnson -v "2.0.0.pre3"

gem install harmony

See Also

  • holygrail: Harmony plugin for Rails tests

Acknowledgement

Harmony is a thin DSL wrapper around three amazing libs, Johnson, env.js and Envjs . The authors of those libs have been doing a huge amount of great work for quite a while, so please go recommend them on WorkingWithRails right now and/or follow them on github:

jbarnette, tenderlove, smparkes, wycats, matthewd, thatcher, jeresig

Special thanks go to smparkes for his patient help, and for providing the last puzzle pieces that made everything work together.

Links

  • code:
  • docs:
  • wiki:
  • bugs:

YinYang ASCII art is © Normand Veilleux (nveilleuATemr1.emrDOTca)

Issues· 5 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言