couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <jch...@apache.org>
Subject Re: Accessing design doc from view server code?
Date Tue, 16 Feb 2010 20:39:18 GMT
On Tue, Feb 16, 2010 at 11:05 AM, Zachary Zolton
<zachary.zolton@gmail.com> wrote:
> Should the require path start from the root of the ddoc object? Or
> should we create an arbitrary first term in the namespace?
>
> Given the design document:
> { "foo": "bar" }
>
> Should it be require("foo") or require("ddoc/foo") to get at "bar"?
>

I like "ddoc/foo" because in the future people may want to include
standard libraries in their couchjs server. Also having ddoc in the
code makes it clear where to put stuff if you want it to show up.

Chris

> -ZZ
>
> On Tue, Feb 16, 2010 at 11:58 AM, Chris Anderson <jchris@apache.org> wrote:
>> On Tue, Feb 16, 2010 at 9:25 AM, Filipe David Manana <fdmanana@gmail.com> wrote:
>>> Chris,
>>>
>>> looking at render.js:
>>>
>>>  function runShow(fun, ddoc, args) {
>>>    try {
>>>      resetList();
>>>      Mime.resetProvides();
>>>      var resp = fun.apply(ddoc, args) || {};
>>
>> Cool, looks like the work is already done. If anyone wants to write a
>> version of CommonJS require() that uses 'this' to load code from the
>> ddoc, it looks like the foundations are already laid.
>>
>> Chris
>>
>>>
>>> The scope under which the show function is executed is in fact the design
>>> doc. Same goes for _list, _update and _validate.
>>>
>>>
>>>
>>> On Tue, Feb 16, 2010 at 1:56 AM, J Chris Anderson <jchris@gmail.com> wrote:
>>>
>>>>
>>>> the design doc is available in the view server (in everything but map and
>>>> reduce functions), but it's not exposed to the sandbox (yet).
>>>>
>>>> I'd like to make it so the design doc is the value of 'this' when you are
>>>> inside _show, _list, etc functions.
>>>>
>>>> This would be a small patch if anyone is up for it.
>>>>
>>>> Chris
>>>>
>>>> >
>>>> >
>>>> > Cheers,
>>>> >
>>>> > Zach
>>>>
>>>>
>>>
>>>
>>> --
>>> Filipe David Manana,
>>> fdmanana@gmail.com
>>> PGP key - http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC569452B
>>>
>>> "Reasonable men adapt themselves to the world.
>>> Unreasonable men adapt the world to themselves.
>>> That's why all progress depends on unreasonable men."
>>>
>>
>>
>>
>> --
>> Chris Anderson
>> http://jchrisa.net
>> http://couch.io
>>
>



-- 
Chris Anderson
http://jchrisa.net
http://couch.io

Mime
View raw message