Permalink
Browse files

up docs and example pic

  • Loading branch information...
1 parent 48ce620 commit 8a92891fdcf936b985bc647c250ccec7aa28960b @radekstepan committed Jul 27, 2012
Showing with 70 additions and 1 deletion.
  1. +70 −1 README.md
  2. BIN example.png
View
71 README.md
@@ -3,6 +3,8 @@ A forms based [node.js](http://nodejs.org/) CMS ala [SilverStripe](http://www.si
The idea was to create a RESTful CMS API that would be edited using a client side app. On the backend, we use [flatiron](http://flatironjs.org/) and on the frontend [chaplin](https://github.com/chaplinjs/chaplin) that itself wraps [Backbone.js](http://documentcloud.github.com/backbone/).
+![image](https://raw.github.com/radekstepan/blad/master/example.png)
+
## Start the service and admin app
We wrap the compilation of user code and core code using `cake` but first, dependencies need to be met.
@@ -22,4 +24,71 @@ To run the tests execute the following.
$ ./test.sh
```
-A `test` collection in MongoDB will be created and cleared before each spec run.
+A `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 receive a lot of timeouts during testing, increase the amount of ms in the `before` function:
+
+```coffeescript
+setTimeout ( ->
+ app.db (collection) ->
+ collection.remove {}, (error, removed) ->
+ collection.find({}).toArray (error, results) ->
+ results.length.should.equal 0
+ done()
+), 100
+```
+
+## Creating custom document types
+
+Create a new folder with the type name in `./src/site`. Each type consists of three files:
+
+### Admin form
+
+Represented by a `form.eco` file.
+
+Each document form automatically has the `url`, `is public?` and `type` fields. Any extra fields are defined by creating a form field that has a unique `name` attribute.
+
+For example, the Markdown document type has a `<textarea>` defined like so:
+
+```eco
+<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:
+
+```eco
+<input type="hidden" name="image" value="<%= @image %>" />
+<input type="file" data-target="image" />
+```
+
+The attribute `data-target`, then, specifies which field to populate with base64 encoded version of the file client side.
+
+### Public presenter
+
+Represented by a `presenter.coffee` file.
+
+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 `html` key:
+
+```coffeescript
+marked = require 'marked'
+
+class MarkdownDocument extends Blað.Type
+
+ # Presentation for the document.
+ render: (done) -> done 'html': marked @markup
+
+Blað.types.MarkdownDocument = MarkdownDocument
+```
+
+Extending the `Blað.Type` class gives us the following helpers:
+
+* `@children()` or `@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.
+
+### Public template
+
+Represented by a `template.eco` file.
+
+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.
View
BIN example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8a92891

Please sign in to comment.