You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Dave <da...@myheartisagapinghole.com> on 2009/01/09 23:03:38 UTC

Adding functions to the JavaScript global object for use in views

Hi,

I was wondering if there was a standard way to add helper functions or
augment the built-in data types (Array, Date, etc.) in the JavaScript
global object used by couch db for map/reduce functions. My motivation
here is to add some code for parsing ISO8601 date strings into
JavaScript Date objects for the purpose of view collation in multiple
views.

Thanks,

Dave

Re: Adding functions to the JavaScript global object for use in views

Posted by Chris Anderson <jc...@gmail.com>.
On Sat, Jan 10, 2009 at 12:18 PM, Dean Landolt <de...@deanlandolt.com> wrote:

>>
>
> is this related to the !json and !code macros I've seen in the sofa code?

yes. CouchApp is what executes those http://github.com/jchris/couchapp

> Is
> what executes these macros buried in couch trunk or is it something else?
>

It has nothing to do with Apache CouchDB, it's just a script that push
your filesystem to a design document

-- 
Chris Anderson
http://jchris.mfdz.com

Re: Adding functions to the JavaScript global object for use in views

Posted by Dean Landolt <de...@deanlandolt.com>.
On Sat, Jan 10, 2009 at 1:15 PM, Chris Anderson <jc...@gmail.com> wrote:

> On Fri, Jan 9, 2009 at 2:03 PM, Dave <da...@myheartisagapinghole.com>
> wrote:
> > Hi,
> >
> > I was wondering if there was a standard way to add helper functions or
> > augment the built-in data types (Array, Date, etc.) in the JavaScript
> > global object used by couch db for map/reduce functions. My motivation
> > here is to add some code for parsing ISO8601 date strings into
> > JavaScript Date objects for the purpose of view collation in multiple
> > views.
> >
>
> The preferred way to do this is to add the library code itself to your
> function. I use a script designed to push filesystem contents to
> design documents. It has an ability to inline additional JavaScript
> into your functions.
>
> I'm in the middle of extracting it to its own project, so the install
> will be getting easier, but the Ruby code is available here:
>
> http://github.com/jchris/couchapp/tree/master
>
> --
> Chris Anderson
> http://jchris.mfdz.com
>

is this related to the !json and !code macros I've seen in the sofa code? Is
what executes these macros buried in couch trunk or is it something else?

Re: Adding functions to the JavaScript global object for use in views

Posted by Chris Anderson <jc...@gmail.com>.
On Fri, Jan 9, 2009 at 2:03 PM, Dave <da...@myheartisagapinghole.com> wrote:
> Hi,
>
> I was wondering if there was a standard way to add helper functions or
> augment the built-in data types (Array, Date, etc.) in the JavaScript
> global object used by couch db for map/reduce functions. My motivation
> here is to add some code for parsing ISO8601 date strings into
> JavaScript Date objects for the purpose of view collation in multiple
> views.
>

The preferred way to do this is to add the library code itself to your
function. I use a script designed to push filesystem contents to
design documents. It has an ability to inline additional JavaScript
into your functions.

I'm in the middle of extracting it to its own project, so the install
will be getting easier, but the Ruby code is available here:

http://github.com/jchris/couchapp/tree/master

-- 
Chris Anderson
http://jchris.mfdz.com