New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReQL proposal: string templating #3353
Comments
If this feature is added, for obvious reasons it should mandate that the first argument to fmt is a string literal, not some other expression that may return a string, not an r.args expression or other expression. |
Thank you for the suggestion @marshall007 . This looks useful. |
very nice! |
Here's a quick and dirty client-side implementation I've been using in case anyone else finds it useful: r.fmt = function (template, params) {
var parts = template.split(/(\{\w+\})/g).map(function (part) {
if (part.indexOf('{') === 0) {
var name = part.slice(1, -1);
return params(name).coerceTo('string');
}
return part;
});
return r.add(r.args(parts));
}; Example usage: r.fmt('http://example.com/foos/{id}/bars?type={type}', r.expr({
id: 123,
type: 'tag'
}))
// => "http://example.com/foos/123/bars?type=tag" |
@marshall007 That's a very neat work-around! |
String building is a bit of a pain right now, at least in the JS driver. This is loosely related to #3048.
It would be nice to have something like this:
The text was updated successfully, but these errors were encountered: