Skip to content

Commit

Permalink
fixed issue #15
Browse files Browse the repository at this point in the history
  • Loading branch information
impronunciable committed Dec 17, 2012
1 parent 3a35ba1 commit e6f9788
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/cartodb.js
Expand Up @@ -195,10 +195,10 @@ CartoDB.prototype.query = function(_sql, args, fn) {
* tmpl("Hi {name}", {name: 'rambo'}) renders "Hi rambo"
*/

function tmpl(s,d){
for(var p in d) s = s.replace('{'+p+'}', d[p]);
return s;
}
var tmpl = CartoDB.tmpl = function(s,d){
for(var p in d) s = s.replace(new RegExp('{'+p+'}', 'g'), d[p]);
return s;
};

/*
* check if the user wants to write to the db
Expand Down
17 changes: 17 additions & 0 deletions test/client.template.js
@@ -0,0 +1,17 @@
var assert = require('assert');
var CartoDB = require('../');
var secret = require('./secret');

describe('Templates', function() {

describe('Can handle multiple ocurrences', function() {

it("should return true for insert", function(done) {
var template = CartoDB.tmpl("InSerT into table {table_id} values ({id}, {table_id}, {id})", {id: 1, table_id: 45});
assert.equal(template, "InSerT into table 45 values (1, 45, 1)");
done();
});
});

});

0 comments on commit e6f9788

Please sign in to comment.