Skip to content

Commit

Permalink
upgrade to latest spike version
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalan committed Aug 17, 2016
1 parent 616a44a commit 6fbe7d2
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 21 deletions.
17 changes: 9 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const rest = require('rest')
const fs = require('fs')
const path = require('path')
const R = require('ramda')
const posthtml = require('posthtml')
const reshape = require('reshape')
const mkdirp = require('mkdirp')
const loader = require('posthtml-loader')
const loader = require('reshape-loader')

// this needs to be a function that returns a function
module.exports = class Records {
Expand Down Expand Up @@ -81,16 +81,17 @@ function writeTemplates (compiler, _data, k) {
filename: path.join(root, tpl.path)
})

const options = loader.parseOptions(compiler.options.posthtml, {})
const outPath = path.join(publicPath, tpl.output(item))
const mockContext = { resourcePath: outPath, addDependency: (x) => x }
const options = loader.parseOptions.call(mockContext, compiler.options.reshape, {})

return posthtml(options.plugins)
return reshape(options)
.process(template)
.then((r) => r.html)
.then((rendered) => {
const outPath = path.join(publicPath, tpl.output(item))
.then(((locals, res) => {
const rendered = res.output(locals)
mkdirp.sync(path.dirname(outPath))
return node.call(fs.writeFile.bind(fs), outPath, rendered)
})
}).bind(null, Object.assign({}, options.locals)))
})
})
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"dependencies": {
"jade": "^1.11.0",
"mkdirp": "^0.5.1",
"ramda": "^0.22.0",
"ramda": "^0.22.1",
"reshape": "^0.3.0",
"reshape-loader": "^0.2.2",
"rest": "^2.0.0",
"when": "^3.7.7"
},
"devDependencies": {
"ava": "^0.16.0",
"coveralls": "^2.11.11",
"nyc": "^8.0.0",
"coveralls": "^2.11.12",
"nyc": "^8.1.0",
"posthtml-exp": "^0.9.0",
"rimraf": "^2.5.4",
"spike-core": "^0.10.0",
"spike-core": "^0.11.1",
"spike-html-standards": "^0.2.1",
"standard": "^7.1.2"
},
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/data/index.html

This file was deleted.

1 change: 1 addition & 0 deletions test/fixtures/data/index.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p {{ test.result }}
1 change: 0 additions & 1 deletion test/fixtures/template/index.html

This file was deleted.

1 change: 1 addition & 0 deletions test/fixtures/template/index.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p {{ posts.length }}
1 change: 0 additions & 1 deletion test/fixtures/template/template.html

This file was deleted.

1 change: 1 addition & 0 deletions test/fixtures/template/template.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p {{ item.title }}
13 changes: 7 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path')
const fs = require('fs')
const Records = require('..')
const rimraf = require('rimraf')
const exp = require('posthtml-exp')
const htmlStandards = require('spike-html-standards')

const fixturesPath = path.join(__dirname, 'fixtures')

Expand Down Expand Up @@ -145,7 +145,7 @@ test.cb('single template works with "path" and "template" params', (t) => {
posts: {
data: [{ title: 'wow' }, { title: 'amaze' }],
template: {
path: 'template.html',
path: 'template.sml',
output: (item) => `posts/${item.title}.html`
}
}
Expand Down Expand Up @@ -174,7 +174,7 @@ test.cb('single template works with "transform" param', (t) => {
data: { response: [{ title: 'wow' }, { title: 'amaze' }] },
template: {
transform: (data) => data.response,
path: 'template.html',
path: 'template.sml',
output: (item) => `posts/${item.title}.html`
}
}
Expand All @@ -183,7 +183,7 @@ test.cb('single template works with "transform" param', (t) => {
const index = fs.readFileSync(path.join(publicPath, 'index.html'), 'utf8')
const wow = fs.readFileSync(path.join(publicPath, 'posts/wow.html'), 'utf8')
const amaze = fs.readFileSync(path.join(publicPath, 'posts/amaze.html'), 'utf8')
t.is(index.trim(), '<p></p>') // bc the transform is not global
t.is(index.trim(), '<p>undefined</p>') // bc the transform is not global
t.is(wow.trim(), '<p>wow</p>')
t.is(amaze.trim(), '<p>amaze</p>')
cb()
Expand All @@ -200,8 +200,9 @@ function configProject (fixturePath, recordsConfig, locals) {
const project = new Spike({
root: projectPath,
entry: { main: [path.join(projectPath, 'app.js')] },
posthtml: { plugins: [exp({ locals })] },
ignore: ['template.html'],
matchers: { html: '**/*.sml' },
reshape: (ctx) => htmlStandards({ webpack: ctx, locals }),
ignore: ['template.sml'],
plugins: [new Records(recordsConfig)]
})
return { projectPath: projectPath, project: project }
Expand Down

0 comments on commit 6fbe7d2

Please sign in to comment.