You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by AL <ne...@alexandreleray.com> on 2012/08/06 19:17:03 UTC

Using underscorejs in a couchapp list

Hi all,

I'm running archlinux and couchdb 1.2. I'm trying to develop a couchapp: 
although I could use couchdb only as a database, I like the idea of 
"self-containess" in couchapps. The application I want to build is 
fairly simple, consisting of list and detail views. I have a set of 
books described in a bibtex-like fashion, and I'm trying to serve a 
webpage that lists the whole collection, organized by year. Here is my 
view map:

     function(doc) {
       if (doc.application === "publication") {
         emit([doc.year, doc.title], doc);
       };
     }

I'd like to get a webpage consisting of several ul tags; one for every 
year. The getrow() function makes it easy to make one big list (1. 
opening the list, 2. creating a list element for every row, 3. closing 
the list) but for what I want to achieve it seems a little bit trickier.

My idea was to use underscorejs `_.sortBy` method to reorganize the data 
by year into a dictionary, to end up with something like this:

     {
       '2009': [
         {'title': ' The Transformer -- Principles of Making Isotype 
Charts', ...},
         {'title': ' Verbindingen/Jonctions 10, Tracks in Electr(on)ic 
Fields', ...},
         {...}
       ],
       '2012': [
         {'title': 'Tying the Story to Data: The graffiti Markup Field 
Recorder Challenged, GML', ...},
         {'title': 'Inside Photoshop', ...},
         {...}
       ],
       ...
     }

 From there, I'd be able to loop through each key and append to my html 
output an HTML list. Unfortunately, I'm unable to import underscorejs, 
as it seems like they have dropped support for commonjs. There are forks 
and similar libraries that are supposed to work, but whatever I try, it 
fails (see my question here: 
http://stackoverflow.com/questions/11781502/using-underscorejs-in-a-couchapp-list/11817375#11817375).

So I'd like to know whether it is achievable in this way or another, and 
if my direction is correct, how I can use underscorejs (or similar) in a 
couchapp.

Thanks a lot,

Alex



Re: Using underscorejs in a couchapp list

Posted by Jim Klo <ji...@sri.com>.
That version doesn't work... :P Which is why I pointed you to the version I had in my project.. underscore removed CommonJS bindings... there's a long thread on that on a google group somewhere...

I dug up some previous version that still had the CommonJS bindings....  which was here:

>>>>>>> https://github.com/jimklo/TheCollector/blob/master/dataservices/thecollector-resources/views/lib/underscore-min.js


you'll need to dump it into the views/lib directory and make sure your kanso.json has modules dependency:

{
   ...
    "modules":["lib","views"],
    "load": "lib/app",
    "dependencies": {
        "modules": null,
        "properties": null
    }
 ...
}

then require in your view would be:

var _ = require("views/lib/underscore-min");

You can take a look at this kanso app as an example:

>>>>>>> https://github.com/jimklo/TheCollector/blob/master/dataservices/thecollector-resources/



Jim Klo
Senior Software Engineer
Center for Software Engineering
SRI International
t.	@nsomnac

On Aug 17, 2012, at 5:26 PM, AL wrote:

> Thanks again,
> 
> again it fails... with:
> 
> https://raw.github.com/amdjs/underscore/master/underscore.js
> 
> Any other suggestion?
> 
> Alex
> 
> On 18/08/2012 02:08, Zera Holladay wrote:
>> Last suggestion, try sticking an AMD-ified version of underscore in
>> lib and load it like:
>> 
>> _ = require("lib/underscore").
>> 
>> I don't really know Kanso, but the only example shows libraries in
>> html only.  However, Sofa uses a server-side require in
>> validate_doc_update like the kind I'm asking you to try.  I might be
>> dead wrong about all of the above, but maybe this response will get
>> someone more knowledgeable than me to respond if I am.
>> 
>> -zh
>> 
>> On Fri, Aug 17, 2012 at 7:55 PM, AL <ne...@alexandreleray.com> wrote:
>>> thanks, unfortunately no more chance. :(
>>> 
>>> Alex
>>> 
>>> 
>>> On 18/08/2012 01:11, Zera Holladay wrote:
>>>> 
>>>> Try changing:
>>>> 
>>>> var _ = require('underscore')._;
>>>> 
>>>> to:
>>>> 
>>>> _ = require('underscore');
>>>> 
>>>> -zh
>>>> 
>>>> 
>>>> On Fri, Aug 17, 2012 at 7:05 PM, AL <ne...@alexandreleray.com>
>>>> wrote:
>>>>> 
>>>>> Thanks Jim and Ryan,
>>>>> 
>>>>> kanso seems quite interesting indeed :)
>>>>> 
>>>>> I have started a small project based on it, but unfortunately I haven't
>>>>> been
>>>>> able to solve my problem.
>>>>> 
>>>>> I was wondering if the folks on the list could have a look at it? I
>>>>> really
>>>>> can't spot the problem...
>>>>> 
>>>>> The project is available here:
>>>>> 
>>>>> https://github.com/aleray/lgru.couch
>>>>> 
>>>>> Visiting the following URL will log variable `_`, which is undefined in
>>>>> my
>>>>> case...
>>>>> 
>>>>> http://127.0.0.1:5984/mydb/_design/lgru/_list/publications/publications
>>>>> 
>>>>> Thanks a lot,
>>>>> 
>>>>> Alex
>>>>> 
>>>>> 
>>>>> On 06/08/2012 19:40, Ryan Ramage wrote:
>>>>>> 
>>>>>> 
>>>>>> Alex,
>>>>>> 
>>>>>> If you are making a couchapp, and you want to use underscore, you
>>>>>> should give http://kan.so/ a try. There is a kanso package already for
>>>>>> underscore:
>>>>>> 
>>>>>> http://kan.so/packages/details/underscore
>>>>>> 
>>>>>> Kanso makes using commonjs modules very easy, and there are lots of
>>>>>> packages already available.
>>>>>> 
>>>>>> Ryan
>>>>>> 
>>>>>> 
>>>>>> On Mon, Aug 6, 2012 at 11:26 AM, Jim Klo <ji...@sri.com> wrote:
>>>>>>> 
>>>>>>> 
>>>>>>> Hmm... I'm using underscore.js in my views and lists...  maybe snake
>>>>>>> the
>>>>>>> version I'm using?
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> https://github.com/jimklo/TheCollector/blob/master/dataservices/thecollector-resources/views/lib/underscore-min.js
>>>>>>> 
>>>>>>> Jim Klo
>>>>>>> Senior Software Engineer
>>>>>>> Center for Software Engineering
>>>>>>> SRI International
>>>>>>> t. @nsomnac
>>>>>>> 
>>>>>>> On Aug 6, 2012, at 10:17 AM, AL wrote:
>>>>>>> 
>>>>>>> Hi all,
>>>>>>> 
>>>>>>> I'm running archlinux and couchdb 1.2. I'm trying to develop a
>>>>>>> couchapp:
>>>>>>> although I could use couchdb only as a database, I like the idea of
>>>>>>> "self-containess" in couchapps. The application I want to build is
>>>>>>> fairly
>>>>>>> simple, consisting of list and detail views. I have a set of books
>>>>>>> described
>>>>>>> in a bibtex-like fashion, and I'm trying to serve a webpage that lists
>>>>>>> the
>>>>>>> whole collection, organized by year. Here is my view map:
>>>>>>> 
>>>>>>>      function(doc) {
>>>>>>>        if (doc.application === "publication") {
>>>>>>>          emit([doc.year, doc.title], doc);
>>>>>>>        };
>>>>>>>      }
>>>>>>> 
>>>>>>> I'd like to get a webpage consisting of several ul tags; one for every
>>>>>>> year.
>>>>>>> The getrow() function makes it easy to make one big list (1. opening
>>>>>>> the
>>>>>>> list, 2. creating a list element for every row, 3. closing the list)
>>>>>>> but
>>>>>>> for
>>>>>>> what I want to achieve it seems a little bit trickier.
>>>>>>> 
>>>>>>> My idea was to use underscorejs `_.sortBy` method to reorganize the
>>>>>>> data
>>>>>>> by
>>>>>>> year into a dictionary, to end up with something like this:
>>>>>>> 
>>>>>>>      {
>>>>>>>        '2009': [
>>>>>>>          {'title': ' The Transformer -- Principles of Making Isotype
>>>>>>> Charts',
>>>>>>> ...},
>>>>>>>          {'title': ' Verbindingen/Jonctions 10, Tracks in Electr(on)ic
>>>>>>> Fields', ...},
>>>>>>>          {...}
>>>>>>>        ],
>>>>>>>        '2012': [
>>>>>>>          {'title': 'Tying the Story to Data: The graffiti Markup Field
>>>>>>> Recorder Challenged, GML', ...},
>>>>>>>          {'title': 'Inside Photoshop', ...},
>>>>>>>          {...}
>>>>>>>        ],
>>>>>>>        ...
>>>>>>>      }
>>>>>>> 
>>>>>>>   From there, I'd be able to loop through each key and append to my
>>>>>>> html
>>>>>>> output an HTML list. Unfortunately, I'm unable to import underscorejs,
>>>>>>> as
>>>>>>> it
>>>>>>> seems like they have dropped support for commonjs. There are forks and
>>>>>>> similar libraries that are supposed to work, but whatever I try, it
>>>>>>> fails
>>>>>>> (see my question here:
>>>>>>> 
>>>>>>> 
>>>>>>> http://stackoverflow.com/questions/11781502/using-underscorejs-in-a-couchapp-list/11817375#11817375).
>>>>>>> 
>>>>>>> So I'd like to know whether it is achievable in this way or another,
>>>>>>> and
>>>>>>> if
>>>>>>> my direction is correct, how I can use underscorejs (or similar) in a
>>>>>>> couchapp.
>>>>>>> 
>>>>>>> Thanks a lot,
>>>>>>> 
>>>>>>> Alex
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>> 
>>>>> 
>>>> 
>>> 
>> 


Re: Using underscorejs in a couchapp list

Posted by AL <ne...@alexandreleray.com>.
Thanks again,

again it fails... with:

https://raw.github.com/amdjs/underscore/master/underscore.js

Any other suggestion?

Alex

On 18/08/2012 02:08, Zera Holladay wrote:
> Last suggestion, try sticking an AMD-ified version of underscore in
> lib and load it like:
>
> _ = require("lib/underscore").
>
> I don't really know Kanso, but the only example shows libraries in
> html only.  However, Sofa uses a server-side require in
> validate_doc_update like the kind I'm asking you to try.  I might be
> dead wrong about all of the above, but maybe this response will get
> someone more knowledgeable than me to respond if I am.
>
> -zh
>
> On Fri, Aug 17, 2012 at 7:55 PM, AL <ne...@alexandreleray.com> wrote:
>> thanks, unfortunately no more chance. :(
>>
>> Alex
>>
>>
>> On 18/08/2012 01:11, Zera Holladay wrote:
>>>
>>> Try changing:
>>>
>>> var _ = require('underscore')._;
>>>
>>> to:
>>>
>>> _ = require('underscore');
>>>
>>> -zh
>>>
>>>
>>> On Fri, Aug 17, 2012 at 7:05 PM, AL <ne...@alexandreleray.com>
>>> wrote:
>>>>
>>>> Thanks Jim and Ryan,
>>>>
>>>> kanso seems quite interesting indeed :)
>>>>
>>>> I have started a small project based on it, but unfortunately I haven't
>>>> been
>>>> able to solve my problem.
>>>>
>>>> I was wondering if the folks on the list could have a look at it? I
>>>> really
>>>> can't spot the problem...
>>>>
>>>> The project is available here:
>>>>
>>>> https://github.com/aleray/lgru.couch
>>>>
>>>> Visiting the following URL will log variable `_`, which is undefined in
>>>> my
>>>> case...
>>>>
>>>> http://127.0.0.1:5984/mydb/_design/lgru/_list/publications/publications
>>>>
>>>> Thanks a lot,
>>>>
>>>> Alex
>>>>
>>>>
>>>> On 06/08/2012 19:40, Ryan Ramage wrote:
>>>>>
>>>>>
>>>>> Alex,
>>>>>
>>>>> If you are making a couchapp, and you want to use underscore, you
>>>>> should give http://kan.so/ a try. There is a kanso package already for
>>>>> underscore:
>>>>>
>>>>> http://kan.so/packages/details/underscore
>>>>>
>>>>> Kanso makes using commonjs modules very easy, and there are lots of
>>>>> packages already available.
>>>>>
>>>>> Ryan
>>>>>
>>>>>
>>>>> On Mon, Aug 6, 2012 at 11:26 AM, Jim Klo <ji...@sri.com> wrote:
>>>>>>
>>>>>>
>>>>>> Hmm... I'm using underscore.js in my views and lists...  maybe snake
>>>>>> the
>>>>>> version I'm using?
>>>>>>
>>>>>>
>>>>>>
>>>>>> https://github.com/jimklo/TheCollector/blob/master/dataservices/thecollector-resources/views/lib/underscore-min.js
>>>>>>
>>>>>> Jim Klo
>>>>>> Senior Software Engineer
>>>>>> Center for Software Engineering
>>>>>> SRI International
>>>>>> t. @nsomnac
>>>>>>
>>>>>> On Aug 6, 2012, at 10:17 AM, AL wrote:
>>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> I'm running archlinux and couchdb 1.2. I'm trying to develop a
>>>>>> couchapp:
>>>>>> although I could use couchdb only as a database, I like the idea of
>>>>>> "self-containess" in couchapps. The application I want to build is
>>>>>> fairly
>>>>>> simple, consisting of list and detail views. I have a set of books
>>>>>> described
>>>>>> in a bibtex-like fashion, and I'm trying to serve a webpage that lists
>>>>>> the
>>>>>> whole collection, organized by year. Here is my view map:
>>>>>>
>>>>>>       function(doc) {
>>>>>>         if (doc.application === "publication") {
>>>>>>           emit([doc.year, doc.title], doc);
>>>>>>         };
>>>>>>       }
>>>>>>
>>>>>> I'd like to get a webpage consisting of several ul tags; one for every
>>>>>> year.
>>>>>> The getrow() function makes it easy to make one big list (1. opening
>>>>>> the
>>>>>> list, 2. creating a list element for every row, 3. closing the list)
>>>>>> but
>>>>>> for
>>>>>> what I want to achieve it seems a little bit trickier.
>>>>>>
>>>>>> My idea was to use underscorejs `_.sortBy` method to reorganize the
>>>>>> data
>>>>>> by
>>>>>> year into a dictionary, to end up with something like this:
>>>>>>
>>>>>>       {
>>>>>>         '2009': [
>>>>>>           {'title': ' The Transformer -- Principles of Making Isotype
>>>>>> Charts',
>>>>>> ...},
>>>>>>           {'title': ' Verbindingen/Jonctions 10, Tracks in Electr(on)ic
>>>>>> Fields', ...},
>>>>>>           {...}
>>>>>>         ],
>>>>>>         '2012': [
>>>>>>           {'title': 'Tying the Story to Data: The graffiti Markup Field
>>>>>> Recorder Challenged, GML', ...},
>>>>>>           {'title': 'Inside Photoshop', ...},
>>>>>>           {...}
>>>>>>         ],
>>>>>>         ...
>>>>>>       }
>>>>>>
>>>>>>    From there, I'd be able to loop through each key and append to my
>>>>>> html
>>>>>> output an HTML list. Unfortunately, I'm unable to import underscorejs,
>>>>>> as
>>>>>> it
>>>>>> seems like they have dropped support for commonjs. There are forks and
>>>>>> similar libraries that are supposed to work, but whatever I try, it
>>>>>> fails
>>>>>> (see my question here:
>>>>>>
>>>>>>
>>>>>> http://stackoverflow.com/questions/11781502/using-underscorejs-in-a-couchapp-list/11817375#11817375).
>>>>>>
>>>>>> So I'd like to know whether it is achievable in this way or another,
>>>>>> and
>>>>>> if
>>>>>> my direction is correct, how I can use underscorejs (or similar) in a
>>>>>> couchapp.
>>>>>>
>>>>>> Thanks a lot,
>>>>>>
>>>>>> Alex
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>

Re: Using underscorejs in a couchapp list

Posted by Zera Holladay <ze...@gmail.com>.
Last suggestion, try sticking an AMD-ified version of underscore in
lib and load it like:

_ = require("lib/underscore").

I don't really know Kanso, but the only example shows libraries in
html only.  However, Sofa uses a server-side require in
validate_doc_update like the kind I'm asking you to try.  I might be
dead wrong about all of the above, but maybe this response will get
someone more knowledgeable than me to respond if I am.

-zh

On Fri, Aug 17, 2012 at 7:55 PM, AL <ne...@alexandreleray.com> wrote:
> thanks, unfortunately no more chance. :(
>
> Alex
>
>
> On 18/08/2012 01:11, Zera Holladay wrote:
>>
>> Try changing:
>>
>> var _ = require('underscore')._;
>>
>> to:
>>
>> _ = require('underscore');
>>
>> -zh
>>
>>
>> On Fri, Aug 17, 2012 at 7:05 PM, AL <ne...@alexandreleray.com>
>> wrote:
>>>
>>> Thanks Jim and Ryan,
>>>
>>> kanso seems quite interesting indeed :)
>>>
>>> I have started a small project based on it, but unfortunately I haven't
>>> been
>>> able to solve my problem.
>>>
>>> I was wondering if the folks on the list could have a look at it? I
>>> really
>>> can't spot the problem...
>>>
>>> The project is available here:
>>>
>>> https://github.com/aleray/lgru.couch
>>>
>>> Visiting the following URL will log variable `_`, which is undefined in
>>> my
>>> case...
>>>
>>> http://127.0.0.1:5984/mydb/_design/lgru/_list/publications/publications
>>>
>>> Thanks a lot,
>>>
>>> Alex
>>>
>>>
>>> On 06/08/2012 19:40, Ryan Ramage wrote:
>>>>
>>>>
>>>> Alex,
>>>>
>>>> If you are making a couchapp, and you want to use underscore, you
>>>> should give http://kan.so/ a try. There is a kanso package already for
>>>> underscore:
>>>>
>>>> http://kan.so/packages/details/underscore
>>>>
>>>> Kanso makes using commonjs modules very easy, and there are lots of
>>>> packages already available.
>>>>
>>>> Ryan
>>>>
>>>>
>>>> On Mon, Aug 6, 2012 at 11:26 AM, Jim Klo <ji...@sri.com> wrote:
>>>>>
>>>>>
>>>>> Hmm... I'm using underscore.js in my views and lists...  maybe snake
>>>>> the
>>>>> version I'm using?
>>>>>
>>>>>
>>>>>
>>>>> https://github.com/jimklo/TheCollector/blob/master/dataservices/thecollector-resources/views/lib/underscore-min.js
>>>>>
>>>>> Jim Klo
>>>>> Senior Software Engineer
>>>>> Center for Software Engineering
>>>>> SRI International
>>>>> t. @nsomnac
>>>>>
>>>>> On Aug 6, 2012, at 10:17 AM, AL wrote:
>>>>>
>>>>> Hi all,
>>>>>
>>>>> I'm running archlinux and couchdb 1.2. I'm trying to develop a
>>>>> couchapp:
>>>>> although I could use couchdb only as a database, I like the idea of
>>>>> "self-containess" in couchapps. The application I want to build is
>>>>> fairly
>>>>> simple, consisting of list and detail views. I have a set of books
>>>>> described
>>>>> in a bibtex-like fashion, and I'm trying to serve a webpage that lists
>>>>> the
>>>>> whole collection, organized by year. Here is my view map:
>>>>>
>>>>>      function(doc) {
>>>>>        if (doc.application === "publication") {
>>>>>          emit([doc.year, doc.title], doc);
>>>>>        };
>>>>>      }
>>>>>
>>>>> I'd like to get a webpage consisting of several ul tags; one for every
>>>>> year.
>>>>> The getrow() function makes it easy to make one big list (1. opening
>>>>> the
>>>>> list, 2. creating a list element for every row, 3. closing the list)
>>>>> but
>>>>> for
>>>>> what I want to achieve it seems a little bit trickier.
>>>>>
>>>>> My idea was to use underscorejs `_.sortBy` method to reorganize the
>>>>> data
>>>>> by
>>>>> year into a dictionary, to end up with something like this:
>>>>>
>>>>>      {
>>>>>        '2009': [
>>>>>          {'title': ' The Transformer -- Principles of Making Isotype
>>>>> Charts',
>>>>> ...},
>>>>>          {'title': ' Verbindingen/Jonctions 10, Tracks in Electr(on)ic
>>>>> Fields', ...},
>>>>>          {...}
>>>>>        ],
>>>>>        '2012': [
>>>>>          {'title': 'Tying the Story to Data: The graffiti Markup Field
>>>>> Recorder Challenged, GML', ...},
>>>>>          {'title': 'Inside Photoshop', ...},
>>>>>          {...}
>>>>>        ],
>>>>>        ...
>>>>>      }
>>>>>
>>>>>   From there, I'd be able to loop through each key and append to my
>>>>> html
>>>>> output an HTML list. Unfortunately, I'm unable to import underscorejs,
>>>>> as
>>>>> it
>>>>> seems like they have dropped support for commonjs. There are forks and
>>>>> similar libraries that are supposed to work, but whatever I try, it
>>>>> fails
>>>>> (see my question here:
>>>>>
>>>>>
>>>>> http://stackoverflow.com/questions/11781502/using-underscorejs-in-a-couchapp-list/11817375#11817375).
>>>>>
>>>>> So I'd like to know whether it is achievable in this way or another,
>>>>> and
>>>>> if
>>>>> my direction is correct, how I can use underscorejs (or similar) in a
>>>>> couchapp.
>>>>>
>>>>> Thanks a lot,
>>>>>
>>>>> Alex
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>

Re: Using underscorejs in a couchapp list

Posted by AL <ne...@alexandreleray.com>.
thanks, unfortunately no more chance. :(

Alex

On 18/08/2012 01:11, Zera Holladay wrote:
> Try changing:
>
> var _ = require('underscore')._;
>
> to:
>
> _ = require('underscore');
>
> -zh
>
>
> On Fri, Aug 17, 2012 at 7:05 PM, AL <ne...@alexandreleray.com> wrote:
>> Thanks Jim and Ryan,
>>
>> kanso seems quite interesting indeed :)
>>
>> I have started a small project based on it, but unfortunately I haven't been
>> able to solve my problem.
>>
>> I was wondering if the folks on the list could have a look at it? I really
>> can't spot the problem...
>>
>> The project is available here:
>>
>> https://github.com/aleray/lgru.couch
>>
>> Visiting the following URL will log variable `_`, which is undefined in my
>> case...
>>
>> http://127.0.0.1:5984/mydb/_design/lgru/_list/publications/publications
>>
>> Thanks a lot,
>>
>> Alex
>>
>>
>> On 06/08/2012 19:40, Ryan Ramage wrote:
>>>
>>> Alex,
>>>
>>> If you are making a couchapp, and you want to use underscore, you
>>> should give http://kan.so/ a try. There is a kanso package already for
>>> underscore:
>>>
>>> http://kan.so/packages/details/underscore
>>>
>>> Kanso makes using commonjs modules very easy, and there are lots of
>>> packages already available.
>>>
>>> Ryan
>>>
>>>
>>> On Mon, Aug 6, 2012 at 11:26 AM, Jim Klo <ji...@sri.com> wrote:
>>>>
>>>> Hmm... I'm using underscore.js in my views and lists...  maybe snake the
>>>> version I'm using?
>>>>
>>>>
>>>> https://github.com/jimklo/TheCollector/blob/master/dataservices/thecollector-resources/views/lib/underscore-min.js
>>>>
>>>> Jim Klo
>>>> Senior Software Engineer
>>>> Center for Software Engineering
>>>> SRI International
>>>> t. @nsomnac
>>>>
>>>> On Aug 6, 2012, at 10:17 AM, AL wrote:
>>>>
>>>> Hi all,
>>>>
>>>> I'm running archlinux and couchdb 1.2. I'm trying to develop a couchapp:
>>>> although I could use couchdb only as a database, I like the idea of
>>>> "self-containess" in couchapps. The application I want to build is fairly
>>>> simple, consisting of list and detail views. I have a set of books
>>>> described
>>>> in a bibtex-like fashion, and I'm trying to serve a webpage that lists
>>>> the
>>>> whole collection, organized by year. Here is my view map:
>>>>
>>>>      function(doc) {
>>>>        if (doc.application === "publication") {
>>>>          emit([doc.year, doc.title], doc);
>>>>        };
>>>>      }
>>>>
>>>> I'd like to get a webpage consisting of several ul tags; one for every
>>>> year.
>>>> The getrow() function makes it easy to make one big list (1. opening the
>>>> list, 2. creating a list element for every row, 3. closing the list) but
>>>> for
>>>> what I want to achieve it seems a little bit trickier.
>>>>
>>>> My idea was to use underscorejs `_.sortBy` method to reorganize the data
>>>> by
>>>> year into a dictionary, to end up with something like this:
>>>>
>>>>      {
>>>>        '2009': [
>>>>          {'title': ' The Transformer -- Principles of Making Isotype
>>>> Charts',
>>>> ...},
>>>>          {'title': ' Verbindingen/Jonctions 10, Tracks in Electr(on)ic
>>>> Fields', ...},
>>>>          {...}
>>>>        ],
>>>>        '2012': [
>>>>          {'title': 'Tying the Story to Data: The graffiti Markup Field
>>>> Recorder Challenged, GML', ...},
>>>>          {'title': 'Inside Photoshop', ...},
>>>>          {...}
>>>>        ],
>>>>        ...
>>>>      }
>>>>
>>>>   From there, I'd be able to loop through each key and append to my html
>>>> output an HTML list. Unfortunately, I'm unable to import underscorejs, as
>>>> it
>>>> seems like they have dropped support for commonjs. There are forks and
>>>> similar libraries that are supposed to work, but whatever I try, it fails
>>>> (see my question here:
>>>>
>>>> http://stackoverflow.com/questions/11781502/using-underscorejs-in-a-couchapp-list/11817375#11817375).
>>>>
>>>> So I'd like to know whether it is achievable in this way or another, and
>>>> if
>>>> my direction is correct, how I can use underscorejs (or similar) in a
>>>> couchapp.
>>>>
>>>> Thanks a lot,
>>>>
>>>> Alex
>>>>
>>>>
>>>>
>>>
>>
>

Re: Using underscorejs in a couchapp list

Posted by Zera Holladay <ze...@gmail.com>.
Try changing:

var _ = require('underscore')._;

to:

_ = require('underscore');

-zh


On Fri, Aug 17, 2012 at 7:05 PM, AL <ne...@alexandreleray.com> wrote:
> Thanks Jim and Ryan,
>
> kanso seems quite interesting indeed :)
>
> I have started a small project based on it, but unfortunately I haven't been
> able to solve my problem.
>
> I was wondering if the folks on the list could have a look at it? I really
> can't spot the problem...
>
> The project is available here:
>
> https://github.com/aleray/lgru.couch
>
> Visiting the following URL will log variable `_`, which is undefined in my
> case...
>
> http://127.0.0.1:5984/mydb/_design/lgru/_list/publications/publications
>
> Thanks a lot,
>
> Alex
>
>
> On 06/08/2012 19:40, Ryan Ramage wrote:
>>
>> Alex,
>>
>> If you are making a couchapp, and you want to use underscore, you
>> should give http://kan.so/ a try. There is a kanso package already for
>> underscore:
>>
>> http://kan.so/packages/details/underscore
>>
>> Kanso makes using commonjs modules very easy, and there are lots of
>> packages already available.
>>
>> Ryan
>>
>>
>> On Mon, Aug 6, 2012 at 11:26 AM, Jim Klo <ji...@sri.com> wrote:
>>>
>>> Hmm... I'm using underscore.js in my views and lists...  maybe snake the
>>> version I'm using?
>>>
>>>
>>> https://github.com/jimklo/TheCollector/blob/master/dataservices/thecollector-resources/views/lib/underscore-min.js
>>>
>>> Jim Klo
>>> Senior Software Engineer
>>> Center for Software Engineering
>>> SRI International
>>> t. @nsomnac
>>>
>>> On Aug 6, 2012, at 10:17 AM, AL wrote:
>>>
>>> Hi all,
>>>
>>> I'm running archlinux and couchdb 1.2. I'm trying to develop a couchapp:
>>> although I could use couchdb only as a database, I like the idea of
>>> "self-containess" in couchapps. The application I want to build is fairly
>>> simple, consisting of list and detail views. I have a set of books
>>> described
>>> in a bibtex-like fashion, and I'm trying to serve a webpage that lists
>>> the
>>> whole collection, organized by year. Here is my view map:
>>>
>>>     function(doc) {
>>>       if (doc.application === "publication") {
>>>         emit([doc.year, doc.title], doc);
>>>       };
>>>     }
>>>
>>> I'd like to get a webpage consisting of several ul tags; one for every
>>> year.
>>> The getrow() function makes it easy to make one big list (1. opening the
>>> list, 2. creating a list element for every row, 3. closing the list) but
>>> for
>>> what I want to achieve it seems a little bit trickier.
>>>
>>> My idea was to use underscorejs `_.sortBy` method to reorganize the data
>>> by
>>> year into a dictionary, to end up with something like this:
>>>
>>>     {
>>>       '2009': [
>>>         {'title': ' The Transformer -- Principles of Making Isotype
>>> Charts',
>>> ...},
>>>         {'title': ' Verbindingen/Jonctions 10, Tracks in Electr(on)ic
>>> Fields', ...},
>>>         {...}
>>>       ],
>>>       '2012': [
>>>         {'title': 'Tying the Story to Data: The graffiti Markup Field
>>> Recorder Challenged, GML', ...},
>>>         {'title': 'Inside Photoshop', ...},
>>>         {...}
>>>       ],
>>>       ...
>>>     }
>>>
>>>  From there, I'd be able to loop through each key and append to my html
>>> output an HTML list. Unfortunately, I'm unable to import underscorejs, as
>>> it
>>> seems like they have dropped support for commonjs. There are forks and
>>> similar libraries that are supposed to work, but whatever I try, it fails
>>> (see my question here:
>>>
>>> http://stackoverflow.com/questions/11781502/using-underscorejs-in-a-couchapp-list/11817375#11817375).
>>>
>>> So I'd like to know whether it is achievable in this way or another, and
>>> if
>>> my direction is correct, how I can use underscorejs (or similar) in a
>>> couchapp.
>>>
>>> Thanks a lot,
>>>
>>> Alex
>>>
>>>
>>>
>>
>

Re: Using underscorejs in a couchapp list

Posted by AL <ne...@alexandreleray.com>.
Thanks Jim and Ryan,

kanso seems quite interesting indeed :)

I have started a small project based on it, but unfortunately I haven't 
been able to solve my problem.

I was wondering if the folks on the list could have a look at it? I 
really can't spot the problem...

The project is available here:

https://github.com/aleray/lgru.couch

Visiting the following URL will log variable `_`, which is undefined in 
my case...

http://127.0.0.1:5984/mydb/_design/lgru/_list/publications/publications

Thanks a lot,

Alex

On 06/08/2012 19:40, Ryan Ramage wrote:
> Alex,
>
> If you are making a couchapp, and you want to use underscore, you
> should give http://kan.so/ a try. There is a kanso package already for
> underscore:
>
> http://kan.so/packages/details/underscore
>
> Kanso makes using commonjs modules very easy, and there are lots of
> packages already available.
>
> Ryan
>
>
> On Mon, Aug 6, 2012 at 11:26 AM, Jim Klo <ji...@sri.com> wrote:
>> Hmm... I'm using underscore.js in my views and lists...  maybe snake the
>> version I'm using?
>>
>> https://github.com/jimklo/TheCollector/blob/master/dataservices/thecollector-resources/views/lib/underscore-min.js
>>
>> Jim Klo
>> Senior Software Engineer
>> Center for Software Engineering
>> SRI International
>> t. @nsomnac
>>
>> On Aug 6, 2012, at 10:17 AM, AL wrote:
>>
>> Hi all,
>>
>> I'm running archlinux and couchdb 1.2. I'm trying to develop a couchapp:
>> although I could use couchdb only as a database, I like the idea of
>> "self-containess" in couchapps. The application I want to build is fairly
>> simple, consisting of list and detail views. I have a set of books described
>> in a bibtex-like fashion, and I'm trying to serve a webpage that lists the
>> whole collection, organized by year. Here is my view map:
>>
>>     function(doc) {
>>       if (doc.application === "publication") {
>>         emit([doc.year, doc.title], doc);
>>       };
>>     }
>>
>> I'd like to get a webpage consisting of several ul tags; one for every year.
>> The getrow() function makes it easy to make one big list (1. opening the
>> list, 2. creating a list element for every row, 3. closing the list) but for
>> what I want to achieve it seems a little bit trickier.
>>
>> My idea was to use underscorejs `_.sortBy` method to reorganize the data by
>> year into a dictionary, to end up with something like this:
>>
>>     {
>>       '2009': [
>>         {'title': ' The Transformer -- Principles of Making Isotype Charts',
>> ...},
>>         {'title': ' Verbindingen/Jonctions 10, Tracks in Electr(on)ic
>> Fields', ...},
>>         {...}
>>       ],
>>       '2012': [
>>         {'title': 'Tying the Story to Data: The graffiti Markup Field
>> Recorder Challenged, GML', ...},
>>         {'title': 'Inside Photoshop', ...},
>>         {...}
>>       ],
>>       ...
>>     }
>>
>>  From there, I'd be able to loop through each key and append to my html
>> output an HTML list. Unfortunately, I'm unable to import underscorejs, as it
>> seems like they have dropped support for commonjs. There are forks and
>> similar libraries that are supposed to work, but whatever I try, it fails
>> (see my question here:
>> http://stackoverflow.com/questions/11781502/using-underscorejs-in-a-couchapp-list/11817375#11817375).
>>
>> So I'd like to know whether it is achievable in this way or another, and if
>> my direction is correct, how I can use underscorejs (or similar) in a
>> couchapp.
>>
>> Thanks a lot,
>>
>> Alex
>>
>>
>>
>

Re: Using underscorejs in a couchapp list

Posted by Ryan Ramage <ry...@gmail.com>.
Alex,

If you are making a couchapp, and you want to use underscore, you
should give http://kan.so/ a try. There is a kanso package already for
underscore:

http://kan.so/packages/details/underscore

Kanso makes using commonjs modules very easy, and there are lots of
packages already available.

Ryan


On Mon, Aug 6, 2012 at 11:26 AM, Jim Klo <ji...@sri.com> wrote:
> Hmm... I'm using underscore.js in my views and lists...  maybe snake the
> version I'm using?
>
> https://github.com/jimklo/TheCollector/blob/master/dataservices/thecollector-resources/views/lib/underscore-min.js
>
> Jim Klo
> Senior Software Engineer
> Center for Software Engineering
> SRI International
> t. @nsomnac
>
> On Aug 6, 2012, at 10:17 AM, AL wrote:
>
> Hi all,
>
> I'm running archlinux and couchdb 1.2. I'm trying to develop a couchapp:
> although I could use couchdb only as a database, I like the idea of
> "self-containess" in couchapps. The application I want to build is fairly
> simple, consisting of list and detail views. I have a set of books described
> in a bibtex-like fashion, and I'm trying to serve a webpage that lists the
> whole collection, organized by year. Here is my view map:
>
>    function(doc) {
>      if (doc.application === "publication") {
>        emit([doc.year, doc.title], doc);
>      };
>    }
>
> I'd like to get a webpage consisting of several ul tags; one for every year.
> The getrow() function makes it easy to make one big list (1. opening the
> list, 2. creating a list element for every row, 3. closing the list) but for
> what I want to achieve it seems a little bit trickier.
>
> My idea was to use underscorejs `_.sortBy` method to reorganize the data by
> year into a dictionary, to end up with something like this:
>
>    {
>      '2009': [
>        {'title': ' The Transformer -- Principles of Making Isotype Charts',
> ...},
>        {'title': ' Verbindingen/Jonctions 10, Tracks in Electr(on)ic
> Fields', ...},
>        {...}
>      ],
>      '2012': [
>        {'title': 'Tying the Story to Data: The graffiti Markup Field
> Recorder Challenged, GML', ...},
>        {'title': 'Inside Photoshop', ...},
>        {...}
>      ],
>      ...
>    }
>
> From there, I'd be able to loop through each key and append to my html
> output an HTML list. Unfortunately, I'm unable to import underscorejs, as it
> seems like they have dropped support for commonjs. There are forks and
> similar libraries that are supposed to work, but whatever I try, it fails
> (see my question here:
> http://stackoverflow.com/questions/11781502/using-underscorejs-in-a-couchapp-list/11817375#11817375).
>
> So I'd like to know whether it is achievable in this way or another, and if
> my direction is correct, how I can use underscorejs (or similar) in a
> couchapp.
>
> Thanks a lot,
>
> Alex
>
>
>

Re: Using underscorejs in a couchapp list

Posted by Jim Klo <ji...@sri.com>.
Hmm... I'm using underscore.js in my views and lists...  maybe snake the version I'm using?

https://github.com/jimklo/TheCollector/blob/master/dataservices/thecollector-resources/views/lib/underscore-min.js

Jim Klo
Senior Software Engineer
Center for Software Engineering
SRI International
t.	@nsomnac

On Aug 6, 2012, at 10:17 AM, AL wrote:

> Hi all,
> 
> I'm running archlinux and couchdb 1.2. I'm trying to develop a couchapp: although I could use couchdb only as a database, I like the idea of "self-containess" in couchapps. The application I want to build is fairly simple, consisting of list and detail views. I have a set of books described in a bibtex-like fashion, and I'm trying to serve a webpage that lists the whole collection, organized by year. Here is my view map:
> 
>    function(doc) {
>      if (doc.application === "publication") {
>        emit([doc.year, doc.title], doc);
>      };
>    }
> 
> I'd like to get a webpage consisting of several ul tags; one for every year. The getrow() function makes it easy to make one big list (1. opening the list, 2. creating a list element for every row, 3. closing the list) but for what I want to achieve it seems a little bit trickier.
> 
> My idea was to use underscorejs `_.sortBy` method to reorganize the data by year into a dictionary, to end up with something like this:
> 
>    {
>      '2009': [
>        {'title': ' The Transformer -- Principles of Making Isotype Charts', ...},
>        {'title': ' Verbindingen/Jonctions 10, Tracks in Electr(on)ic Fields', ...},
>        {...}
>      ],
>      '2012': [
>        {'title': 'Tying the Story to Data: The graffiti Markup Field Recorder Challenged, GML', ...},
>        {'title': 'Inside Photoshop', ...},
>        {...}
>      ],
>      ...
>    }
> 
> From there, I'd be able to loop through each key and append to my html output an HTML list. Unfortunately, I'm unable to import underscorejs, as it seems like they have dropped support for commonjs. There are forks and similar libraries that are supposed to work, but whatever I try, it fails (see my question here: http://stackoverflow.com/questions/11781502/using-underscorejs-in-a-couchapp-list/11817375#11817375).
> 
> So I'd like to know whether it is achievable in this way or another, and if my direction is correct, how I can use underscorejs (or similar) in a couchapp.
> 
> Thanks a lot,
> 
> Alex
> 
>