Permalink
Browse files

Added an API test file. Updated attribute fixtures for rendered -> ou…

…t property renames.
  • Loading branch information...
1 parent 579e951 commit d5f45aaefaf58ddba6f7c6e32b0993dd867ae03d @balupton balupton committed Aug 10, 2012
View
@@ -2202,31 +2202,35 @@ class DocPad extends EventEmitterEnhanced
# Render Path
# next(err,result)
renderPath: (path,opts,next) ->
- document = @ensureDocument(
+ attributes = balUtil.extend({
fullPath: path
- )
+ },opts.attributes)
+ document = @ensureDocument(attributes)
@loadAndRenderDocument(document,opts,next)
@
# Render Data
# next(err,result)
renderData: (content,opts,next) ->
- document = @createDocument(
+ attributes = balUtil.extend({
filename: opts.filename
data: content
- )
+ },opts.attributes)
+ document = @createDocument(attributes)
@loadAndRenderDocument(document,opts,next)
@
# Render Text
+ # Doesn't extract meta information, or render layouts
# next(err,result)
renderText: (text,opts,next) ->
- document = @createDocument(
+ attributes = balUtil.extend({
filename: opts.filename
data: text
body: text
content: text
- )
+ },opts.attributes)
+ document = @createDocument(attributes)
opts.actions ?= ['renderExtensions','renderDocument']
balUtil.flow(
object: document
@@ -0,0 +1,89 @@
+# RequirestestServer
+balUtil = require('bal-util')
+chai = require('chai')
+expect = chai.expect
+joe = require('joe')
+_ = require('underscore')
+
+# -------------------------------------
+# Configuration
+
+# Vars
+docpadPath = __dirname+'/../..'
+rootPath = docpadPath+'/test'
+renderPath = rootPath+'/render'
+expectPath = rootPath+'/render-expected'
+cliPath = docpadPath+'/bin/docpad'
+
+# Configure DocPad
+docpadConfig =
+ growl: false
+ port: 9780
+ rootPath: rootPath
+ logLevel: if process.env.TRAVIS_NODE_VERSION? then 7 else 5
+ skipUnsupportedPlugins: false
+ catchExceptions: false
+ environments:
+ development:
+ a: 'instanceConfig'
+ b: 'instanceConfig'
+ templateData:
+ a: 'instanceConfig'
+ b: 'instanceConfig'
+
+# Fail on an uncaught error
+process.on 'uncaughtException', (err) ->
+ throw err
+
+# Local globals
+docpad = null
+logger = null
+
+# -------------------------------------
+# Tests
+
+joe.suite 'docpad-api', (suite,test) ->
+
+ # Create a DocPad Instance
+ test 'createInstance', (done) ->
+ docpad = require(__dirname+'/../main').createInstance(docpadConfig,done)
+
+ # Render some input
+ suite 'render', (suite,test) ->
+ # Check rendering stdin inputs
+ inputs = [
+ {
+ testname: 'markdown without extension'
+ filename: ''
+ stdin: '*awesome*'
+ stdout: '*awesome*'
+ }
+ {
+ testname: 'markdown with extension'
+ filename: 'markdown'
+ stdin: '*awesome*'
+ stdout: '<p><em>awesome</em></p>'
+ }
+ {
+ testname: 'markdown with extensions'
+ filename: '.html.md'
+ stdin: '*awesome*'
+ stdout: '<p><em>awesome</em></p>'
+ }
+ {
+ testname: 'markdown with filename'
+ filename: 'example.html.md'
+ stdin: '*awesome*'
+ stdout: '<p><em>awesome</em></p>'
+ }
+ ]
+ balUtil.each inputs, (input) ->
+ test input.testname, (done) ->
+ opts =
+ data: input.stdin
+ filename: input.filename
+ renderSingleExtensions: true
+ docpad.action 'render', opts, (err,result) ->
+ return done(err) if err
+ expect(result).to.equal(input.stdout)
+ done()
@@ -1,3 +1,4 @@
# Tests
require(__dirname+'/render.test')
+require(__dirname+'/api.test')
require(__dirname+'/actions.test')
@@ -1,24 +1,24 @@
{ basename: 'attributes-nolayout',
body: '# Fetch data\nattrs = @getDocument().getAttributes()\n\n# Delete environment specific variables\ndelete attrs.ctime\ndelete attrs.mtime\ndelete attrs.date\ndelete attrs.fullPath\ndelete attrs.fullDirPath\ndelete attrs.outPath\ndelete attrs.outDirPath\ndelete attrs.data\n\n# Sort the attributes\nkeys = []\nkeys.push(key) for own key,value of attrs\nkeys.sort()\nsortedAttrs = {}\nfor key in keys\n sortedAttrs[key] = attrs[key]\n\n# Output data\ntext @require(\'util\').inspect(sortedAttrs)',
content: '# Fetch data\nattrs = @getDocument().getAttributes()\n\n# Delete environment specific variables\ndelete attrs.ctime\ndelete attrs.mtime\ndelete attrs.date\ndelete attrs.fullPath\ndelete attrs.fullDirPath\ndelete attrs.outPath\ndelete attrs.outDirPath\ndelete attrs.data\n\n# Sort the attributes\nkeys = []\nkeys.push(key) for own key,value of attrs\nkeys.sort()\nsortedAttrs = {}\nfor key in keys\n sortedAttrs[key] = attrs[key]\n\n# Output data\ntext @require(\'util\').inspect(sortedAttrs)',
- contentRendered: '{ basename: \'attributes-nolayout\',\n body: \'# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n content: \'# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n contentRendered: false,\n contentRenderedWithoutLayouts: null,\n contentType: \'application/octet-stream\',\n contentTypeRendered: \'text/plain\',\n dynamic: false,\n encoding: \'utf8\',\n extension: \'coffee\',\n extensionRendered: \'txt\',\n extensions: [ \'txt\', \'coffee\' ],\n filename: \'attributes-nolayout.txt.coffee\',\n filenameRendered: \'attributes-nolayout.txt\',\n header: \'title: \\\'Attributes No Layout\\\'\\ntags: [\\\'attributes\\\',\\\'with-layout\\\']\\n\',\n id: \'attributes-nolayout.txt.coffee\',\n isDocument: true,\n meta: \n { title: \'Attributes No Layout\',\n tags: [ \'attributes\', \'with-layout\' ] },\n name: \'attributes-nolayout.txt\',\n parser: \'yaml\',\n referencesOthers: false,\n relativeBase: \'attributes-nolayout\',\n relativeDirPath: \'\',\n relativeOutDirPath: \'\',\n relativeOutPath: \'attributes-nolayout.txt\',\n relativePath: \'attributes-nolayout.txt.coffee\',\n render: true,\n renderSingleExtensions: false,\n rendered: false,\n slug: \'attributes-nolayout\',\n source: \'---\\ntitle: \\\'Attributes No Layout\\\'\\ntags: [\\\'attributes\\\',\\\'with-layout\\\']\\n---\\n\\n# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n tags: [ \'attributes\', \'with-layout\' ],\n title: \'Attributes No Layout\',\n url: \'/attributes-nolayout.txt\',\n urls: [ \'/attributes-nolayout.txt\' ],\n write: true }',
- contentRenderedWithoutLayouts: '{ basename: \'attributes-nolayout\',\n body: \'# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n content: \'# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n contentRendered: false,\n contentRenderedWithoutLayouts: null,\n contentType: \'application/octet-stream\',\n contentTypeRendered: \'text/plain\',\n dynamic: false,\n encoding: \'utf8\',\n extension: \'coffee\',\n extensionRendered: \'txt\',\n extensions: [ \'txt\', \'coffee\' ],\n filename: \'attributes-nolayout.txt.coffee\',\n filenameRendered: \'attributes-nolayout.txt\',\n header: \'title: \\\'Attributes No Layout\\\'\\ntags: [\\\'attributes\\\',\\\'with-layout\\\']\\n\',\n id: \'attributes-nolayout.txt.coffee\',\n isDocument: true,\n meta: \n { title: \'Attributes No Layout\',\n tags: [ \'attributes\', \'with-layout\' ] },\n name: \'attributes-nolayout.txt\',\n parser: \'yaml\',\n referencesOthers: false,\n relativeBase: \'attributes-nolayout\',\n relativeDirPath: \'\',\n relativeOutDirPath: \'\',\n relativeOutPath: \'attributes-nolayout.txt\',\n relativePath: \'attributes-nolayout.txt.coffee\',\n render: true,\n renderSingleExtensions: false,\n rendered: false,\n slug: \'attributes-nolayout\',\n source: \'---\\ntitle: \\\'Attributes No Layout\\\'\\ntags: [\\\'attributes\\\',\\\'with-layout\\\']\\n---\\n\\n# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n tags: [ \'attributes\', \'with-layout\' ],\n title: \'Attributes No Layout\',\n url: \'/attributes-nolayout.txt\',\n urls: [ \'/attributes-nolayout.txt\' ],\n write: true }',
+ contentRendered: '{ basename: \'attributes-nolayout\',\n body: \'# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n content: \'# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n contentRendered: false,\n contentRenderedWithoutLayouts: null,\n contentType: \'application/octet-stream\',\n dynamic: false,\n encoding: \'utf8\',\n extension: \'coffee\',\n extensions: [ \'txt\', \'coffee\' ],\n filename: \'attributes-nolayout.txt.coffee\',\n header: \'title: \\\'Attributes No Layout\\\'\\ntags: [\\\'attributes\\\',\\\'with-layout\\\']\\n\',\n id: \'attributes-nolayout.txt.coffee\',\n isDocument: true,\n meta: \n { title: \'Attributes No Layout\',\n tags: [ \'attributes\', \'with-layout\' ] },\n name: \'attributes-nolayout.txt\',\n outContentType: \'text/plain\',\n outExtension: \'txt\',\n outFilename: \'attributes-nolayout.txt\',\n parser: \'yaml\',\n referencesOthers: false,\n relativeBase: \'attributes-nolayout\',\n relativeDirPath: \'\',\n relativeOutDirPath: \'\',\n relativeOutPath: \'attributes-nolayout.txt\',\n relativePath: \'attributes-nolayout.txt.coffee\',\n render: true,\n renderSingleExtensions: false,\n rendered: false,\n slug: \'attributes-nolayout\',\n source: \'---\\ntitle: \\\'Attributes No Layout\\\'\\ntags: [\\\'attributes\\\',\\\'with-layout\\\']\\n---\\n\\n# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n tags: [ \'attributes\', \'with-layout\' ],\n title: \'Attributes No Layout\',\n url: \'/attributes-nolayout.txt\',\n urls: [ \'/attributes-nolayout.txt\' ],\n write: true }',
+ contentRenderedWithoutLayouts: '{ basename: \'attributes-nolayout\',\n body: \'# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n content: \'# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n contentRendered: false,\n contentRenderedWithoutLayouts: null,\n contentType: \'application/octet-stream\',\n dynamic: false,\n encoding: \'utf8\',\n extension: \'coffee\',\n extensions: [ \'txt\', \'coffee\' ],\n filename: \'attributes-nolayout.txt.coffee\',\n header: \'title: \\\'Attributes No Layout\\\'\\ntags: [\\\'attributes\\\',\\\'with-layout\\\']\\n\',\n id: \'attributes-nolayout.txt.coffee\',\n isDocument: true,\n meta: \n { title: \'Attributes No Layout\',\n tags: [ \'attributes\', \'with-layout\' ] },\n name: \'attributes-nolayout.txt\',\n outContentType: \'text/plain\',\n outExtension: \'txt\',\n outFilename: \'attributes-nolayout.txt\',\n parser: \'yaml\',\n referencesOthers: false,\n relativeBase: \'attributes-nolayout\',\n relativeDirPath: \'\',\n relativeOutDirPath: \'\',\n relativeOutPath: \'attributes-nolayout.txt\',\n relativePath: \'attributes-nolayout.txt.coffee\',\n render: true,\n renderSingleExtensions: false,\n rendered: false,\n slug: \'attributes-nolayout\',\n source: \'---\\ntitle: \\\'Attributes No Layout\\\'\\ntags: [\\\'attributes\\\',\\\'with-layout\\\']\\n---\\n\\n# Fetch data\\nattrs = @getDocument().getAttributes()\\n\\n# Delete environment specific variables\\ndelete attrs.ctime\\ndelete attrs.mtime\\ndelete attrs.date\\ndelete attrs.fullPath\\ndelete attrs.fullDirPath\\ndelete attrs.outPath\\ndelete attrs.outDirPath\\ndelete attrs.data\\n\\n# Sort the attributes\\nkeys = []\\nkeys.push(key) for own key,value of attrs\\nkeys.sort()\\nsortedAttrs = {}\\nfor key in keys\\n sortedAttrs[key] = attrs[key]\\n\\n# Output data\\ntext @require(\\\'util\\\').inspect(sortedAttrs)\',\n tags: [ \'attributes\', \'with-layout\' ],\n title: \'Attributes No Layout\',\n url: \'/attributes-nolayout.txt\',\n urls: [ \'/attributes-nolayout.txt\' ],\n write: true }',
contentType: 'application/octet-stream',
- contentTypeRendered: 'text/plain',
dynamic: false,
encoding: 'utf8',
extension: 'coffee',
- extensionRendered: 'txt',
extensions: [ 'txt', 'coffee' ],
filename: 'attributes-nolayout.txt.coffee',
- filenameRendered: 'attributes-nolayout.txt',
header: 'title: \'Attributes No Layout\'\ntags: [\'attributes\',\'with-layout\']\n',
id: 'attributes-nolayout.txt.coffee',
isDocument: true,
meta:
{ title: 'Attributes No Layout',
tags: [ 'attributes', 'with-layout' ] },
name: 'attributes-nolayout.txt',
+ outContentType: 'text/plain',
+ outExtension: 'txt',
+ outFilename: 'attributes-nolayout.txt',
parser: 'yaml',
referencesOthers: false,
relativeBase: 'attributes-nolayout',
Oops, something went wrong.

0 comments on commit d5f45aa

Please sign in to comment.