Is CSON optional?

42 views
Skip to first unread message

Asa Baylus

unread,
Nov 4, 2012, 9:35:25 AM11/4/12
to doc...@googlegroups.com
Is it essential to use a docpad.cson file or can we use a docpad.json instead? In playing around I had noticed that building a docpad.json works to a point. However converting the example CSON for the QueryEngine to a JS object literal blows up when processing the "function" reserved keyword.

# sample docpad.cson works great
{
    collections:
        articles: (database) ->
            database.findAllLive({layout: 'article.html.eco'}, {date:-1})
}



# sample docpad.json An error occured: reserved word "function" on line 3 SyntaxError: reserved word "function" on line 3
collections : {
articles : function(database){
   database.findAllLive({
    layout: 'article.html.eco'
   }, {date:-1});
}
}
}
 

Is this happening because the CSON is getting processed by node and returning well formed JSON?

I'm really just curious whether CSON is optional or a hard rule. Its not that I dislike the CSON, actually it's quite nice.

Thanks

Benjamin Lupton

unread,
Nov 13, 2012, 8:10:00 PM11/13/12
to
Unfortunately, the JSON standard does not support functions in it, as well as comments and other nice things. Really blows - which is why we use CSON :)

You can however, make a it a .js file and prefix your configuration object with `module.exports = `. So something like:

# sample docpad.js
module.exports = { 
collections : {
articles : function(database){
    database.findAllLive({
     layout: 'article.html.eco'
    }, {date:-1});
}
}
}
Reply all
Reply to author
Forward
0 new messages