Skip to content

Commit

Permalink
adding a Makefile and caching the latest coffee output for people
Browse files Browse the repository at this point in the history
who wont like just a coffee src file
  • Loading branch information
joenoon committed Sep 27, 2011
1 parent dfbd809 commit 3e2750b
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
all: coffee

coffee:
mkdir -p build
coffee -p src/sqlite_plugin.js.coffee > build/sqlite_plugin.js

clean:
rm -f build/sqlite_plugin.js
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ Installing
Drag .h and .m files into your project's Plugins folder (in xcode) -- I always
just have "Create references" as the option selected.

Compile the coffeescript file to javascript WITH the top-level function wrapper
option (default).
Take the precompiled javascript file from build/, or compile the coffeescript
file in src/ to javascript WITH the top-level function wrapper option (default).

Use the resulting javascript file in your HTML.

Expand Down
121 changes: 121 additions & 0 deletions build/sqlite_plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
(function() {
var callbacks, counter, fnref, getOptions, root;
root = this;
callbacks = {};
counter = 0;
fnref = function(fn) {
var f;
f = "cb" + (counter += 1);
callbacks[f] = fn;
return f;
};
getOptions = function(opts, success, error) {
if (typeof success === "function") {
opts.successCallback = fnref(success);
}
if (typeof error === "function") {
opts.errorCallback = fnref(error);
}
return opts;
};
root.PGSQLitePlugin = (function() {
PGSQLitePlugin.prototype.openDBs = {};
function PGSQLitePlugin(dbPath, openSuccess, openError) {
this.dbPath = dbPath;
this.openSuccess = openSuccess;
this.openError = openError;
if (!dbPath) {
throw new Error("Cannot create a PGSQLitePlugin instance without a dbPath");
}
this.openSuccess || (this.openSuccess = function() {
console.log("DB opened: " + dbPath);
});
this.openError || (this.openError = function(e) {
console.log(e.message);
});
this.open(this.openSuccess, this.openError);
}
PGSQLitePlugin.handleCallback = function() {
var args, f, _ref;
args = Array.prototype.slice.call(arguments);
f = args.shift();
if ((_ref = callbacks[f]) != null) {
_ref.apply(null, args);
}
callbacks[f] = null;
delete callbacks[f];
};
PGSQLitePlugin.prototype.executeSql = function(sql, success, error) {
var opts;
if (!sql) {
throw new Error("Cannot executeSql without a query");
}
opts = getOptions({
query: [].concat(sql || []),
path: this.dbPath
}, success, error);
PhoneGap.exec("PGSQLitePlugin.backgroundExecuteSql", opts);
};
PGSQLitePlugin.prototype.transaction = function(fn, success, error) {
var t;
t = new root.PGSQLitePluginTransaction(this.dbPath);
fn(t);
return t.complete(success, error);
};
PGSQLitePlugin.prototype.open = function(success, error) {
var opts;
if (!(this.dbPath in this.openDBs)) {
this.openDBs[this.dbPath] = true;
opts = getOptions({
path: this.dbPath
}, success, error);
PhoneGap.exec("PGSQLitePlugin.open", opts);
}
};
PGSQLitePlugin.prototype.close = function(success, error) {
var opts;
if (this.dbPath in this.openDBs) {
delete this.openDBs[this.dbPath];
opts = getOptions({
path: this.dbPath
}, success, error);
PhoneGap.exec("PGSQLitePlugin.close", opts);
}
};
return PGSQLitePlugin;
})();
root.PGSQLitePluginTransaction = (function() {
function PGSQLitePluginTransaction(dbPath) {
this.dbPath = dbPath;
this.executes = [];
}
PGSQLitePluginTransaction.prototype.executeSql = function(sql, success, error) {
this.executes.push(getOptions({
query: [].concat(sql || []),
path: this.dbPath
}, success, error));
};
PGSQLitePluginTransaction.prototype.complete = function(success, error) {
var begin_opts, commit_opts, executes, opts;
if (this.__completed) {
throw new Error("Transaction already run");
}
this.__completed = true;
begin_opts = getOptions({
query: ["BEGIN;"],
path: this.dbPath
});
commit_opts = getOptions({
query: ["COMMIT;"],
path: this.dbPath
}, success, error);
executes = [begin_opts].concat(this.executes).concat([commit_opts]);
opts = {
executes: executes
};
PhoneGap.exec("PGSQLitePlugin.backgroundExecuteSqlBatch", opts);
this.executes = [];
};
return PGSQLitePluginTransaction;
})();
}).call(this);
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ callbacks = {}
counter = 0

fnref = (fn) ->
f = "_sqliteplugin#{counter+=1}"
f = "cb#{counter+=1}"
callbacks[f] = fn
f

Expand Down

0 comments on commit 3e2750b

Please sign in to comment.