Permalink
Browse files

Fiddling with suspending collections. Needs reset to add shim with qu…

…ery engine to handle certain use cases. Live has to be re-enabled before render. Seems better off just doing silent changes initially.
  • Loading branch information...
1 parent 3b6b1ad commit 40ef6e5ed5d4a3e9621d267d0fdec757b593ecd6 @balupton balupton committed Oct 25, 2012
Showing with 114 additions and 87 deletions.
  1. +2 −2 locale/en.cson
  2. +112 −85 src/lib/docpad.coffee
View
@@ -44,7 +44,7 @@
watchChange: "Change detected at %s"
watchIgnoredChange: "Ignored change at %s"
watchDirectoryChange: "Directory change at %s"
- watchConfigChange: "Configuration change detected at %s"
+ watchReloadChange: "Reload change detected at %s"
# Render
renderingFiles: "Rendering %s files"
@@ -53,7 +53,7 @@
renderProgress: "Currently on %s at %s"
renderGenerating: "Generating..."
renderGeneratingNotification: "Website generating..."
- renderGenerated: "Generated %s files"
+ renderGenerated: "Generated %s files in %s seconds"
renderGeneratedNotification: "Website generated"
renderParsing: 'Parsing everything'
renderParsed: 'Parsed everything'
View
@@ -172,6 +172,17 @@ class DocPad extends EventEmitterEnhanced
@blocks[name] = value
@
+ # Get blocks
+ setBlocks: (blocks) ->
+ @blocks
+ @
+
+ # Set blocks
+ setBlocks: (blocks) ->
+ for own name,value of blocks
+ @setBlock(name,value)
+ @
+
# Collections
collections: null
### {
@@ -185,9 +196,19 @@ class DocPad extends EventEmitterEnhanced
layouts: null # QueryEngine Collection
} ###
+ # Get collections
+ getCollections: ->
+ return @collections
+
+ # Set collections
+ setCollections: (collections) ->
+ for own name,value of collections
+ @setCollection(name,value)
+ @
+
# Get a collection
getCollection: (name) ->
- @collections[name]
+ return @collections[name]
# Set a collection
setCollection: (name,value) ->
@@ -1170,93 +1191,86 @@ class DocPad extends EventEmitterEnhanced
config.collections or= {}
# Standard Collections
- documentsCollection = database.createLiveChildCollection()
- .setQuery('isDocument', {
- $or:
- isDocument: true
- fullPath: $startsWith: config.documentsPaths
- })
- .on('add', (model) ->
- docpad.log('debug', util.format(locale.addingDocument, model.attributes.fullPath))
- _.defaults(model.attributes,{
- isDocument: true
- render: true
- write: true
+ @setCollections(
+ # Standard Collections
+ documents: database.createLiveChildCollection()
+ .setQuery('isDocument', {
+ $or:
+ isDocument: true
+ fullPath: $startsWith: config.documentsPaths
})
- )
- filesCollection = database.createLiveChildCollection()
- .setQuery('isFile', {
- $or:
- isFile: true
- fullPath: $startsWith: config.filesPaths
- })
- .on('add', (model) ->
- docpad.log('debug', util.format(locale.addingFile, model.attributes.fullPath))
- _.defaults(model.attributes,{
- isFile: true
- render: false
- write: true
+ .on('add', (model) ->
+ docpad.log('debug', util.format(locale.addingDocument, model.attributes.fullPath))
+ _.defaults(model.attributes,{
+ isDocument: true
+ render: true
+ write: true
+ })
+ )
+ files: database.createLiveChildCollection()
+ .setQuery('isFile', {
+ $or:
+ isFile: true
+ fullPath: $startsWith: config.filesPaths
})
- )
- layoutsCollection = database.createLiveChildCollection()
- .setQuery('isLayout', {
- $or:
- isLayout: true
- fullPath: $startsWith: config.layoutsPaths
- })
- .on('add', (model) ->
- docpad.log('debug', util.format(locale.addingLayout, model.attributes.fullPath))
- _.defaults(model.attributes,{
- isLayout: true
- render: false
- write: false
+ .on('add', (model) ->
+ docpad.log('debug', util.format(locale.addingFile, model.attributes.fullPath))
+ _.defaults(model.attributes,{
+ isFile: true
+ render: false
+ write: true
+ })
+ )
+ layouts: database.createLiveChildCollection()
+ .setQuery('isLayout', {
+ $or:
+ isLayout: true
+ fullPath: $startsWith: config.layoutsPaths
})
- )
-
- # Special Collections
- htmlCollection = database.createLiveChildCollection()
- .setQuery('isHTML', {
- $or:
- isDocument: true
- isFile: true
- outExtension: 'html'
- })
- .on('add', (model) ->
- docpad.log('debug', util.format(locale.addingHtml, model.attributes.fullPath))
- )
- stylesheetCollection = database.createLiveChildCollection()
- .setQuery('isStylesheet', {
- $or:
- isDocument: true
- isFile: true
- outExtension: $in: [
- 'css',
- 'scss', 'sass',
- 'styl', 'stylus'
- 'less'
- ]
- })
- .on('add', (model) ->
- docpad.log('debug', util.format(locale.addingStylesheet, model.attributes.fullPath))
- model.attributes.referencesOthers = true
- )
+ .on('add', (model) ->
+ docpad.log('debug', util.format(locale.addingLayout, model.attributes.fullPath))
+ _.defaults(model.attributes,{
+ isLayout: true
+ render: false
+ write: false
+ })
+ )
- # Apply collections
- @setCollection('documents', documentsCollection)
- @setCollection('files', filesCollection)
- @setCollection('layouts', layoutsCollection)
- @setCollection('html', htmlCollection)
- @setCollection('stylesheets', stylesheetCollection)
+ # Special Collections
+ html: database.createLiveChildCollection()
+ .setQuery('isHTML', {
+ $or:
+ isDocument: true
+ isFile: true
+ outExtension: 'html'
+ })
+ .on('add', (model) ->
+ docpad.log('debug', util.format(locale.addingHtml, model.attributes.fullPath))
+ )
+ stylesheet: database.createLiveChildCollection()
+ .setQuery('isStylesheet', {
+ $or:
+ isDocument: true
+ isFile: true
+ outExtension: $in: [
+ 'css',
+ 'scss', 'sass',
+ 'styl', 'stylus'
+ 'less'
+ ]
+ })
+ .on('add', (model) ->
+ docpad.log('debug', util.format(locale.addingStylesheet, model.attributes.fullPath))
+ model.attributes.referencesOthers = true
+ )
+ )
# Blocks
- metaBlock = new MetaCollection()
- scriptsBlock = new ScriptsCollection()
- stylesBlock = new StylesCollection()
-
- # Apply Blocks
- @setBlock('meta', metaBlock)
- @setBlock('scripts', scriptsBlock)
- @setBlock('styles', stylesBlock)
+ @setBlocks(
+ meta: new MetaCollection()
+ scripts: new ScriptsCollection()
+ styles: new StylesCollection()
+ )
# Custom Collections Group
tasks = new balUtil.Group (err) ->
@@ -2178,6 +2192,10 @@ class DocPad extends EventEmitterEnhanced
docpad.log 'info', locale.renderGenerating
docpad.notify (new Date()).toLocaleTimeString(), title: locale.renderGeneratingNotification
+ # Disable live collections during the initial generation phase
+ _.each docpad.getCollections(), (collection,collectionName) ->
+ collection.live(false) if collectionName isnt 'layouts'
+
# Fire plugins
docpad.emitSync 'generateBefore', server:docpad.getServer(), (err) ->
# Forward
@@ -2289,6 +2307,10 @@ class DocPad extends EventEmitterEnhanced
collection = opts.collection or @getDatabase()
setProgressIndicator = opts.setProgressIndicator or null
+ # Refresh our collections
+ _.each docpad.getCollections(), (collection) ->
+ collection.live(true).query()
+
# Contextualize the datbaase, perform two render passes, and perform a write
balUtil.flow(
object: docpad
@@ -2309,12 +2331,17 @@ class DocPad extends EventEmitterEnhanced
docpad = @
locale = @getLocale()
+ # Bring our collections back to life
+ _.each docpad.getCollections(), (collection) ->
+ collection.live(true).query()
+
# Fire plugins
docpad.emitSync 'generateAfter', server:docpad.getServer(), (err) ->
return next(err) if err
# Log generated
- docpad.log 'info', util.format(locale.renderGenerated, (opts.count ? 'all'))
+ seconds = (new Date() - docpad.lastGenerate) / 1000
+ docpad.log 'info', util.format(locale.renderGenerated, (opts.count ? 'all'), seconds)
docpad.notify (new Date()).toLocaleTimeString(), title: locale.renderGeneratedNotification
# Completed
@@ -2540,9 +2567,9 @@ class DocPad extends EventEmitterEnhanced
# Watch the config
watchrs = watchr.watch(
- paths: docpad.config.configPaths
+ paths: (docpad.config.reloadPaths or []).concat(docpad.config.configPaths or [])
listener: ->
- docpad.log 'info', util.format(locale.watchConfigChange, new Date().toLocaleTimeString())
+ docpad.log 'info', util.format(locale.watchReloadChange, new Date().toLocaleTimeString())
docpad.action 'load', (err) ->
return docpad.fatal(err) if err
performGenerate(reset:true)

0 comments on commit 40ef6e5

Please sign in to comment.