Tag Archives: javascript

Pet Project: Mechanic.js, a jQuery-esque UIAutomation library for iOS

March 12, 2012 | Jason Kozemczak

A few weeks back, I started working on a new project at work. Our client had a suite of iPad apps that had originally been written by an offshore IT firm. The many-tentacled beast of a codebase had nothing in the form of testing, so early on we started adding basic UATs and regressions where possible in order to safeguard the features of the various iPad apps (which had little to nothing in terms of documentation, etc).

As we worked to add UAT coverage with UIAutomation, I was growing tired of the rather verbose syntax that UIAutomation provides. Many of the functions available to UIAutomation elements have multiple versions of functions (tap, doubleTap, twoFingerTap, tapWithOptions, etc.), and no easy way to traverse an app’s element hierarchy.

I pined for a library that would make interacting with UIAElements as fun and simple as libraries like jQuery, Dojo, Zepto and the like have made interacting with the DOM. When I found there was no such library, I wrote my own: mechanic.js.

Mechanic gives you the element traversal features you know and love from CSS selector engines along with the ability to chain selector functions together. Convenience methods for much of the UIAutomation API have been provided in a “chained” version.

I’ve been working on an initial implementation this week, and API documentation and test coverage are my next concerns in the coming weeks. In the meantime, check it out on Github. If you find a missing or broken feature (and there surely are some), submit an issue (or just fix it yourself and send a pull request via Github.

Hopefully this is useful to more than just myself. Let me know what you think in the comments!

Introducing nCoffeeScript: a CoffeeScript compiler for Windows

January 8, 2011 | Jason Kozemczak

The wonderful CoffeeScript turned 1 (dot 0) over the Christmas break. For those who haven’t heard of it yet, I highly recommend you visit the site and look/play around. You can even check out the amazing annotated source for it, courtesy of its primary developer, Jeremy Ashkenas. The documentation is incredible actually.

In case Coffeescript is new to you, it’s a language that looks a lot like the lovechild of Ruby and Python, and it just so happens to compile into Javascript. If you visited the link above, you’d learn that it compiles 1-to-1 into Javascript. CoffeeScript’s compiled output is well-formed and well-performing Javascript. I could go on, but it’s probably best just to go to the site; it’ll do a far better job demonstrating its awesome-ness.

Poor Windows Developers…

CoffeeScript’s command-line compiler is implemented using Node.js; the downside to that fact is that there’s no easy way for Windows developers to integrate CoffeeScript into new and existing web apps. Since CoffeeScript is actually written in Javascript, it can be compiled in the browser, but this isn’t a very practical in an automated build/deploymen environment. CoffeeScript can also be compiled “on the fly” in a client’s browser, but this solution is not a viable production-level option.

Another possible solution is to install Cygwin, compile Node.js, and then download/install CoffeeScript, but this path is long and difficult, and still makes compiling from Windows arduous.

nCoffeeScript to the Rescue

The obvious solution to this problem was to create my own path. As such, I’ve created nCoffeeScript, a CoffeeScript compiler written in .NET for Windows environments! The source can be found on Github. Get the source, build it, and try it out. Let me know what you like and what you wish you could do with it!

I consider nCoffeeScript to be at v0.1 sort of state. I spent a few hours the past two nights getting the main use cases working, but haven’t put that much time into just yet.

Under the covers, nCoffeeScript uses Mozilla’s Rhino. nCoffeeScript interfaces with Rhino using IKVM for Java/.NET interoperability. nCoffeeScript is inspired by jCoffeeScript in its use of Rhino to execute the compilation process in Javascript.

Right now, you can use nCoffeeScript to compile an individual CoffeeScript file; you can also pass it a directory, and nCoffeeScript will compile each CoffeeScript file in the directory into its own Javascript file. By default, nCoffeeScript will wrap the compiled Javascript in a safety function. This wrapper can optionally be left out using the “/nowrap” command-line option.

For more details, visit the Github repo! Hopefully this is one step toward making it trivial to leverage CoffeeScript in our web applications. I hope to follow up with a possible path to utilizing nCoffeeScript in ASP.NET builds/deployments.