Skip to content

Commit

Permalink
v6.0.5. Updated QueryEngine. Watching bugfixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Jun 19, 2012
1 parent 2f807a8 commit 9b2a8eb
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## History

- v6.0.5 June 19, 2012
- Updated QueryEngine from version 1.1 to 1.2
- Fixed watch error when deleting files, or changing a directory

- v6.0.4 June 19, 2012
- Fixed skeleton action

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docpad",
"version": "6.0.4",
"version": "6.0.5",
"description": "DocPad is a language agnostic document management system. This means you write your website as documents, in whatever language you wish, and DocPad will handle the compiling, templates and layouts for you. For static documents it will generate static files, for dynamic documents it'll re-render them on each request. You can utilise DocPad by itself, or use it as a module your own custom system. It's pretty cool, and well worth checking out. We love it.",
"homepage": "https://github.com/bevry/docpad",
"keywords": [
Expand Down Expand Up @@ -38,7 +38,7 @@
"bal-util": "1.8.x",
"express": "2.5.x",
"mime": "1.2.x",
"query-engine": "1.1.x",
"query-engine": "1.2.x",
"watchr": "2.0.x",
"caterpillar": "1.1.x",
"commander": "0.6.x",
Expand Down
6 changes: 1 addition & 5 deletions src/lib/base.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ class View extends Backbone.View
class QueryCollection extends QueryEngine.QueryCollection
log: log
emit: emit

# Create Child Collection
createChildCollection: ->
collection = new QueryCollection().setParentCollection(@)
return collection
Collection: QueryCollection

# Export our BaseModel Class
module.exports = {Backbone,Events,Model,Collection,View,QueryCollection}
31 changes: 25 additions & 6 deletions src/lib/docpad.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,7 @@ class DocPad extends EventSystem
# Prepare
{opts,next} = @getActionArgs(opts,next)
docpad = @
docpad.lastGenerate ?= new Date('1970')

# Re-load and re-render only what is necessary
if opts.reset? and opts.reset is false
Expand All @@ -1876,13 +1877,14 @@ class DocPad extends EventSystem

# Reload changed files
database = docpad.getDatabase()
filesToReload = database.findAll(mtime: $gte: docpad.lastGenerate)
filesToReload = opts.filesToReload or new docpad.FilesCollection()
filesToReload.add(database.findAll(mtime: $gte: docpad.lastGenerate).models)
docpad.lastGenerate = new Date()
docpad.loadFiles {collection:filesToReload}, (err) ->
return docpad.generateError(err,next) if err

# Re-render necessary files
filesToRender = new docpad.FilesCollection()
filesToRender = opts.filesToRender or new docpad.FilesCollection()
filesToRender.add(database.findAll(referencesOthers: true).models)
filesToRender.add(filesToReload.models)
docpad.generateRender {collection:filesToRender}, (err) ->
Expand Down Expand Up @@ -2013,26 +2015,43 @@ class DocPad extends EventSystem
# Change event handler
changeHandler = (eventName,filePath,fileCurrentStat,filePreviousStat) ->
# Fetch the file
docpad.log 'debug', "Change detected at #{new Date().toLocaleTimeString()}", eventName, filePath

# Check if we are a file we don't care about
if ( balUtil.commonIgnorePatterns.test(pathUtil.basename(filePath)) )
docpad.log 'debug', "Ignored change at #{new Date().toLocaleTimeString()}", filePath
return

# Don't care if we are a directory
if (fileCurrentStat or filePreviousStat).isDirectory()
docpad.log 'debug', "Directory change at #{new Date().toLocaleTimeString()}", filePath
return

# Create the file object
file = docpad.ensureFileOrDocument({fullPath:filePath})

# Prepare generate everything else
performGenerate = (opts={}) ->
# Do not reset when we do this generate
opts.reset = false
# Log
docpad.log "Regenerating at #{new Date().toLocaleTimeString()}"
# Afterwards, re-render anything that should always re-render
docpad.generate opts, (err) ->
docpad.error(err) if err
docpad.log "Regenerated at #{new Date().toLocaleTimeString()}"

# File was deleted, destroy it
# File was deleted, delete the rendered file, and remove it from the database
if eventName is 'unlink'
file.destroy()
performGenerate()
database.remove(file)
file.delete (err) ->
return docpad.error(err) if err
performGenerate()

# File is new or was changed, update it's mtime by setting the stat
else if eventName in ['new','change']
file.setStat(fileCurrentStat)
performGenerate()
performGenerate({filesToReload:new docpad.FilesCollection([file])})

# Start watching
watch = ->
Expand Down
24 changes: 24 additions & 0 deletions src/lib/models/file.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -442,5 +442,29 @@ class FileModel extends Model
# Chain
@

# Delete the file
# next(err)
delete: (next) ->
# Prepare
file = @
fileOutPath = @get('outPath')

# Log
file.log 'debug', "Delete the file: #{fileOutPath}"

# Write data
balUtil.unlink fileOutPath, (err) ->
# Check
return next(err) if err

# Log
file.log 'debug', "Deleted the file: #{fileOutPath}"

# Next
next()

# Chain
@

# Export
module.exports = FileModel

0 comments on commit 9b2a8eb

Please sign in to comment.