You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Clemens Cap <ca...@unagon.com> on 2010/02/27 20:56:37 UTC

Newbie problem with template path

I am having a problem to understand the path where the engine looks for
the files included with the !json and !code macros.

More exactly: I am having a

{
   "_id": "_design/example",
   "_rev": "11-4ca79b908a6278eeb8d4d5e2e6488fb5",
   "views": {
       "foo": {
           "map": "function(doc){ emit(doc._id, doc._rev+'QQQ')}"
       }
   },
   "shows": {
       "my": "function(req, doc) {
                // !json templates.edit
                return template(templates.edit,{})  ; }"
   }
}

and

http://localhost:5984/mydatabase/_design/example/_view/foo

as expected. However

http://localhost:5984/mydatabase/_design/example/_show/my

produces a

{"error":"normal","reason":"{gen_server,call,\n
[couch_query_servers,\n
{ret_proc,{proc,<0.21518.0>,<<\"javascript\">>,\n
      {couch_os_process,prompt},\n
{couch_os_process,set_timeout},\n
{couch_os_process,stop}}}]}"}

I am having a non-empty

{
   "_id": "_design/template/_show/my",
   "_rev": "2-7051cbe5c8faecd085a3fa619e6e6337"
}

but this does not seem to help here. Moreover, where do I place the
template content into this object ?


I never got that part working so probably it is just a very stupid
newbie error...

Best
Clemens



Re: Newbie problem with template path

Posted by J Chris Anderson <jc...@gmail.com>.
On Apr 11, 2010, at 4:07 PM, Avi Flax wrote:

> On Sun, Apr 11, 2010 at 19:01, Avi Flax <av...@arc90.com> wrote:
> 
>> Now that 0.11 has been released, I'm wondering if this happened? I
>> can't seem to find any documentation on such a feature.
> 
> OK, after a little more digging, I found some JIRA issues that seem to
> be related:
> 
> https://issues.apache.org/jira/browse/COUCHDB-658
> "Add CommonJS style modules to the view server" — I imagine this would
> be useful for loading a templating library.
> 
> https://issues.apache.org/jira/browse/COUCHDB-693
> "require function - add support for requiring plain html/xml files in
> addition to only javascript" — this seems it would be the mechanism
> for loading the templates themselves.
> 
> They are both marked as open and unassigned, so I assume neither made
> it in to 0.11. Since 0.11 is supposed to be a feature freeze for 1.0,
> I suppose that means that these features will be post-1.0?


The first (CommonJS require) made it into 0.11 and I've just commented on the second with the correct way to load templates (the _design doc is available as the "this" object in _show _list etc functions).

Thanks for bringing these to my attention. I've closed them both.

Chris

Re: Newbie problem with template path

Posted by Avi Flax <av...@arc90.com>.
On Sun, Apr 11, 2010 at 19:01, Avi Flax <av...@arc90.com> wrote:

> Now that 0.11 has been released, I'm wondering if this happened? I
> can't seem to find any documentation on such a feature.

OK, after a little more digging, I found some JIRA issues that seem to
be related:

https://issues.apache.org/jira/browse/COUCHDB-658
"Add CommonJS style modules to the view server" — I imagine this would
be useful for loading a templating library.

https://issues.apache.org/jira/browse/COUCHDB-693
"require function - add support for requiring plain html/xml files in
addition to only javascript" — this seems it would be the mechanism
for loading the templates themselves.

They are both marked as open and unassigned, so I assume neither made
it in to 0.11. Since 0.11 is supposed to be a feature freeze for 1.0,
I suppose that means that these features will be post-1.0?

Re: Newbie problem with template path

Posted by Avi Flax <av...@arc90.com>.
Back in February, Clemens pasted this from an email from Chris:

> CouchDB itself has no idea about //!json, it's all in the toolchain.
> (We're working on changing this but the syntax will be proper javascript
> instead of a macro. This will be in 0.11 and will make it easier for you.)

Now that 0.11 has been released, I'm wondering if this happened? I
can't seem to find any documentation on such a feature.

Thanks!
Avi

--
Avi Flax » Partner » Arc90 » http://arc90.com

Re: Newbie problem with template path

Posted by Clemens Cap <ca...@unagon.com>.
On 28.02.2010 03:28, Patrick Barnes wrote:
> To confirm...
> You *are* using couchapp to generate your design doc, keeping the view and
> show funcs in files, and the included files in the same couchapp area?

No, I am not.

I got a reply from Chris which pointed out that issue - and as a
consequence of this my issue got solved today at (local time) noon. :-)

