ragex logo Wipes away the cruft of XHTML

General Information

What is ragex?

Ragex is a ruby library for generating valid XHTML. It offers two (mixable) styles: Block-based (preferred) and stateful. Most XHTML tags are supported currently (v0.2.1), and new ones can be added very easily.
This page was generated using ragex. The source file can be found here.
View some small examples here.
If you have any comments or suggestions please contact me at: peter@metaclassofnil.com

Design goals

User quotes

Get it

Ragex is just one file (ragex.rb) with no dependencies.
Additionally, there's ragexex.rb with some additional stuff which needs the 'syntax' gem.

Examples

Hello World

r = Ragex.new
r.html {
	head {
		title { "Hello Ragex" }
		meta("author", "Peter Thoman")
	}
	body {
		div("header") { "I'm a header" }
		div("box") {
			h1 { "What you say??" }
			em { "Hello World" }
			img("image.png", "I'm an alt tag.")
		}
	}
}

Alternative style

Use only if you can't use block style for some reason ;)

r = Ragex.new
r.html_s      # or html_start or html_o or html_open
r.head_s
r.title { "Hello Ragex" }
r.meta("author", "Peter Thoman")
r.head_e      # or head_end/head_c/head_close or just close/c/end/e (automagic)
r.body_s
r.div_s("header") 
r.t "I'm a header"
div("box") {
h1 { "What you say??" }
	em { "Hello World" }
}
r.close_all   # closes all open tags (also c_a, end_all, e_a)

Forms

Could still be easier, probably in future ragexex versions.

form("cgi.cgi", "post") {
	fieldset { 
		select("selector") {
			optgroup("First Group") { option{"O1"}; option{"O2"} }
			optgroup("Second Group") { option{"O3"}; option{"O4"} }
		} 
		br
		textarea("area", 4, 40) { "Area default text" } # nonstring params
		br
		button("submitter", "submit") { "Foo me" }
	}
}

Other stuff

r = Ragex.new(stream) # redirects output to stream
r.p { '&"<>' } # html entities are replaced automatically

ul {
	li { tt(:style=>"font-size:large") { "Code" } } # use nondefault attribs
	li { a("http://metaclassofnil.com") {"I link to a great site!"} }
}

Links

Here are some related (or not) links: