Mar 08
modulr is a CommonJS module implementation in Ruby for client-side JavaScript
Ruby? what does that have anything to do with it? Ah, its from one of those Prototype guys isn’t it…. Yup, Tobie is at it again, this time with modulr:
modulr accepts a singular file as input (the program) on which is does static analysis to recursively resolve its dependencies.
The program, its dependencies and a small, namespaced JavaScript library are concatenated into a single js file.
The bundled JavaScript library provides each module with the necessary require function and exports and module free variables.
This can also help sharing that CommonJS code. I recently did just that and had some:
JAVASCRIPT:
-
-
// check to see if you are running inside of node.js and export if you are
-
if (typeof GLOBAL == “object” && typeof GLOBAL[‘node’] == “object”) {
-
exports.Appetite = Appetite;
-
}
-
Continue reading »
Tagged with: clientside • CommonJS • implementation • JavaScript • module • modulr • Ruby
Feb 17
Martin Aumont has released Harmony, which “provides a simple DSL to execute JavaScript and DOM code within Ruby.”
This enables you to do very cool things such as unit test JavaScript in the same area as your Ruby tests:
RUBY:
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
and you can even use JavaScript libraries…. as script tags are autofetched:
RUBY:
require ‘harmony’
page = Harmony::Page.new(<<-HTML)
<html>
<head>
<script src="javascripts/jquery.js" type="text/javascript"></script>
</head>
<body>
<div id="widget">ohaie</div>
</body>
HTML
page.execute_js("$(‘#widget’).innerHTML") #=> "ohaie"
This library builds on the shoulders of giants, one of which is Mr. Johnson, John Barnette who I had the pleasure of working with many moons ago. He is the person I think of when I remember that the best engineers that I have worked with haven’t been computer scientists, but musicians and biologists. He is also a great fun guy.
Anyway, sorry for the aside.
If you are a Rails chap, you may also be interested in the Rails plugin holygrail.
Continue reading »
Tagged with: awesome • Bringing • enable • great • Harmony • Libraries • Ruby • Testing • together