 		else
 			@element.innerHTML = window.Milk.render(@template, @model)
 
-	# Do an inital update of the DOM
-	wrangler.update()
+# Add an event to the DOM.
+Wrangler.addEvent = (element, name, callback) ->
+	if element.addEventListener
+		element.addEventListener(name, callback, false)
+	else if element.attachEvent
+		element.attachEvent("on#{name}", callback)
 
-	# We're done!
-	return wrangler+# Escape some text to safe HTML.
+Wrangler.escape = (html) ->
+	html.replace(/&/g, '&amp;').replace(/</g, "&lt;").replace(/>/g, '&gt;').replace(/\ \ /g, '&nbsp;&nbsp;')


###

window.wrangle = (model, template, options) ->

	# Get the wrangler object we'll be returning
	wrangler = {}

	# Give this wrangler the model
	wrangler.model = model

	# Get template element
	if ($?) and (template instanceof $)
		template = template[0]
	if (typeof template is 'string') or (template instanceof String)
		template = document.getElementById(template)
	wrangler.element = template
	wrangler.template = template.innerHTML

	# Set a property and then update
	wrangler.set = (index, property, value) ->
		if value?
			@model[index][property] = value
		else
			@model[index] = property
		@update()

	# Update the DOM
	wrangler.update = ->
		if @model instanceof Array
			output = ''
			for m in @model

###

Wrangler
by Evan Hahn

Get your got'dang data into your got'dang webpage and stop worrying about it.

*******************************************************************************

Copyright (c) 2012, Fetchnotes LLC

