You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/04/06 03:20:42 UTC

[8/40] git commit: Monkey patched file API to use JSON encoded map of known values

Monkey patched file API to use JSON encoded map of known values


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/95a46c62
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/95a46c62
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/95a46c62

Branch: refs/heads/master
Commit: 95a46c6211e7e258b94d182b172bdec075d49199
Parents: 0f9cb70
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Apr 3 17:46:38 2012 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Apr 3 17:46:38 2012 -0700

----------------------------------------------------------------------
 lib/wp7/exec.js |   59 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/95a46c62/lib/wp7/exec.js
----------------------------------------------------------------------
diff --git a/lib/wp7/exec.js b/lib/wp7/exec.js
index e90432e..8432e99 100644
--- a/lib/wp7/exec.js
+++ b/lib/wp7/exec.js
@@ -13,10 +13,56 @@ var cordova = require('cordova');
  * @param {String} service      The name of the service to use
  * @param {String} action       Action to be run in cordova
  * @param {String[]} [args]     Zero or more arguments to pass to the method
+
  */
+ 
+var MonkeyPatch = 
+{
+	File:
+	{
+		"getFileMetadata":function(arg)
+		{
+			return  {fullPath:arg[0]};
+		},
+		"readAsText":function(arg)
+		{ //[this.fileName, enc]
+			return {fileName:arg[0],encoding:arg[1]};
+		},
+		"readAsDataURL":function(arg)
+		{
+			return {fileName:arg[0]};
+		},
+		"getDirectory":function(arg)
+		{
+			return {fullPath:arg[0],path:arg[1],options:arg[2]};
+		},
+		"removeRecursively":function(arg)
+		{ 
+			return {fullPath:arg[0]};
+		},
+		"getFile":function(arg)
+		{
+			return {fullPath:arg[0],path:arg[1],options:arg[2]};
+		},
+		"readEntries":function(arg)
+		{
+			return {fullPath:arg[0]};
+		},
+		"write":function(arg)
+		{
+			return {fileName:arg[0],data:arg[1],position:arg[2]};
+		},
+		"truncate":function(arg)
+		{
+			return {fileName:arg[0],size:arg[1]};
+		}
+
+	}
+};
 
 module.exports = function(success, fail, service, action, args) 
 {
+
     var callbackId = service + cordova.callbackId++;
     if (typeof success == "function" || typeof fail == "function") 
 	{
@@ -24,10 +70,15 @@ module.exports = function(success, fail, service, action, args)
     }
     // generate a new command string, ex. DebugConsole/log/DebugConsole23/{"message":"wtf dude?"}
 	
-	if(args && args.length && args.length == 1)
-	{
-		args = args[0];	
-	}
+	 if(MonkeyPatch[service] && MonkeyPatch[service][action])
+	 {
+		console.log("MonkeyPatching " + service + "." + action);
+		args =  MonkeyPatch[service][action](args);
+	 }
+	 else if(args && args.length && args.length == 1)
+	 {
+		 args = args[0]; 
+	 }
 	
      var command = service + "/" + action + "/" + callbackId + "/" + JSON.stringify(args);
      // pass it on to Notify