Permalink
Browse files

Merged in dev-profile

  • Loading branch information...
2 parents 978c781 + a877850 commit b9a2f3610aaa7ac189e52aa1936035070fffce69 @balupton balupton committed Nov 28, 2012
View
@@ -1,5 +1,18 @@
#!/usr/bin/env node
-var command = [process.argv[0],'--debug-brk',__dirname+'/../out/bin/docpad'].concat(process.argv.slice(2));
+
+// Prefix our docpad executable with the node debug and profile flags
+// and suffix docpad with it's profile flag
+var command = [
+ process.argv[0],
+ '--debug-brk',
+ '--prof',
+ __dirname+'/../out/bin/docpad'
+].concat(process.argv.slice(2));
+
+// Output the command we'll be running
+console.log(command.join(' '));
+
+// And spawn our command and let us know if any errors occur
require('bal-util').spawn(command,{cwd:process.cwd(),output:true},function(err){
if (err) console.log(err);
});
View
@@ -82,6 +82,10 @@
writingFiles: "Writing %s files"
wroteFiles: "Wrote %s files"
+ # Clean
+ cleaningFiles: "Cleaning %s files"
+ cleanedFiles: "Cleaned %s files"
+
# Action
actionStart: "Performing the action %s"
actionFinished: "Performed the action %s"
@@ -150,6 +154,7 @@
consoleOptionForce: "force a re-install of all modules"
consoleOptionPort: "a custom port to use for the server <port>"
consoleOptionSkeleton: "for new projects, instead of being asked for the skeleton, you can specify it here"
+ consoleOptionProfile: "enable profiling"
# Misc
welcome: "Welcome to DocPad %s"
View
@@ -190,6 +190,8 @@ class DocPad extends EventEmitterEnhanced
'renderAfter'
'writeBefore'
'writeAfter'
+ 'cleanBefore'
+ 'cleanAfter'
'serverBefore'
'serverExtend'
'serverAfter'
@@ -2318,6 +2320,44 @@ class DocPad extends EventEmitterEnhanced
# Chain
@
+ # Clean files
+ # next(err)
+ cleanFiles: (opts={},next) ->
+ # Prepare
+ docpad = @
+ locale = @getLocale()
+ {collection} = opts
+
+ # Log
+ docpad.log 'debug', util.format(locale.cleaningFiles, collection.length)
+
+ # Async
+ tasks = new balUtil.Group (err) ->
+ return next(err) if err
+ # After
+ docpad.emitSync 'cleanAfter', {collection}, (err) ->
+ return next(err) if err
+ docpad.log 'debug', util.format(locale.cleanedFiles, collection.length)
+ return next()
+
+ # Set progress indicator
+ opts.setProgressIndicator? -> ['cleanFiles',tasks.completed,tasks.total]
+
+ # Cycle
+ collection.forEach (file,index) -> tasks.push (complete) ->
+ file.clean(complete)
+
+ # Start writing
+ if tasks.total
+ docpad.emitSync 'cleanBefore', {collection}, (err) =>
+ return next(err) if err
+ tasks.async()
+ else
+ tasks.exit()
+
+ # Chain
+ @
+
# =================================
# Actions
@@ -2420,10 +2460,10 @@ class DocPad extends EventEmitterEnhanced
# Chain
@
- # Generate Clean
+ # Generate Reset
# opts = {}
# next(err)
- generateClean: (opts,next) =>
+ generateReset: (opts,next) =>
# Prepare
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
docpad = @
@@ -2502,7 +2542,7 @@ class DocPad extends EventEmitterEnhanced
# Contextualize the datbaase, perform two render passes, and perform a write
balUtil.flow(
object: docpad
- action: 'contextualizeFiles renderFiles renderFiles writeFiles'
+ action: 'contextualizeFiles renderFiles renderFiles writeFiles cleanFiles'
args: [{collection,templateData,setProgressIndicator}]
next: (err) ->
return next(err)
@@ -2630,7 +2670,7 @@ class DocPad extends EventEmitterEnhanced
docpad.lastGenerate = new Date()
balUtil.flow(
object: docpad
- action: 'generatePrepare generateCheck generateClean generateParse generateRender generatePostpare'
+ action: 'generatePrepare generateCheck generateReset generateParse generateRender generatePostpare'
args: [opts]
next: (err) ->
return finish(err)
@@ -2651,8 +2691,8 @@ class DocPad extends EventEmitterEnhanced
action: 'load contextualize render'
args: [opts]
next: (err) ->
- result = document.get('contentRendered')
- return next(err,result,document)
+ document.getOutContent (err,result) ->
+ return next(err,result,document)
)
@
@@ -2700,8 +2740,8 @@ class DocPad extends EventEmitterEnhanced
action: 'normalize contextualize render'
args: [opts]
next: (err) ->
- result = document.get('contentRendered')
- return next(err,result,document)
+ document.getOutContent (err,result) ->
+ return next(err,result,document)
)
@
@@ -2995,6 +3035,9 @@ class DocPad extends EventEmitterEnhanced
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
{document,err,req,res} = opts
docpad = @
+ error = (err) ->
+ docpad.error(err)
+ return next(err)
# If no document, then exit early
unless document
@@ -3013,27 +3056,26 @@ class DocPad extends EventEmitterEnhanced
templateData = balUtil.extend({}, req.templateData or {}, {req,err})
templateData = docpad.getTemplateData(templateData)
document.render {templateData}, (err) ->
- content = document.get('contentRendered') or document.get('content') or document.getData()
- if err
- docpad.error(err)
- return next(err)
- else
+ return error(err) if err
+ document.getOutContent (err,content) ->
+ return error(err) if err
if opts.statusCode?
return res.send(opts.statusCode, content)
else
return res.send(content)
else
- content = document.get('contentRendered') or document.get('content') or document.getData()
- if content
- if opts.statusCode?
- return res.send(opts.statusCode, content)
- else
- return res.send(content)
- else
- if opts.statusCode?
- return res.send(opts.statusCode)
+ document.getOutContent (err,content) ->
+ return error(err) if err
+ if content
+ if opts.statusCode?
+ return res.send(opts.statusCode, content)
+ else
+ return res.send(content)
else
- return next()
+ if opts.statusCode?
+ return res.send(opts.statusCode)
+ else
+ return next()
# Chain
@
@@ -42,6 +42,12 @@ class ConsoleInterface
'-f, --force'
locale.consoleOptionForce
)
+ ###
+ .option(
+ '--profile'
+ locale.consoleOptionProfile
+ )
+ ###
# -----------------------------
# Commands
@@ -55,7 +55,7 @@ class DocumentModel extends FileModel
rendered: false
# The rendered content (after it has been wrapped in the layouts)
- contentRendered: false
+ contentRendered: null
# The rendered content (before being passed through the layouts)
contentRenderedWithoutLayouts: null
@@ -80,7 +80,7 @@ class DocumentModel extends FileModel
# Initialize
initialize: (attrs,opts) ->
# Prepare
- {@layouts,meta} = opts
+ {meta} = opts
# Forward
super
@@ -89,6 +89,31 @@ class DocumentModel extends FileModel
getMeta: ->
return @meta
+ # Prepare
+ getOutContent: (next) ->
+ outContent = @get('contentRendered')
+ if outContent
+ next(null,outContent)
+ else
+ @getContent(next)
+ @
+
+ # Clean
+ # Wipe any unnecessary data
+ clean: (next) ->
+ ###
+ @set({
+ header: null
+ parser: null
+ body: null
+ rendered: false
+ contentRendered: null
+ contentRenderedWithoutLayouts: null
+ })
+ ###
+ super
+ @
+
# To JSON
toJSON: ->
data = super
@@ -101,11 +126,13 @@ class DocumentModel extends FileModel
@set({referencesOthers:flag})
@
- # Parse data
- # Parses some data, and loads the meta data and content from it
+ # Parse
+ # Parse our buffer and extract meaningful data from it
# next(err)
- parseData: (data,next) ->
+ parse: (opts={},next) ->
# Prepare
+ {opts,next} = @getActionArgs(opts,next)
+ buffer = @buffer
meta = @getMeta()
# Wipe any meta attributes that we've copied over to our file
@@ -121,7 +148,7 @@ class DocumentModel extends FileModel
# Reparse the data and extract the content
# With the content, fetch the new meta data, header, and body
- super data, =>
+ super buffer, =>
# Content
content = @get('content')
@@ -187,30 +214,34 @@ class DocumentModel extends FileModel
# Next
next()
+
+ # Chain
@
# Write the rendered file
# next(err)
writeRendered: (next) ->
# Prepare
file = @
- fileOutPath = @get('outPath')
- contentRendered = @get('contentRendered')
- encoding = @get('encoding')
-
- # Log
- file.log 'debug', "Writing the rendered file: #{fileOutPath} #{encoding}"
-
- # Write data
- balUtil.writeFile fileOutPath, contentRendered, (err) ->
- # Check
+ @getOutContent (err,contentRendered) =>
+ # Prepare
return next(err) if err
+ fileOutPath = @get('outPath')
+ encoding = @get('encoding')
# Log
- file.log 'debug', "Wrote the rendered file: #{fileOutPath} #{encoding}"
+ file.log 'debug', "Writing the rendered file: #{fileOutPath} #{encoding}"
- # Next
- return next()
+ # Write data
+ balUtil.writeFile fileOutPath, contentRendered, (err) ->
+ # Check
+ return next(err) if err
+
+ # Log
+ file.log 'debug', "Wrote the rendered file: #{fileOutPath} #{encoding}"
+
+ # Next
+ return next()
# Chain
@
@@ -223,32 +254,35 @@ class DocumentModel extends FileModel
CSON = require('cson') unless CSON
# Fetch
- fullPath = @get('fullPath')
- content = @get('content')
- parser = 'cson'
- seperator = '---'
+ @getContent (err,content) =>
+ # Prepare
+ return next(err) if err
+ fullPath = @get('fullPath')
+ content = @get('content')
+ parser = 'cson'
+ seperator = '---'
- # Log
- file.log 'debug', "Writing the source file: #{fullPath}"
+ # Log
+ file.log 'debug', "Writing the source file: #{fullPath}"
- # Adjust
- header = CSON.stringifySync(@meta.toJSON())
- content = body = content.replace(/^\s+/,'')
- source = "#{seperator} #{parser}\n#{header}\n#{seperator}\n\n#{body}"
+ # Adjust
+ header = CSON.stringifySync(@meta.toJSON())
+ content = body = content.replace(/^\s+/,'')
+ source = "#{seperator} #{parser}\n#{header}\n#{seperator}\n\n#{body}"
- # Apply
- @set({parser,header,body,content,source})
+ # Apply
+ @set({parser,header,body,content,source})
- # Write content
- balUtil.writeFile fileOutPath, source, (err) ->
- # Check
- return next(err) if err
+ # Write content
+ balUtil.writeFile fileOutPath, source, (err) ->
+ # Check
+ return next(err) if err
- # Log
- file.log 'info', "Wrote the source file: #{fullPath}"
+ # Log
+ file.log 'info', "Wrote the source file: #{fullPath}"
- # Next
- next()
+ # Next
+ next()
# Chain
@
Oops, something went wrong.

0 comments on commit b9a2f36

Please sign in to comment.