Tuesday, March 4, 2008

Html-R: Make our Ruby HTML Pretty

What?

Html-R, an ajaxified online Ruby2HTML converter.

Why?

When you share your code online, it should look good and be readable, just like in your favorite text editor (emacs, right?).

With TextMate inspired syntax highlighting, Html-R quickly turns this



# Why's (Poignant) Guide to Ruby - The Endertrombe Wishmaker
require 'endertromb'
class WishMaker
def initialize
@energy = rand( 6 )
end
def grant( wish )
if wish.length > 10 or wish.include? ' '
raise ArgumentError, "Bad wish."
end
if @energy.zero?
raise Exception, "No energy left."
end
@energy -= 1
Endertromb::make( wish )
end
end
into that

# Why's (Poignant) Guide to Ruby - The Endertrombe Wishmaker
require 'endertromb'
class WishMaker
def initialize
@energy = rand( 6 )
end
def grant( wish )
if wish.length > 10 or wish.include? ' '
raise ArgumentError, "Bad wish."
end
if @energy.zero?
raise Exception, "No energy left."
end
@energy -= 1
Endertromb::make( wish )
end
end

How?

Using jQuery, there's a listener that sits and waits for changes to the source code. After new code appears, it sends a re quest to the server which uses the syntax gem to generate the appropriate html.

The appended css is of my own design, and is intended to mimic that of TextMate.

Here are screenshots of the step by step process. Or you can just demo it yourself.




No comments: