view editor.tp @ 24:fe3533494ce9

Display symbols order first by depth. Eliminate extraneous setter symbols
author Mike Pavone <pavone@retrodev.com>
date Tue, 27 Mar 2012 00:39:32 -0700
parents 068d63627b16
children 4d87c38404d6
line wrap: on
line source

#{
//mquery functions
q <- foreign: :query {}
qall <- foreign: :query {}
each <- foreign: :iterable fun {}
addClass <- foreign: :node className {}
removeClass <- foreign: :node className {}
get <- foreign: :url onSuccess onFail onOther {}
newEl <- foreign: :tagname props {}

//TP Parser
parser <- foreign: #{
	parse <- foreign: :str {}
}

//js builtins
console <- foreign: #{
	log <- foreign: :val {}
}
window <- #{}
Object <- foreign: #{
	keys <- foreign: :object {}
}

//kernel definitions
true <- #{
  if:else <- :self trueblock :elseblock {
    trueblock:
  }
}

false <- #{
  if:else <- :self trueblock :elseblock {
    elseblock:
  }
}

editFile <- :path {
	get: path :request {
		addClass: (q: "body") "editorMode"
		src <- request responseText
		console log: src
		ast <- parser parse: src
		console log: ast
		ast populateSymbols: (foreign: null)
		ast toHTML: (q: "#src")
	}
}

symbolClick <- :domnode astnode {
	inscope <- q: "#inscope"
	inscope innerHTML!: ""
	console log: astnode
	syms <- (astnode symbols) allSymbols
	each: syms :idx key {
		inscope appendChild: (newEl: "li" #{
			textContent <- key
		})
	}
}

//editor code
main <- {
	//bind handlers for file browser links
	each: (qall: "a") :idx el {
		el onclick!: :event {
			link <- foreign: this
			path <- link href
			path <- path substr: (path indexOf: "/edit/") + 5
			console log: path
			editFile: path
			foreign: false
		}
	}
	
	//bind handlers for editor buttons
	each: (qall: ".controls li") :idx el {
		el onclick!: :event {
			srcel <- (q: "#src")
			srcel textContent!: (srcel textContent) + (el textContent)
		}
	}
	(q: "#ops_button") onclick!: :event {
		addClass: (q: ".controls") "showops"
	}
	
	path <- (window location) pathname
	if: (path indexOf: "/edit/") = 0 {
		editFile: (path substr: 5)
	} else: {}
}

}