Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

reworked startup and loading of site files

  • Loading branch information...
commit 21f34f16c1b68a0b53b65bac01216880ce8c2e0c 1 parent 92eda0c
@radekstepan authored
Showing with 230 additions and 164 deletions.
  1. +3 −5 README.md
  2. +152 −89 blad.coffee
  3. +5 −0 logo.txt
  4. +3 −2 package.json
  5. 0  public/{ → admin}/css/fonts.css
  6. 0  public/{ → admin}/css/fonts/FontAwesome-webfont.woff
  7. 0  public/{ → admin}/css/fonts/OpenSans-Bold-webfont.woff
  8. 0  public/{ → admin}/css/fonts/OpenSans-ExtraBold-webfont.woff
  9. 0  public/{ → admin}/css/fonts/OpenSans-Light-webfont.woff
  10. 0  public/{ → admin}/css/fonts/OpenSans-Regular-webfont.woff
  11. 0  public/{ → admin}/css/fonts/OpenSans-Semibold-webfont.woff
  12. 0  public/{ → admin}/css/fonts/ProximaNova-Bold-webfont.woff
  13. 0  public/{ → admin}/css/fonts/ProximaNova-Light-webfont.woff
  14. 0  public/{ → admin}/css/fonts/ProximaNova-Reg-webfont.woff
  15. 0  public/{ → admin}/css/fonts/ProximaNova-Xbold-webfont.woff
  16. 0  public/{ → admin}/css/foundation3.css
  17. 0  public/{ → admin}/css/style.css
  18. +2 −2 public/{ → admin}/index.html
  19. 0  public/{ → admin}/js/.gitignore
  20. 0  public/{ → admin}/js/lib/support.js
  21. 0  public/{ → admin}/js/lib/utils.js
  22. 0  public/{ → admin}/js/templates/.gitignore
  23. 0  public/{ → admin}/js/vendor/backbone-0.9.2.js
  24. 0  public/{ → admin}/js/vendor/browserid.js
  25. 0  public/{ → admin}/js/vendor/chaplin.js
  26. 0  public/{ → admin}/js/vendor/foundation.js
  27. 0  public/{ → admin}/js/vendor/jquery-1.7.2.js
  28. 0  public/{ → admin}/js/vendor/kronic.js
  29. 0  public/{ → admin}/js/vendor/modernizr.foundation.js
  30. 0  public/{ → admin}/js/vendor/require-2.0.2.js
  31. 0  public/{ → admin}/js/vendor/underscore-1.3.3.js
  32. +1 −1  src/application.coffee
  33. +3 −3 test/basic.spec.coffee
  34. +3 −3 test/cache.spec.coffee
  35. +3 −3 test/children.spec.coffee
  36. +3 −3 test/children_nested.spec.coffee
  37. +3 −3 test/delete.spec.coffee
  38. +3 −3 test/mapping.spec.coffee
  39. +3 −3 test/markdown.spec.coffee
  40. +3 −3 test/menu.spec.coffee
  41. +3 −3 test/parent.spec.coffee
  42. +3 −3 test/siblings.spec.coffee
  43. +3 −3 test/sitemap.spec.coffee
  44. +31 −32 utils.coffee
