You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Aliaksandr Barysiuk <a....@gmail.com> on 2012/10/09 17:08:01 UTC
Couchdb and Handlebars
Hello,
I faced with issues when i have tried to use Handlebars (http://handlebarsjs.com/) in my show function. It seems it's
CommonJS compliant but following simple example fails...
function(doc, req) {
var Handlebars = require('lib/handlebars');
var source = "<div>{{user}}</div>"
var template = Handlebars.compile(source);
return template( { user:"John" } );
}
...with error:
{"error":"render_error","reason":"function raised error: (new TypeError(\"Handlebars.compile is not a function\", \"\",
4) ...
log(Handlebars) prints "Log :: {"parser":{"yy":{}}}".
So the problem is to find how to create Handlebars instance. Could somebody advise?
Thank you
Re: Couchdb and Handlebars
Posted by "matt j. sorenson" <ma...@sorensonbros.net>.
couple more resources I'm aware of, but haven't used personally (so ymmv)...
kanso (a couchapp generator) had/has a handlebars package:
http://kan.so/packages/details/handlebars
and I found this plugin on github w/a quick search:
https://github.com/SlexAxton/require-handlebars-plugin
--
*matt j. sorenson*
On Wed, Oct 10, 2012 at 3:44 AM, Aliaksandr Barysiuk
<a....@gmail.com>wrote:
> Robin,
>
> Thank's for the answer. But does Couchdb support AMD modules? I only found
> CommonJS info ( http://wiki.apache.org/**couchdb/CommonJS_Modules<http://wiki.apache.org/couchdb/CommonJS_Modules>
> ).
>
> However using patched Handlebars with 'require('lib/handlebars')' or
> 'require(['lib/handlebars'], function(module) { ...})' failed. The former
> with 'define is not defined' error, the latter with 'name.split is not a
> function' error.
>
>
> On 10/10/12 10:49, Robin Berjon wrote:
>
>> Hi,
>>
>> On 09/10/2012 17:08 , Aliaksandr Barysiuk wrote:
>>
>>> I faced with issues when i have tried to use Handlebars
>>> (http://handlebarsjs.com/) in my show function. It seems it's CommonJS
>>> compliant but following simple example fails...
>>>
>>> function(doc, req) {
>>>
>>> var Handlebars = require('lib/handlebars');
>>> var source = "<div>{{user}}</div>"
>>> var template = Handlebars.compile(source);
>>> return template( { user:"John" } );
>>> }
>>>
>>> ...with error:
>>>
>>> {"error":"render_error","**reason":"function raised error: (new
>>> TypeError(\"Handlebars.compile is not a function\", \"\", 4) ...
>>>
>>
>> This looks like Handlebars is not AMD friendly. It probably tries to
>> define a global Handlebars object, which obviously won't work here.
>>
>> What you need to do is wrap the lib so that it'll work with AMD. I
>> haven't checked it out closely, but maybe this patch can help:
>>
>> https://github.com/wycats/**handlebars.js/pull/187<https://github.com/wycats/handlebars.js/pull/187>
>>
>>
>
Re: Couchdb and Handlebars
Posted by Aliaksandr Barysiuk <a....@gmail.com>.
Robin,
Thank's for the answer. But does Couchdb support AMD modules? I only found CommonJS info (
http://wiki.apache.org/couchdb/CommonJS_Modules).
However using patched Handlebars with 'require('lib/handlebars')' or 'require(['lib/handlebars'], function(module) {
...})' failed. The former with 'define is not defined' error, the latter with 'name.split is not a function' error.
On 10/10/12 10:49, Robin Berjon wrote:
> Hi,
>
> On 09/10/2012 17:08 , Aliaksandr Barysiuk wrote:
>> I faced with issues when i have tried to use Handlebars
>> (http://handlebarsjs.com/) in my show function. It seems it's CommonJS
>> compliant but following simple example fails...
>>
>> function(doc, req) {
>>
>> var Handlebars = require('lib/handlebars');
>> var source = "<div>{{user}}</div>"
>> var template = Handlebars.compile(source);
>> return template( { user:"John" } );
>> }
>>
>> ...with error:
>>
>> {"error":"render_error","reason":"function raised error: (new
>> TypeError(\"Handlebars.compile is not a function\", \"\", 4) ...
>
> This looks like Handlebars is not AMD friendly. It probably tries to define a global Handlebars object, which
> obviously won't work here.
>
> What you need to do is wrap the lib so that it'll work with AMD. I haven't checked it out closely, but maybe this
> patch can help:
>
> https://github.com/wycats/handlebars.js/pull/187
>
Re: Couchdb and Handlebars
Posted by Robin Berjon <ro...@berjon.com>.
Hi,
On 09/10/2012 17:08 , Aliaksandr Barysiuk wrote:
> I faced with issues when i have tried to use Handlebars
> (http://handlebarsjs.com/) in my show function. It seems it's CommonJS
> compliant but following simple example fails...
>
> function(doc, req) {
>
> var Handlebars = require('lib/handlebars');
> var source = "<div>{{user}}</div>"
> var template = Handlebars.compile(source);
> return template( { user:"John" } );
> }
>
> ...with error:
>
> {"error":"render_error","reason":"function raised error: (new
> TypeError(\"Handlebars.compile is not a function\", \"\", 4) ...
This looks like Handlebars is not AMD friendly. It probably tries to
define a global Handlebars object, which obviously won't work here.
What you need to do is wrap the lib so that it'll work with AMD. I
haven't checked it out closely, but maybe this patch can help:
https://github.com/wycats/handlebars.js/pull/187
--
Robin Berjon - http://berjon.com/ - @robinberjon