Since his reply didn't make it to the list I provide the essentials here
for the benefit of others - since this was the missing link for me.

Thanx again !


==PASTE==
Ahh. the key is that you need to use `couchapp push` to upload your
design doc to the couch.

when it's pushed, the couch should have:

shows : {
  my : {
   "
function(doc) {
var templates = {
    edit : "TEXT"
 }
return templates.edit;
}
"
...

CouchDB itself has no idea about //!json, it's all in the toolchain.
(We're working on changing this but the syntax will be proper javascript
instead of a macro. This will be in 0.11 and will make it easier for you.)

Couchapp push is required. Without it of course you could just put the
template into your function by hand, but that's no fun.

Chris

==PASTE==


> 
> -Patrick
> 
> On 28/02/2010 6:57 AM, "Clemens Cap" <ca...@unagon.com> wrote:
> 
> I am having a problem to understand the path where the engine looks for
> the files included with the !json and !code macros.
> 
> More exactly: I am having a
> 
> {
>   "_id": "_design/example",
>   "_rev": "11-4ca79b908a6278eeb8d4d5e2e6488fb5",
>   "views": {
>       "foo": {
>           "map": "function(doc){ emit(doc._id, doc._rev+'QQQ')}"
>       }
>   },
>   "shows": {
>       "my": "function(req, doc) {
>                // !json templates.edit
>                return template(templates.edit,{})  ; }"
>   }
> }
> 
> and
> 
> http://localhost:5984/mydatabase/_design/example/_view/foo
> 
> as expected. However
> 
> http://localhost:5984/mydatabase/_design/example/_show/my
> 
> produces a
> 
> {"error":"normal","reason":"{gen_server,call,\n
> [couch_query_servers,\n
> {ret_proc,{proc,<0.21518.0>,<<\"javascript\">>,\n
>      {couch_os_process,prompt},\n
> {couch_os_process,set_timeout},\n
> {couch_os_process,stop}}}]}"}
> 
> I am having a non-empty
> 
> {
>   "_id": "_design/template/_show/my",
>   "_rev": "2-7051cbe5c8faecd085a3fa619e6e6337"
> }
> 
> but this does not seem to help here. Moreover, where do I place the
> template content into this object ?
> 
> 
> I never got that part working so probably it is just a very stupid
> newbie error...
> 
> Best
> Clemens
> 


Re: Newbie problem with template path

Posted by Patrick Barnes <mr...@gmail.com>.
To confirm...
You *are* using couchapp to generate your design doc, keeping the view and
show funcs in files, and the included files in the same couchapp area?

-Patrick

On 28/02/2010 6:57 AM, "Clemens Cap" <ca...@unagon.com> wrote:

I am having a problem to understand the path where the engine looks for
the files included with the !json and !code macros.

More exactly: I am having a

{
  "_id": "_design/example",
  "_rev": "11-4ca79b908a6278eeb8d4d5e2e6488fb5",
  "views": {
      "foo": {
          "map": "function(doc){ emit(doc._id, doc._rev+'QQQ')}"
      }
  },
  "shows": {
      "my": "function(req, doc) {
               // !json templates.edit
               return template(templates.edit,{})  ; }"
  }
}

and

http://localhost:5984/mydatabase/_design/example/_view/foo

as expected. However

http://localhost:5984/mydatabase/_design/example/_show/my

produces a

{"error":"normal","reason":"{gen_server,call,\n
[couch_query_servers,\n
{ret_proc,{proc,<0.21518.0>,<<\"javascript\">>,\n
     {couch_os_process,prompt},\n
{couch_os_process,set_timeout},\n
{couch_os_process,stop}}}]}"}

I am having a non-empty

{
  "_id": "_design/template/_show/my",
  "_rev": "2-7051cbe5c8faecd085a3fa619e6e6337"
}

but this does not seem to help here. Moreover, where do I place the
template content into this object ?


I never got that part working so probably it is just a very stupid
newbie error...

Best
Clemens

Re: Newbie problem with template path

Posted by Chris Anderson <jc...@apache.org>.
On Sat, Feb 27, 2010 at 11:56 AM, Clemens Cap <ca...@unagon.com> wrote:
> I am having a problem to understand the path where the engine looks for
> the files included with the !json and !code macros.
>

I replied to this on the CouchApp list, but it somehow didn't go
through. Lemme see if I can dig it out of buffer or something and
repost it. But not till after I walk the dogs.

The gist is to have it all in one design doc, so it replicates
properly. See the source layout of http://github.com/jchris/taskr/ for
examples.

Chris



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