View
8 README.md
@@ -1,4 +1,4 @@
-# Blað
+# blað
A forms based [node.js](http://nodejs.org/) CMS ala [SilverStripe](http://www.silverstripe.com/), but smaller.
@@ -82,15 +82,13 @@ Each document has a custom class that determines how it is rendered. It has to o
```coffeescript
marked = require 'marked'
-class MarkdownDocument extends Blað.Type
+class exports.MarkdownDocument
# Presentation for the document.
render: (done) -> done 'html': marked @markup
-
-Blað.types.MarkdownDocument = MarkdownDocument
```
-Extending the `Blað.Type` class gives us the following helpers:
+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.
View
241 blad.coffee
@@ -7,18 +7,24 @@ request = require 'request'
crypto = require 'crypto'
urlib = require 'url'
fs = require 'fs'
-cs = require 'coffee-script'
eco = require 'eco'
Q = require 'q'
domain = require 'domain' # experimental!
winston = require 'winston'
+# The config once set.
+CONFIG = {}
+# The MongoDB connection once set.
+DB = null
+# Path to the site source code will be here.
+SITE_PATH = null
+# blað in da house.
+blað = 'types': {}
+
# Internal flatiron app.
service = flatiron.app
-# The config once set.
-config = {}
-
+# HTTP plugins.
service.use flatiron.plugins.http,
'before': [
# Have a nice favicon.
@@ -35,7 +41,7 @@ service.use flatiron.plugins.http,
res.end()
else
# Is the key valid?
- if req.headers['x-blad-apikey'] in config.browserid.hashes
+ if req.headers['x-blad-apikey'] in CONFIG.browserid.hashes
next()
else
res.writeHead 403
@@ -52,13 +58,12 @@ service.use flatiron.plugins.http,
# Go Union!
union.errorHandler err, req, res
-# -------------------------------------------------------------------
-# Eco templating.
+# Eco templating plugin.
service.use
- name: "eco-templating"
+ name: 'eco-templating'
attach: (options) ->
service.eco = (path, data, cb) ->
- fs.readFile "./src/site/#{path}.eco", "utf8", (err, template) ->
+ fs.readFile "#{SITE_PATH}/src/types/#{path}.eco", "utf8", (err, template) ->
if err then cb err, null
else
try
@@ -66,42 +71,35 @@ service.use
catch e
cb e, null
-# Start MongoDB.
-db = null
-# Add a collection plugin.
+# MongoDB collection plugin.
service.use
- name: "mongodb"
+ name: 'mongodb'
attach: (options) ->
service.db = (done) ->
collection = (done) ->
- db.collection config.env, (err, coll) ->
+ DB.collection CONFIG.env, (err, coll) ->
throw err if err
done coll
- unless db?
- mongodb.Db.connect config.mongodb, (err, connection) ->
- winston.info "Connected to #{config.mongodb}"
- db = connection
+ unless DB?
+ winston.debug 'Connect to MongoDB'
+
+ mongodb.Db.connect CONFIG.mongodb, (err, connection) ->
throw err if err
+ winston.info 'Connected to ' + CONFIG.mongodb.bold
+ DB = connection
collection done
else
collection done
-# Map all existing public documents.
-service.db (collection) ->
- collection.find('public': true).toArray (err, docs) ->
- throw err if err
- for doc in docs
- winston.info "Mapping url " + doc.url
- service.router.path doc.url, Blað.get
-
# -------------------------------------------------------------------
+
# BrowserID auth.
service.router.path "/auth", ->
@post ->
# Authenticate.
request.post
- 'url': config.browserid.provider
+ 'url': CONFIG.browserid.provider
'form':
'assertion': @req.body.assertion
'audience': "http://#{@req.headers.host}"
@@ -112,13 +110,13 @@ service.router.path "/auth", ->
if body.status is 'okay'
# Authorize.
- if body.email in config.browserid.users
+ if body.email in CONFIG.browserid.users
winston.info "Identity verified for #{body.email}"
# Create API Key from email and salt for the client.
@res.writeHead 200, 'application/json'
@res.write JSON.stringify
'email': body.email
- 'key': crypto.createHash('md5').update(body.email + config.browserid.salt).digest('hex')
+ 'key': crypto.createHash('md5').update(body.email + CONFIG.browserid.salt).digest('hex')
else
winston.warning "#{body.email} tried to access the API"
@res.writeHead 403, 'application/json'
@@ -126,17 +124,18 @@ service.router.path "/auth", ->
'message': "Your email #{body.email} is not authorized to access the service"
else
# Pass on the authentication error response to the client.
- service.log.info body.message.red if config.env isnt 'test'
+ winston.error body.message
@res.writeHead 403, 'application/json'
@res.write JSON.stringify body
@res.end()
# -------------------------------------------------------------------
+
# Sitemap.xml
service.router.path "/sitemap.xml", ->
@get ->
- service.log.info "Get sitemap.xml" if config.env isnt 'test'
+ winston.info 'Get sitemap.xml'
# Give me all public documents.
service.db (collection) =>
@@ -153,6 +152,7 @@ service.router.path "/sitemap.xml", ->
@res.end()
# -------------------------------------------------------------------
+
# Get all documents.
service.router.path "/api/documents", ->
@get ->
@@ -165,6 +165,8 @@ service.router.path "/api/documents", ->
@res.write JSON.stringify docs
@res.end()
+# -------------------------------------------------------------------
+
# Get/update/create a document.
service.router.path "/api/document", ->
@get ->
@@ -217,7 +219,7 @@ service.router.path "/api/document", ->
cb = => @res.writeHead 201, "content-type": "application/json"
# One command to save/update and optionaly unmap.
- Blað.save doc, (err, reply) =>
+ blað.save doc, (err, reply) =>
if err
winston.error 'I am different...'
@@ -228,8 +230,8 @@ service.router.path "/api/document", ->
else
if doc.public
# Map a document to a public URL.
- winston.info "Mapping url #{reply}"
- service.router.path reply, Blað.get
+ winston.info 'Mapping url ' + reply.underline
+ service.router.path reply, blað.get
# Stringify the new document so Backbone can see what has changed.
service.db (collection) =>
@@ -279,7 +281,7 @@ service.router.path "/api/document", ->
# Did this doc actually exist?
if doc
# Unmap the url.
- Blað.unmap doc.url
+ blað.unmap doc.url
# Respond in kind.
@res.writeHead 200, "content-type": "application/json"
@@ -289,11 +291,9 @@ service.router.path "/api/document", ->
@res.end()
# -------------------------------------------------------------------
-# Blað.
-Blað = {}
# Save/update a document.
-Blað.save = (doc, cb) ->
+blað.save = (doc, cb) ->
# Prefix URL with a forward slash if not present.
if doc.url[0] isnt '/' then doc.url = '/' + doc.url
# Remove trailing slash if present.
@@ -332,7 +332,7 @@ Blað.save = (doc, cb) ->
else
# Unmap the original URL if it was public.
old = docs.pop()
- if old.public then Blað.unmap old.url
+ if old.public then blað.unmap old.url
# Get the id and remove the key as we cannot modify that one.
_id = doc._id
@@ -359,7 +359,7 @@ Blað.save = (doc, cb) ->
cb false, records[0].url
# Retrieve publicly mserviceed document.
-Blað.get = ->
+blað.get = ->
@get ->
# Get the doc(s) from the db. We want to get the whole 'group'.
service.db (collection) =>
@@ -371,22 +371,20 @@ Blað.get = ->
# Any children?
if docs.length > 1 then record._children = (d for d in docs[1...docs.length])
- winston.info "Serving document #{record._id}"
+ winston.debug 'Render url ' + (record.url or record._id).underline
# Do we have this type?
- if Blað.types[record.type]?
+ if blað.types[record.type]?
# Create a new domain for the 'untrusted' presenter.
doom = domain.create()
# Handle this doom like this.
- doom.on 'error', (err) =>
- # Say what?
- winston.error err.message
-
+ doom.on 'error', (err) =>
# Can we grace?
try
+ winston.error t = "Error occurred, sorry: #{err.message}"
@res.writeHead 500
- @res.end 'Error occurred, sorry.'
+ @res.end t
@res.on 'close', ->
# Forcibly shut down any other things added to this domain.
doom.dispose()
@@ -398,7 +396,7 @@ Blað.get = ->
# Finally execute the presenter in the domain context.
doom.run =>
# Init new type.
- presenter = new Blað.types[record.type](record)
+ presenter = new blað.types[record.type](record)
# Give us the data.
presenter.render (context, template=true) =>
@@ -408,25 +406,27 @@ Blað.get = ->
if err
@res.writeHead 500
@res.write err.message
+ @res.end()
else
# Do we have a layout template to render to?
service.eco 'layout', 'page': html, (err, layout) =>
- @res.writeHead 200, "content-type": "text/html"
+ @res.writeHead 200, 'content-type': 'text/html'
@res.write if err then html else layout
@res.end()
else
# Render as is, JSON.
- @res.writeHead 200, "content-type": "application/json"
+ @res.writeHead 200, 'content-type': 'application/json'
@res.write JSON.stringify context
@res.end()
else
+ winston.warn t = "Document type #{record.type} not one of #{Object.keys(blað.types).join(', ')}"
@res.writeHead 500
- @res.write 'Non existent document type'
+ @res.write t
@res.end()
# Unmap document from router.
-Blað.unmap = (url) ->
- winston.info "Delete url #{url}"
+blað.unmap = (url) ->
+ winston.info 'Delete url ' + url.underline
# A bit of hairy tweaking.
if url is '/' then delete service.router.routes.get
@@ -440,10 +440,7 @@ Blað.unmap = (url) ->
else
r = r[parts[i]]
-# Document types.
-Blað.types = {}
-
-class Blað.Type
+class blað.Type
# Returns top level documents.
menu: (cb) ->
@@ -549,78 +546,144 @@ class Blað.Type
true
# A type that is always present, the default.
-class BasicDocument extends Blað.Type
+class blað.types.BasicDocument extends blað.Type
# Presentation for the document.
render: (done) -> done @, false
-Blað.types.BasicDocument = BasicDocument
-
# -------------------------------------------------------------------
-# So we can inject our own types.
-exports.Blað = Blað
-
# Exposed firestarter that builds the site and starts the service.
exports.start = (cfg, dir, done) ->
+ # CLI output on the default output?
+ winston.cli()
+
+ # Set site path on us.
+ SITE_PATH = dir
+
+ # Welcome.
+ ( do ->
+ def = Q.defer()
+
+ winston.info "Welcome to #{'blað'.grey}"
+
+ fs.readFile "#{__dirname}/logo.txt", (err, data) ->
+ if err then def.reject err
+
+ ( winston.help line.cyan.bold for line in data.toString('utf-8').split('\n') )
+
+ winston.help ''
+ winston.help 'A forms based Node.js CMS'
+ winston.help ''
+
+ def.resolve()
+
+ def.promise
+
# Deep copy of config (and check dict passed in).
- Q.fcall( ->
- config = JSON.parse JSON.stringify cfg
+ ).then( ->
+ winston.debug 'Duplicate config'
+
+ CONFIG = JSON.parse JSON.stringify cfg
# Go env or config? And validate.
).then( ->
- # Resolve config coming from environment and the `cfg` dict.
- config.mongodb = process.env.DATABASE_URL or config.mongodb # MongoDB database
- config.port = process.env.PORT or config.port # port number
- config.env = process.env.NODE_ENV or 'documents' # environment/collection to use
- config.browserid ?= {}
- config.browserid.salt = process.env.API_SALT or config.browserid.salt # API key salt
+ winston.debug 'Validate config'
- # CLI output on the default output?
- winston.cli()
+ # Resolve config coming from environment and the `cfg` dict.
+ CONFIG.mongodb = process.env.DATABASE_URL or CONFIG.mongodb # MongoDB database
+ CONFIG.port = process.env.PORT or CONFIG.port # port number
+ CONFIG.env = process.env.NODE_ENV or 'documents' # environment/collection to use
+ CONFIG.browserid ?= {}
+ CONFIG.browserid.salt = process.env.API_SALT or CONFIG.browserid.salt # API key salt
# Validate file.
- if not config.browserid? or
- not config.browserid.provider? or
- not config.browserid.salt? or
- not config.browserid.users? or
- not config.browserid.users instanceof Array
+ if not CONFIG.browserid? or
+ not CONFIG.browserid.provider? or
+ not CONFIG.browserid.salt? or
+ not CONFIG.browserid.users? or
+ not CONFIG.browserid.users instanceof Array
throw 'You need to create a valid `browserid` section'
- if not config.mongodb?
+ if not CONFIG.mongodb?
throw 'You need to specify the `mongodb` uri'
# Create create hashes of salt + user emails.
- config.browserid.hashes = []
- for email in config.browserid.users
- config.browserid.hashes.push crypto.createHash('md5').update(email + config.browserid.salt).digest('hex')
+ CONFIG.browserid.hashes = []
+ for email in CONFIG.browserid.users
+ CONFIG.browserid.hashes.push crypto.createHash('md5').update(email + CONFIG.browserid.salt).digest('hex')
+ # Code compilation.
).then( ->
+ winston.debug 'Compile code'
+
utils = require './utils.coffee'
- # Compile admin coffee files.
+ # Compile our and their code.
+ Q.all [ utils.compile.admin(), utils.compile.forms(SITE_PATH), utils.include.presenters(SITE_PATH) ]
- # Compile in the site's type forms.
+ # Include site's presenters on us.
+ ).then( ([ α, β, presenters ]) ->
+ winston.debug 'Including custom presenters'
- # Include all the site's type presenters.
+ # Class extends like in CoffeeScript.
+ ext = (child, parent) ->
+ ctor = -> @constructor = child
+
+ for key of parent
+ child[key] = parent[key] if {}.hasOwnProperty.call(parent, key)
+
+ ctor:: = parent::
+ child:: = new ctor()
+ child.__super__ = parent::
+ child
+
+ # Traverse all plain functions.
+ for f in presenters
+ # Require the file.
+ req = require f
+ # Get the first key - a document that will be exposed, hopefully.
+ key = Object.keys(req)[0]
+ # The function exposed.
+ fn = req[key]
+
+ # Extend the function on us.
+ blað.types[key] = fn extends blað.Type
# Start flatiron service on a port.
).then( ->
+ winston.debug 'Start ' + 'flatiron'.grey
+
def = Q.defer()
- service.start config.port, (err) ->
+ service.start CONFIG.port, (err) ->
if err then def.reject err
else def.resolve()
def.promise
+ # Map all existing public documents.
+ ).then( ->
+ winston.debug 'Map existing documents'
+
+ def = Q.defer()
+ service.db (collection) ->
+ collection.find('public': true).toArray (err, docs) ->
+ if err then def.reject errr
+ for doc in docs
+ winston.info 'Mapping url ' + doc.url.underline
+ service.router.path doc.url, blað.get
+ def.resolve()
+ def.promise
+
# OK or bust.
).done(
->
- winston.info "Listening on port #{service.server.address().port} " + 'ok'.green.bold
+ winston.info 'Listening on port ' + service.server.address().port.toString().bold
+ winston.info 'blað'.grey + ' started ' + 'ok'.green.bold
# Callback?
if done and typeof done is 'function' then done()
, (err) ->
try
err = JSON.parse(err)
- winston.error(err.error.message or err.message or err)
+ winston.error err.error.message or err.message or err
catch e
- winston.error(err) if config.env isnt 'test'
+ winston.error err
)
View
5 logo.txt
@@ -0,0 +1,5 @@
+______ ______ _________
+___ /____ /_____ ______ /
+__ __ \_ /_ __ `/ __ /
+_ /_/ / / / /_/ // /_/ /
+/_.___//_/ \__,_/ \__,_/
View
5 package.json
@@ -29,6 +29,7 @@
"test": "NODE_ENV=test ./node_modules/mocha/bin/mocha --compilers coffee:coffee-script --ui bdd --reporter spec"
},
"bin": {
- "blad": "./bin/blad"
- }
+ "blad": "./bin/blad.js"
+ },
+ "main": "./blad.coffee"
}
View
0  public/css/fonts.css → public/admin/css/fonts.css
File renamed without changes
View
0  public/css/fonts/FontAwesome-webfont.woff → .../admin/css/fonts/FontAwesome-webfont.woff
File renamed without changes
View
0  public/css/fonts/OpenSans-Bold-webfont.woff → ...dmin/css/fonts/OpenSans-Bold-webfont.woff
File renamed without changes
View
0  ...css/fonts/OpenSans-ExtraBold-webfont.woff → ...css/fonts/OpenSans-ExtraBold-webfont.woff
File renamed without changes
View
0  public/css/fonts/OpenSans-Light-webfont.woff → ...min/css/fonts/OpenSans-Light-webfont.woff
File renamed without changes
View
0  ...c/css/fonts/OpenSans-Regular-webfont.woff → ...n/css/fonts/OpenSans-Regular-webfont.woff
File renamed without changes
View
0  .../css/fonts/OpenSans-Semibold-webfont.woff → .../css/fonts/OpenSans-Semibold-webfont.woff
File renamed without changes
View
0  ...c/css/fonts/ProximaNova-Bold-webfont.woff → ...n/css/fonts/ProximaNova-Bold-webfont.woff
File renamed without changes
View
0  .../css/fonts/ProximaNova-Light-webfont.woff → .../css/fonts/ProximaNova-Light-webfont.woff
File renamed without changes
View
0  ...ic/css/fonts/ProximaNova-Reg-webfont.woff → ...in/css/fonts/ProximaNova-Reg-webfont.woff
File renamed without changes
View
0  .../css/fonts/ProximaNova-Xbold-webfont.woff → .../css/fonts/ProximaNova-Xbold-webfont.woff
File renamed without changes
View
0  public/css/foundation3.css → public/admin/css/foundation3.css
File renamed without changes
View
0  public/css/style.css → public/admin/css/style.css
File renamed without changes
View
4 public/index.html → public/admin/index.html
@@ -2,7 +2,7 @@
<head>
<meta charset="utf-8" />
- <title>Blað CMS</title>
+ <title>blað CMS</title>
<link rel="stylesheet" href="css/foundation3.css">
<link rel="stylesheet" href="css/style.css">
@@ -13,7 +13,7 @@
<div id="top">
<div class="row">
<div class="two columns">
- <a class="name" href="/admin">Blað CMS</a>
+ <a class="name" href="/admin">blað CMS</a>
</div>
<div class="two column">
<a href="/admin/new" class="small blue nice button right new">New Document</a></a>
View
0  public/js/.gitignore → public/admin/js/.gitignore
File renamed without changes
View
0  public/js/lib/support.js → public/admin/js/lib/support.js
File renamed without changes
View
0  public/js/lib/utils.js → public/admin/js/lib/utils.js
File renamed without changes
View
0  public/js/templates/.gitignore → public/admin/js/templates/.gitignore
File renamed without changes
View
0  public/js/vendor/backbone-0.9.2.js → public/admin/js/vendor/backbone-0.9.2.js
File renamed without changes
View
0  public/js/vendor/browserid.js → public/admin/js/vendor/browserid.js
File renamed without changes
View
0  public/js/vendor/chaplin.js → public/admin/js/vendor/chaplin.js
File renamed without changes
View
0  public/js/vendor/foundation.js → public/admin/js/vendor/foundation.js
File renamed without changes
View
0  public/js/vendor/jquery-1.7.2.js → public/admin/js/vendor/jquery-1.7.2.js
File renamed without changes
View
0  public/js/vendor/kronic.js → public/admin/js/vendor/kronic.js
File renamed without changes
View
0  public/js/vendor/modernizr.foundation.js → ...c/admin/js/vendor/modernizr.foundation.js
File renamed without changes
View
0  public/js/vendor/require-2.0.2.js → public/admin/js/vendor/require-2.0.2.js
File renamed without changes
View
0  public/js/vendor/underscore-1.3.3.js → public/admin/js/vendor/underscore-1.3.3.js
File renamed without changes
View
2  src/application.coffee
@@ -10,7 +10,7 @@ define [
# Set your application name here so the document title is set to
# “Controller title – Site title” (see Layout#adjustTitle)
- title: 'Blað CMS'
+ title: 'blað CMS'
# Store the X-Blad-ApiKey here. Application is global.
apiKey: undefined
View
6 test/basic.spec.coffee
@@ -4,14 +4,14 @@ querystring = require 'querystring'
exported = require('../server.coffee')
app = exported.app
-Blað = exported.Blað
+blað = exported.blað
config = exported.config
config.browserid.hashes = [ '@dummy' ]
# -------------------------------------------------------------------
-class BasicDocument extends Blað.Type
+class BasicDocument extends blað.Type
# Render as JSON as is.
render: (done) ->
@@ -21,7 +21,7 @@ class BasicDocument extends Blað.Type
'url': @url
, false
-Blað.types.BasicDocument = BasicDocument
+blað.types.BasicDocument = BasicDocument
# -------------------------------------------------------------------
View
6 test/cache.spec.coffee
@@ -4,14 +4,14 @@ querystring = require 'querystring'
exported = require('../server.coffee')
app = exported.app
-Blað = exported.Blað
+blað = exported.blað
config = exported.config
config.browserid.hashes = [ '@dummy' ]
# -------------------------------------------------------------------
-class CacheDocument extends Blað.Type
+class CacheDocument extends blað.Type
render: (done) ->
# Do we have cache already?
@@ -38,7 +38,7 @@ class CacheDocument extends Blað.Type
'was': 'new'
, false
-Blað.types.CacheDocument = CacheDocument
+blað.types.CacheDocument = CacheDocument
# -------------------------------------------------------------------
View
6 test/children.spec.coffee
@@ -4,21 +4,21 @@ querystring = require 'querystring'
exported = require('../server.coffee')
app = exported.app
-Blað = exported.Blað
+blað = exported.blað
config = exported.config
config.browserid.hashes = [ '@dummy' ]
# -------------------------------------------------------------------
-class HasChildrenDocument extends Blað.Type
+class HasChildrenDocument extends blað.Type
render: (done) ->
done
'all': @children() or {}
, false
-Blað.types.HasChildrenDocument = HasChildrenDocument
+blað.types.HasChildrenDocument = HasChildrenDocument
# -------------------------------------------------------------------
View
6 test/children_nested.spec.coffee
@@ -4,14 +4,14 @@ querystring = require 'querystring'
exported = require('../server.coffee')
app = exported.app
-Blað = exported.Blað
+blað = exported.blað
config = exported.config
config.browserid.hashes = [ '@dummy' ]
# -------------------------------------------------------------------
-class HasChildrenDocument extends Blað.Type
+class HasChildrenDocument extends blað.Type
render: (done) ->
done
@@ -20,7 +20,7 @@ class HasChildrenDocument extends Blað.Type
'lvl1': @children 1
, false
-Blað.types.HasChildrenDocument = HasChildrenDocument
+blað.types.HasChildrenDocument = HasChildrenDocument
# -------------------------------------------------------------------
View
6 test/delete.spec.coffee
@@ -4,14 +4,14 @@ querystring = require 'querystring'
exported = require('../server.coffee')
app = exported.app
-Blað = exported.Blað
+blað = exported.blað
config = exported.config
config.browserid.hashes = [ '@dummy' ]
# -------------------------------------------------------------------
-class DeleteDocument extends Blað.Type
+class DeleteDocument extends blað.Type
# Render as JSON as is.
render: (done) ->
@@ -20,7 +20,7 @@ class DeleteDocument extends Blað.Type
'url': @url
, false
-Blað.types.DeleteDocument = DeleteDocument
+blað.types.DeleteDocument = DeleteDocument
# -------------------------------------------------------------------
View
6 test/mapping.spec.coffee
@@ -4,14 +4,14 @@ querystring = require 'querystring'
exported = require('../server.coffee')
app = exported.app
-Blað = exported.Blað
+blað = exported.blað
config = exported.config
config.browserid.hashes = [ '@dummy' ]
# -------------------------------------------------------------------
-class DummyDocument extends Blað.Type
+class DummyDocument extends blað.Type
# Render as JSON as is.
render: (done) ->
@@ -21,7 +21,7 @@ class DummyDocument extends Blað.Type
'_id': @_id
, false
-Blað.types.DummyDocument = DummyDocument
+blað.types.DummyDocument = DummyDocument
# -------------------------------------------------------------------
View
6 test/markdown.spec.coffee
@@ -4,7 +4,7 @@ querystring = require 'querystring'
exported = require('../server.coffee')
app = exported.app
-Blað = exported.Blað
+blað = exported.blað
config = exported.config
config.browserid.hashes = [ '@dummy' ]
@@ -13,14 +13,14 @@ config.browserid.hashes = [ '@dummy' ]
marked = require 'marked'
-class MarkdownDocument extends Blað.Type
+class MarkdownDocument extends blað.Type
render: (done) ->
done
'html': marked @markup
, false
-Blað.types.MarkdownDocument = MarkdownDocument
+blað.types.MarkdownDocument = MarkdownDocument
# -------------------------------------------------------------------
View
6 test/menu.spec.coffee
@@ -4,21 +4,21 @@ querystring = require 'querystring'
exported = require('../server.coffee')
app = exported.app
-Blað = exported.Blað
+blað = exported.blað
config = exported.config
config.browserid.hashes = [ '@dummy' ]
# -------------------------------------------------------------------
-class MenuDocument extends Blað.Type
+class MenuDocument extends blað.Type
# Render as JSON as is.
render: (done) ->
@menu (docs) ->
done docs, false
-Blað.types.MenuDocument = MenuDocument
+blað.types.MenuDocument = MenuDocument
# -------------------------------------------------------------------
View
6 test/parent.spec.coffee
@@ -4,21 +4,21 @@ querystring = require 'querystring'
exported = require('../server.coffee')
app = exported.app
-Blað = exported.Blað
+blað = exported.blað
config = exported.config
config.browserid.hashes = [ '@dummy' ]
# -------------------------------------------------------------------
-class ParentDocument extends Blað.Type
+class ParentDocument extends blað.Type
# Render as JSON as is.
render: (done) ->
@parent (doc) ->
done doc, false
-Blað.types.ParentDocument = ParentDocument
+blað.types.ParentDocument = ParentDocument
# -------------------------------------------------------------------
View
6 test/siblings.spec.coffee
@@ -4,21 +4,21 @@ querystring = require 'querystring'
exported = require('../server.coffee')
app = exported.app
-Blað = exported.Blað
+blað = exported.blað
config = exported.config
config.browserid.hashes = [ '@dummy' ]
# -------------------------------------------------------------------
-class SiblingsDocument extends Blað.Type
+class SiblingsDocument extends blað.Type
# Render as JSON as is.
render: (done) ->
@siblings (docs) ->
done docs, false
-Blað.types.SiblingsDocument = SiblingsDocument
+blað.types.SiblingsDocument = SiblingsDocument
# -------------------------------------------------------------------
View
6 test/sitemap.spec.coffee
@@ -4,16 +4,16 @@ querystring = require 'querystring'
exported = require('../server.coffee')
app = exported.app
-Blað = exported.Blað
+blað = exported.blað
config = exported.config
config.browserid.hashes = [ '@dummy' ]
# -------------------------------------------------------------------
-class SitemapDocument extends Blað.Type
+class SitemapDocument extends blað.Type
-Blað.types.SitemapDocument = SitemapDocument
+blað.types.SitemapDocument = SitemapDocument
# -------------------------------------------------------------------
View
63 utils.coffee
@@ -4,40 +4,33 @@ cs = require 'coffee-script'
eco = require 'eco'
uglify = require 'uglify-js'
Q = require 'q'
-require 'colors'
# Compile API server and admin client code.
-exports.compile =
- # Core server code.
- 'server': ->
- codez = [ fs.readFileSync('./server.coffee', "utf-8") ]
-
- # Custom presenters.
- walk './src/site', (files) ->
- for file in files when file.match /presenter\.coffee/
- console.log file.grey
- codez.push fs.readFileSync(file, "utf-8")
-
- # Write it all.
- write './server.js', cs.compile codez.join("\n")
-
- # Client side code.
- 'client': (done) ->
- walk './src/admin', (files) ->
+exports.compile =
+ #Admin client code.
+ 'admin': ->
+ def = Q.defer()
+
+ walk "#{__dirname}/src", (files) ->
for file in files
- console.log file.grey
if file.match /\.eco/
name = file.split('/').pop()
js = eco.precompile fs.readFileSync file, "utf-8"
js = (uglify.minify("JST['#{name}'] = #{js}", 'fromString': true)).code
- write file.replace('./src/admin', './public/admin/js').replace('.eco', '.js'), js
+ write file.replace('/src/', '/public/admin/js/').replace('.eco', '.js'), js # what if we have /src/ in deeper?
else if file.match /\.coffee/
js = cs.compile fs.readFileSync(file, "utf-8"), 'bare': 'on'
- write file.replace('./src/admin', './public/admin/js').replace('.coffee', '.js'), js
-
- # Custom document forms.
- 'forms': (done) ->
- walk './src/site', (files) ->
+ write file.replace('/src/', '/public/admin/js/').replace('.coffee', '.js'), js # what if we have /src/ in deeper?
+
+ def.resolve()
+
+ def.promise
+
+ # Site's custom document type forms.
+ 'forms': (dir) ->
+ def = Q.defer()
+
+ walk "#{dir}/src/types", (files) ->
tml = []
# Inject a BasicDocument form first.
@@ -45,12 +38,23 @@ exports.compile =
# Do user's files.
for file in files when file.match /form\.eco/
- console.log file.grey
js = eco.precompile fs.readFileSync file, "utf-8"
p = file.split('/') ; name = p[p.length-2]
tml.push (uglify.minify("JST['form_#{name}.eco'] = #{js}", 'fromString': true)).code
- write './public/admin/js/templates/document_forms.js', tml.join("\n")
+ write "#{__dirname}/public/admin/js/templates/document_forms.js", tml.join("\n")
+
+ def.resolve()
+
+ def.promise
+
+exports.include =
+ # Get a list of presenter paths to includ in super.
+ 'presenters': (dir) ->
+ def = Q.defer()
+ walk "#{dir}/src/types", (files) ->
+ def.resolve ( f for f in files when f.match /presenter\.coffee/ )
+ def.promise
exports.db =
# Export the database into a JSON file.
@@ -66,8 +70,6 @@ exports.db =
# Write file.
fs.write id, JSON.stringify(docs, null, "\t"), null, "utf8"
-
- console.log "Dumped #{docs.length} documents".yellow
# Clears all! and imports the database from a JSON file.
'import': ->
blad.app.db (collection) ->
@@ -85,8 +87,6 @@ exports.db =
collection.insert docs, { 'safe': true }, (err, docs) ->
throw err if err
- console.log "Inserted #{docs.length} documents".yellow
-
# -------------------------------------------------------------------
# Traverse a directory and return a list of files (async, recursive).
@@ -127,7 +127,6 @@ write = (path, text, mode = "w") ->
# Create the directory if it does not exist first.
dir = path.split('/').reverse()[1...].reverse().join('/')
if dir isnt '.'
- console.log "Creating dir #{dir}".yellow
try
fs.mkdirSync dir, 0o0777
catch e
Please sign in to comment.
Something went wrong with that request. Please try again.