Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Collection+JSON View Engine for Node.js
CoffeeScript
tree: 6165ba9072

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
README.md
index.js
package.json

README.md

CoffeeScript meets Collection+JSON (cscj)

cscj is a little templating library that makes writing the Collection+JSON media type painless:

# views/index.coffee
@collection ->

  root = "http://localhost:5000"

  @error code: "404", message: "This is a test"

  @href root

  @link href: root, rel: "index"

  @item ->
    @href "#{root}/people/1"
    @link href: "#{root}/1/photos", rel: "photos"
    @datum name: "firstName", value: "Cameron", prompt: "First Name"
    @datum name: "lastName", value: "Bytheway", prompt: "Last Name"

  @query ->
    @href "#{root}/people"
    @rel "people"
    @datum name: "firstName", prompt: "First Name"
    @datum name: "lastName", prompt: "Last Name"

  @template ->
    @datum name: "firstName", prompt: "First Name"
    @datum name: "lastName", prompt: "Last Name"

which would render

{
   "collection":{
      "href":"http://localhost:5000",
      "version":"1.0",
      "error":{
         "code":"404",
         "message":"This is a test"
      },
      "links":[
         {
            "href":"http://localhost:5000",
            "rel":"index"
         }
      ],
      "items":[
         {
            "href":"http://localhost:5000/people/1",
            "links":[
               {
                  "href":"http://localhost:5000/1/photos",
                  "rel":"photos"
               }
            ],
            "data":[
               {
                  "name":"firstName",
                  "value":"Cameron",
                  "prompt":"First Name"
               },
               {
                  "name":"lastName",
                  "value":"Bytheway",
                  "prompt":"Last Name"
               }
            ]
         }
      ],
      "queries":[
         {
            "href":"http://localhost:5000/people",
            "rel":"people",
            "data":[
               {
                  "name":"firstName",
                  "prompt":"First Name"
               },
               {
                  "name":"lastName",
                  "prompt":"Last Name"
               }
            ]
         }
      ],
      "template":{
         "data":[
            {
               "name":"firstName",
               "prompt":"First Name"
            },
            {
               "name":"lastName",
               "prompt":"Last Name"
            }
         ]
      }
   }
}

Usage

Just add it to your dependencies in package.json and you're ready to go!

Tests

npm install -d
npm test
Something went wrong with that request. Please try again.