Skip to content

Commit

Permalink
Pushing the versions of the cachr and partials plugins that work with…
Browse files Browse the repository at this point in the history
… docpad 5.2. I suspect cachr is just whitespace, partials did have to get some changes done.
  • Loading branch information
balupton committed May 4, 2012
1 parent 1d6b5d6 commit 3bec8c4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
14 changes: 9 additions & 5 deletions plugins/cachr/cachr.plugin.coffee
Expand Up @@ -110,7 +110,7 @@ module.exports = (BasePlugin) ->
cachr = @
@urlsToCache = {}
@urlsToCacheLength = 0

# Apply
templateData.cachr = (sourceUrl) ->
return cachr.queueRemoteUrlSync(sourceUrl)
Expand All @@ -128,6 +128,7 @@ module.exports = (BasePlugin) ->
# Prepare
cachr = @
docpad = @docpad
logger = @docpad.logger
config = @config
urlsToCache = @urlsToCache
urlsToCacheLength = @urlsToCacheLength
Expand All @@ -138,25 +139,28 @@ module.exports = (BasePlugin) ->
unless urlsToCacheLength
return next?()

# Log
logger.log 'info', 'Cachr started caching...', (if failures then "with #{failures} failures" else '')

# Ensure Path
balUtil.ensurePath cachrPath, (err) ->
# Check
return next?(err) if err

# Async
tasks = new balUtil.Group (err) =>
docpad.logger.log (if failures then 'warn' else 'info'), 'Cachr finished caching everything', (if failures then "with #{failures} failures" else '')
logger.log (if failures then 'warn' else 'info'), 'Cachr finished caching', (if failures then "with #{failures} failures" else '')

# Store all our files to be cached
balUtil.each urlsToCache, (details,sourceUrl) ->
tasks.push (complete) ->
cachr.cacheRemoteUrl details, (err) ->
if err
docpad.logger.log 'warn', "Cachr failed to fetch [#{sourceUrl}]"
docpad.logger.log 'warn', "Cachr failed to fetch: #{sourceUrl}"
docpad.error(err)
++failures
return complete()

# Fire the tasks together
tasks.async()

Expand Down
48 changes: 29 additions & 19 deletions plugins/partials/partials.plugin.coffee
Expand Up @@ -13,8 +13,8 @@ module.exports = (BasePlugin) ->
config:
partialsPath: 'partials'

# A list of all the partials to render
partialsToRender: null # Object
# A list of all the partials we've discovered
foundPartials: null # Object

# Prepare our Configuration
constructor: ->
Expand All @@ -33,7 +33,7 @@ module.exports = (BasePlugin) ->
# Render Partial Sync
# Mapped to templateData.partial
# Takes in a partialId and it's data and returns a temporary container
# which will be replaced later when we've finished rendering our partial
# which will be replaced later when we've finished rendering our partial
renderPartialSync: (name,data) ->
# Prepare
config = @config
Expand All @@ -48,7 +48,7 @@ module.exports = (BasePlugin) ->
container: "[partial:#{id}]"

# Store it for later
@partialsToRender[id] = partial
@foundPartials[id] = partial

# Return the partial's container
return partial.container
Expand All @@ -60,10 +60,11 @@ module.exports = (BasePlugin) ->
renderPartial: (partial,next) ->
# Prepare
docpad = @docpad

# Render
document = docpad.createPartial()
document = docpad.createDocument()
document.set(
partialId: partial.id
filename: partial.name
fullPath: partial.path
)
Expand All @@ -83,8 +84,8 @@ module.exports = (BasePlugin) ->
renderBefore: ({templateData}, next) ->
# Prepare
me = @
@partialsToRender = {}
@foundPartials = {}

# Apply
templateData.partial = (name,data) ->
return me.renderPartialSync(name,data)
Expand All @@ -105,34 +106,43 @@ module.exports = (BasePlugin) ->
# Prepare
me = @
docpad = @docpad
logger = @docpad.logger
config = @config
partialsToRender = @partialsToRender

# Ensure we are a document
return next?() if file.type is 'partial'
foundPartials = @foundPartials

# Async
tasks = new balUtil.Group (err) ->
# Forward
return next(err)

# Store all our files to be cached
balUtil.each partialsToRender, (partial) ->
balUtil.each foundPartials, (partial) ->
tasks.push (complete) ->
docpad.logger.log 'debug', "Partials rendering [#{partial.name}]"
# Check if we use this partial
# if we don't, then skip this partial
return complete() if opts.content.indexOf(partial.container) is -1

# Log
logger.log 'debug', "Rendering partial: #{partial.name}"

# Render
me.renderPartial partial, (err,contentRendered) ->
# Check
if err
docpad.logger.log 'warn', "Partials failed to render [#{partial.name}]"
docpad.error(err)
# Warn
docpad.warn("Rendering partial failed: #{partial.name}. The error follows:", err)

# Replace container with the rendered content
else
# Log
logger.log 'debug', "Rendered partial: #{partial.name}"

# Apply
opts.content = opts.content.replace(partial.container,contentRendered)

# Done
return complete()

# Fire the tasks together
tasks.async()

Expand Down

0 comments on commit 3bec8c4

Please sign in to comment.