The way to use this CMS is to require it as a package. See blað example site for a guide on how to do so. If you know what you are doing, require and start the service like so:
fs = require 'fs'service = require 'blad'config = JSONparse fsreadFileSync './config.json'servicestart config__dirname
Creating custom document types
Create a new folder with the type name in
./src/site. Each type consists of three files:
Represented by a
Each document form automatically has the
is public? and
type fields. Any extra fields are defined by creating a form field that has a unique
For example, the Markdown document type has a
<textarea> defined like so:
<div class="nine columns"><textarea name="markup"><%= @markup %></textarea></div>
Notice that to display the already saved version of that field, we use eco markup that populates a variable by the
name of the field.
File upload fields are a special case that need to have two fields defined. One for the actual
type="file" and one for a place where the field will be loaded client side:
<input type="hidden" name="image" value="<%= @image %>" /><input type="file" data-custom="file" data-target="image" />
data-target, then, specifies which field to populate with base64 encoded version of the file client side.
By the same token, we use Kronic to work with nicely formatted dates. To make use of this library, define the date fields like so:
<input type="hidden" name="published" value="<%= @published or (new Date()).toJSON() %>" /><input type="text" data-custom="date" data-target="published" value="<%= if @published then Kronic.format(new Date(@published)) else 'Today' %>" />
Represented by a
Each document has a custom class that determines how it is rendered. It has to only have a
render function defined that takes a callback with contect that is passed to a template. As an example of Markdown rendering that returns the HTML result under the
require 'blad'marked = require 'marked'# Presentation for the document.: done 'html': marked @markup
blað.Type class gives us the following helpers:
@children(n)that returns public and private documents (optionally of a specific level) that begin with the same URL as the current document... its children.
@menu()that returns public and private top level documents; those documents that have only a leading slash in its URL.
Represented by a
This file is populated with a context coming from the presenter. In the above Markdown example, we have passed only the
html key - value forward.
/src/site/layout.eco file is found, it will be used as a wrapping template around individual templates. The key
page populated with the individual template is passed to it.
Sometimes new data may be fetched from within the Presenter and one would like to cache these for say a day. The following shows a workflow from within the Presneter's
- We check if data under a specific key is old. The second parameter represents a time in milliseconds after which to consider a key value pair to be old. One could also pass a third paramter passing in which unit the previous parameter is.
- If all data is fresh we get a data saved under a key. We could also pass a context/document as the second parameter. This is useful if we want to retrieve cache for a sibling, child document etc.
- If data is old, we save the new data returning the result in a callback.
# Check if data in store is old.if @storeisOld 'data'300# Update with new info and render back.@storesave 'data''new information'=>done'data': @storeget'data''was': 'old'falseelse# Nope, all fresh.done'data': @storeget'data''was': 'fresh'false
Mocha test suite
To run the tests execute the following.
$ npm test
test collection in MongoDB will be created and cleared before each spec run. Make sure the server app is switched off in order to run the tests.