Monday, April 04, 2011 at 1:06 AM.

radio2Suite.writeStaticFile

on writeStaticFile (adruser, relpath, filetext, type=nil) {
	<<Changes
		<<2/28/11; 8:43:43 AM by DW
			<<Add optional type param, defaults to nil.
		<<2/24/11; 10:57:04 AM by DW
			<<Generic static file-writer. Makes it easy to provide another rendering. 
	local (adrdata = radio2suite.init (), url = "", now = clock.now ());
	bundle { //save it to S3
		if adrdata^.prefs.s3enabled {
			url = s3.newobject (adrdata^.prefs.s3path + nameof (adruser^) + "/" + relpath, filetext, type);
			if sizeof (adrdata^.prefs.s3url) > 0 {
				url = adrdata^.prefs.s3url + nameof (adruser^) + "/"  + relpath}}};
	bundle { //save it to the user's S3 bucket
		if adruser^.prefs.s3bucket.enabled and (adruser^.prefs.s3bucket.path != "") {
			local (path = adruser^.prefs.s3bucket.path);
			if not (path beginswith "/") {
				path = "/" + path};
			if not (path endswith "/") {
				path = path + "/"};
			url = s3.newobject (path + relpath, filetext, type);
			if adruser^.prefs.s3bucket.url != "" {
				url = adruser^.prefs.s3bucket.url + relpath}}};
	adruser^.stats.ctStaticFileWrites++;
	adruser^.stats.whenLastStaticFileWrite = now;
	return (url)};
bundle { //test code
	webbrowser.openurl (writeStaticFile (@config.radio2.users.dave, "now.txt", string (clock.now ())))}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.