Skip to content

Commit

Permalink
v6.21.0. Improvement. Bugfix.
Browse files Browse the repository at this point in the history
- v6.21.0 January 2, 2013
	- Cleanup focused around loading, parsing, and writing of files and
documents
	- Added
		- `DocPad::flowDocument`
		- `DocPad::loadDocument`
		- `exists` attribute on `File` model
	- Fixed
		- `Document::writeSource`
  • Loading branch information
balupton committed Jan 2, 2013
1 parent 0c7b187 commit 97e7659
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 60 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -4,7 +4,7 @@
## Support

1. Use the GitHub Issues only for development tasks and bug reports
1. For anything else (questions, support, etc) use our [Official Support Channels](http://bevry.me/support)
1. For anything else (questions, support, etc) use our [Official Support Channels](http://docpad.org/support)
1. With bug reports, be sure to specify:
1. Your docpad version `docpad --version`
1. Your node version `node --version`
Expand Down
8 changes: 8 additions & 0 deletions History.md
@@ -1,5 +1,13 @@
## History

- v6.21.0 January 2, 2013
- Cleanup focused around loading, parsing, and writing of files and documents
- Added
- `DocPad::flowDocument`
- `DocPad::loadDocument`
- `exists` attribute on `File` model
- Fixed `Document::writeSource`

- v6.20.1 December 24, 2012
- Fixed `File::writeSource`
- Thanks to [ashnur](https://github.com/ashnur) for [pull request #381](https://github.com/bevry/docpad/pull/381)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
@@ -1,6 +1,6 @@
(The MIT License)

Copyright (c) 2012 Bevry Pty Ltd <us@bevry.me>
Copyright (c) 2012+ Bevry Pty Ltd <us@bevry.me>
Copyright (c) 2011 Benjamin Lupton <b@lupton.cc>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -91,7 +91,7 @@ You can discover the version history inside the [History.md](https://github.com/
## License

Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT License](http://creativecommons.org/licenses/MIT/)
<br/>Copyright &copy; 2012 [Bevry Pty Ltd](http://bevry.me)
<br/>Copyright &copy; 2012+ [Bevry Pty Ltd](http://bevry.me)
<br/>Copyright &copy; 2011 [Benjamin Lupton](http://balupton.com)


Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "docpad",
"version": "6.20.1",
"version": "6.21.0",
"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",
"installUrl": "http://docpad.org/install",
Expand Down
81 changes: 71 additions & 10 deletions src/lib/docpad.coffee
Expand Up @@ -1383,7 +1383,7 @@ class DocPad extends EventEmitterEnhanced
})
.on('add', (model) ->
docpad.log('debug', util.format(locale.addingDocument, model.attributes.fullPath))
_.defaults(model.attributes,{
model.setDefaults({
isDocument: true
render: true
write: true
Expand All @@ -1397,7 +1397,7 @@ class DocPad extends EventEmitterEnhanced
})
.on('add', (model) ->
docpad.log('debug', util.format(locale.addingFile, model.attributes.fullPath))
_.defaults(model.attributes,{
model.setDefaults({
isFile: true
render: false
write: true
Expand All @@ -1411,7 +1411,7 @@ class DocPad extends EventEmitterEnhanced
})
.on('add', (model) ->
docpad.log('debug', util.format(locale.addingLayout, model.attributes.fullPath))
_.defaults(model.attributes,{
model.setDefaults({
isLayout: true
render: false
write: false
Expand Down Expand Up @@ -1443,7 +1443,9 @@ class DocPad extends EventEmitterEnhanced
})
.on('add', (model) ->
docpad.log('debug', util.format(locale.addingStylesheet, model.attributes.fullPath))
model.attributes.referencesOthers = true
model.setDefaults({
referencesOthers: true
})
)
)

Expand Down Expand Up @@ -2701,58 +2703,115 @@ class DocPad extends EventEmitterEnhanced
# ---------------------------------
# Render

# Load and Render a Document
# Flow through a Document
# next(err,document)
loadAndRenderDocument: (document,opts,next) ->
flowDocument: (document,opts,next) ->
# Prepare
[opts,next] = balUtil.extractOptsAndCallback(opts,next)

# Flow
balUtil.flow(
object: document
action: 'load contextualize render'
action: opts.action
args: [opts]
next: (err) ->
result = document.getOutContent()
return next(err,result,document)
return next?(err,document)
)

# Chain
@

# Load a Document
# next(err,document)
loadDocument: (document,opts,next) ->
# Prepare
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
opts.action or= 'load contextualize'

# Flow
@flowDocument(document, opts, next)

# Chain
@

# Load and Render a Document
# next(err,document)
loadAndRenderDocument: (document,opts,next) ->
# Prepare
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
opts.action or= 'load contextualize render'

# Flow
@flowDocument document, opts, (err) ->
result = document.getOutContent()
return next?(err,result,document)

# Chain
@

# Render Document
# next(err,result)
renderDocument: (document,opts,next) ->
# Prepare
[opts,next] = balUtil.extractOptsAndCallback(opts,next)

# Render
document.render(opts,next)

# Chain
@

# Render Path
# next(err,result)
renderPath: (path,opts,next) ->
# Prepare
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
attributes = balUtil.extend({
fullPath: path
},opts.attributes)

# Handle
document = @ensureDocument(attributes)
@loadAndRenderDocument(document,opts,next)

# Chain
@

# Render Data
# next(err,result)
renderData: (content,opts,next) ->
# Prepare
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
attributes = balUtil.extend({
filename: opts.filename
data: content
},opts.attributes)

# Handle
document = @createDocument(attributes)
@loadAndRenderDocument(document,opts,next)

# Chain
@

# Render Text
# Doesn't extract meta information, or render layouts
# next(err,result)
renderText: (text,opts,next) ->
# Prepare
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
opts.actions ?= ['renderExtensions','renderDocument']
attributes = balUtil.extend({
filename: opts.filename
data: text
body: text
content: text
},opts.attributes)

# Handle
document = @createDocument(attributes)
opts.actions ?= ['renderExtensions','renderDocument']

# Flow
balUtil.flow(
object: document
action: 'normalize contextualize render'
Expand All @@ -2761,6 +2820,8 @@ class DocPad extends EventEmitterEnhanced
result = document.getOutContent()
return next(err,result,document)
)

# Chain
@

# Render Action
Expand Down
32 changes: 19 additions & 13 deletions src/lib/models/document.coffee
Expand Up @@ -138,13 +138,13 @@ class DocumentModel extends FileModel
switch parser
when 'cson', 'coffee', 'coffeescript', 'coffee-script'
CSON = require('cson') unless CSON
meta = CSON.parseSync(header)
@meta.set(meta)
metaData = CSON.parseSync(header)
meta.set(metaData)

when 'yaml'
YAML = require('yamljs') unless YAML
meta = YAML.parse(header)
@meta.set(meta)
metaData = YAML.parse(header)
meta.set(metaData)

else
err = new Error("Unknown meta parser: #{parser}")
Expand All @@ -166,26 +166,28 @@ class DocumentModel extends FileModel
)

# Correct data format
metaDate = @meta.get('date')
metaDate = meta.get('date')
if metaDate
metaDate = new Date(metaDate)
@meta.set({date:metaDate})
meta.set({date:metaDate})

# Correct ignore
ignored = @meta.get('ignored') or @meta.get('ignore') or @meta.get('skip') or @meta.get('draft') or (@meta.get('published') is false)
@meta.set({ignored:true}) if ignored
ignored = meta.get('ignored') or meta.get('ignore') or meta.get('skip') or meta.get('draft') or (meta.get('published') is false)
meta.set({ignored:true}) if ignored

# Handle urls
metaUrls = @meta.get('urls')
metaUrl = @meta.get('url')
metaUrls = meta.get('urls')
metaUrl = meta.get('url')
@addUrl(metaUrls) if metaUrls
@addUrl(metaUrl) if metaUrl

# Apply meta to us
@set(@meta.toJSON())
@set(meta.toJSON())

# Next
next()

# Chain
@

# Normalize data
Expand Down Expand Up @@ -612,18 +614,22 @@ class DocumentModel extends FileModel
writeSource: (next) ->
# Prepare
file = @
meta = @getMeta()
CSON = require('cson') unless CSON

# Fetch
fullPath = @get('fullPath')
content = @get('content')
content = (@getContent() or '').toString()
parser = 'cson'
seperator = '---'

# Log
file.log 'debug', "Writing the source file: #{fullPath}"

# Adjust
header = CSON.stringifySync(@meta.toJSON())
metaData = meta.toJSON()
console.log({metaData})
header = CSON.stringifySync(metaData)
content = body = content.replace(/^\s+/,'')
source = "#{seperator} #{parser}\n#{header}\n#{seperator}\n\n#{body}"

Expand Down

0 comments on commit 97e7659

Please sign in to comment.