Logging "<<print $name>>","saved this!"\n\n<<logdata $name "saved this!" "demo1">>\n\n<html>See it <a target='blank' href='https://docs.google.com/spreadsheet/ccc?key=0AkU0AKJLROGEdFJ6Sk44SV9MVkJwUER5LW12Z2sxLXc&usp=sharing'>here</a>\n\n<p>\n <a href='GoogleSpreadsheetMacros.zip'>Download macro and server files</a>\n</p>\n</html>\n\n[[Back|Start]]
\nEnter your name:\n\n<<textinput "name" "Logging" "Now log it" >>
// CONFIGURATION\n// Edit base urls to point to the directory containing the log.php, fetch.php files:\n\nvar lalanl_baseLoggingUrl = "http://devonbaumgarten.com/twine/macros/gdoc/";\nvar lalanl_baseFetchUrl = "http://devonbaumgarten.com/twine/macros/gdoc/";\n\n//===========================\n\nlalanl_logging = {\n baseUrl: lalanl_baseLoggingUrl,\n debugMode: (!window.version),\n logData: function(name, data, sheet, callback){ \n jQuery.ajax({\n url:this.baseUrl+'log.php',\n method:'POST',\n data:{name:name, data:data, sheet:sheet},\n success:function(e){\n response = e; \n try{\n console.log(e);\n if(callback)callback(e);\n }catch(ex){\n console.log('Error: ', e);\n }\n },\n });\n }\n};\n\ntry{\n if(!lalanl_logging.debugMode)(function () {\n var script = document.createElement('script');\n script.src = 'http://code.jquery.com/jquery-1.10.2.min.js';\n script.onload = function f(){ \n $.noConflict(); \n console.log("loaded jquery");\n }\n document.body.appendChild(script);\n console.log("loading jquery...");\n })();\n\n if(lalanl_logging.debugMode){\n window.version = {extensions:[]};\n window.macros = [];\n }\n\n version.extensions['lalanl_logging'] = {\n major:1,minor:0,revision:0\n }; \n \n macros['logdata'] = {\n handler: function(p,m,params,parser){\n try{\n var args = [];\n for(p in params){\n if(params[p].toString().substring(0,1)=='$'){\n args[p] = state.history[0].variables[params[p].substring(1,params[p].length)];\n args[p] = args[p] || params[p];\n }\n else args[p] = params[p];\n }\n lalanl_logging.logData(args[0], args[1], args[2], args[3]);\n }catch(e){\n // don't break if logging fails.\n }\n },\n init: function(){}\n };\n} catch (e){\n console.log("ERROR: " + e);\n}\n\nvar lalanl_fetch = {\n baseUrl: lalanl_baseFetchUrl,\n debugMode: (!window.version), //'Name','MonsterId','2','fetch1'\n fetchData: function(fetchCol, keyCol, key, sheet, callback){ \n \n var result = null;\n jQuery.ajax({\n method:'POST',\n url:'fetch.php',\n data:{"sheet":sheet, "keyCol":keyCol, "key":key, "fetchCol":fetchCol},\n dataType:'json',\n async:false,\n success:function(e){\n console.log(e, callback);\n if(callback)callback(e);\n console.log('returning ', e.value);\n result = e.value;\n },\n error:function(e){\n console.log("Fetch Error: " + e.responseText || JSON.stringify(e));\n }\n });\n return result;\n }\n};\n\ntry{\n if(!lalanl_fetch.debugMode)(function () {\n window.onload=function(){\n var script = document.createElement('script');\n script.src = 'http://code.jquery.com/jquery-1.10.2.min.js';\n script.onload = function f(){ \n $.noConflict(); \n console.log("loaded jquery");\n }\n document.body.appendChild(script);\n console.log("loading jquery...");\n };\n })();\n\n if(lalanl_fetch.debugMode){\n window.version = {extensions:[]};\n window.macros = [];\n }\n\n version.extensions['lalanl_fetch'] = {\n major:1,minor:0,revision:0\n }; \n \n \n \n macros['fetch'] = {\n handler: function(p,m,params,parser){\n try{\n var args = [];\n console.log('before parse');\n for(p in params){\n if(params[p].toString().substring(0,1)=='$'){\n args[p] = state.history[0].variables[params[p].substring(1,params[p].length)];\n args[p] = args[p] || params[p];\n }\n else args[p] = params[p];\n }\n console.log('before fetch', args);\n var v = lalanl_fetch.fetchData(args[0], args[1], args[2], args[3], args[5]);\n console.log('Received ', v);\n var variable = args[4];\n if(variable[0] == '$') variable = variable.substring(1,variable.length);\n try{state.history[0].variables[variable] = v;}catch(e){console.log('Cannot assign variable');}\n return v;\n }catch(e){\n console.log('Error: ', e);\n }\n },\n init: function(){}\n };\n} catch (e){\n console.log("ERROR: " + e);\n}
Google Docs Spreadsheet Macro Demo\n<html><a href='http://twitter.com/lalanl'>@lalanl</a></html>\n\nRequires a webserver capable of running PHP (won't work in dropbox, sorry).\n\n[[Try Logging]]\n[[Try Fetching]]\n<html>\n<p>\n <a href='GoogleSpreadsheetMacros.zip'>Or just download the macro and server files</a>\n</p>\n</html>
\nUsing < <fetch description monsterid 2 fetch1 $myMonster> > \n<<fetch description monsterid 2 fetch1 $myMonster>>\n\nThe monster we fetched is <<print $myMonster>> \n\n<html>See the source sheet <a target='blank' href='https://docs.google.com/spreadsheet/ccc?key=0AkU0AKJLROGEdFBabk1rLUVXZUVrNzEybTNmeHVHOWc&usp=sharing'>here</a>\n\n<p>\n <a href='GoogleSpreadsheetMacros.zip'>Download macro and server files</a>\n</p>\n</html>\n\n[[Back|Start]]
Google Docs Spreadsheet Macro Demo
a{color:#4d6ad8;;text-decoration:none}\na:hover{color:#8ea6ff;text-decoration:none}