A forms based node.js CMS ala SilverStripe, but smaller
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
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
blad.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.
One can save a file in
src/types/additions.coffee that exports an object. Then, this file can be included from within a Presenter. This way, you can re-use common functionality across types.
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
# 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
It may be useful to know that cache is per document specific, so one can use the same cache key in different document types.
To run the tests execute the following.
$ npm install$ 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.
If you want to test the UI through an example app, execute the following:
$ PORT=5200 npm start
Then visit http://127.0.0.1:5200/admin.