-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lazy caching, cwd and renameKey fixes
- Loading branch information
1 parent
9c5fe4f
commit 72d0ae3
Showing
21 changed files
with
392 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var App = require('..'); | ||
var app = new App(); | ||
|
||
app.collection('file', {type: 'files'}); | ||
// app.file('foo', {content: 'bar'}); | ||
|
||
// var foo = app.files.get('foo'); | ||
|
||
// console.log(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var green = require('ansi-green'); | ||
var success = require('success-symbol'); | ||
var App = require('..'); | ||
var app = new App(); | ||
|
||
app.engine('*', require('engine-lodash')); | ||
|
||
/** | ||
* Create | ||
*/ | ||
app.create('page'); | ||
|
||
|
||
/** | ||
* Load | ||
*/ | ||
app.pages('a', {path: 'a', content: 'aaa...'}); | ||
app.pages('b', {path: 'b', content: 'bbb...'}); | ||
app.pages('c', {path: 'c', content: 'ccc...'}); | ||
app.pages('d', {path: 'd', content: 'ddd...'}) | ||
|
||
|
||
var page = app.pages.get('a'); | ||
|
||
page.on('write', function (dest) { | ||
console.log(green(success), 'file written to', dest); | ||
}); | ||
|
||
page.on('render', function (dest) { | ||
console.log(green(success), 'file written to', dest); | ||
}); | ||
|
||
page.writeSync('test/actual/a.md'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var green = require('ansi-green'); | ||
var red = require('ansi-red'); | ||
var success = require('success-symbol'); | ||
var App = require('..'); | ||
var app = new App(); | ||
|
||
app.option({ | ||
mixins: { | ||
shout: function (str) { | ||
console.log(red(str.toUpperCase() + '!')); | ||
} | ||
} | ||
}); | ||
|
||
app.shout('hello'); | ||
//=> 'HELLO!' | ||
|
||
/** | ||
* Create | ||
*/ | ||
app.create('page'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var matter = require('parser-front-matter'); | ||
var App = require('..'); | ||
var app = new App(); | ||
|
||
|
||
/** | ||
* Need to get the frontmatter from the contents. | ||
*/ | ||
|
||
app.onLoad(/\.hbs$/, function (view, next) { | ||
matter.parse(view, next); | ||
}); | ||
|
||
|
||
/** | ||
* Define a template engine for rendering templates | ||
* in `.hbs` files | ||
*/ | ||
|
||
app.engine('hbs', require('engine-handlebars')); | ||
app.engine('md', require('engine-handlebars')); | ||
|
||
|
||
|
||
app.helper('pager', function(locals, options, cb) { | ||
locals = extend({modifier: ''}, locals, options.hash); | ||
|
||
var template = [ | ||
'<ul class="pager {{modifier}}">', | ||
' {{#is pagination.currentPage 1}}', | ||
' <li class="pager-heading">POPULAR</li>', | ||
' {{/is}}', | ||
' {{#isnt pagination.currentPage 1}}', | ||
' <li class="previous"><a href="{{relative page.dest prev.dest}}">← Previous</a></li>', | ||
' {{/isnt}}', | ||
' {{#isnt pagination.currentPage pagination.totalPages}}', | ||
' <li class="next"><a href="{{relative page.dest next.dest}}">Next →</a></li>', | ||
' {{/isnt}}', | ||
' {{#is pagination.currentPage pagination.totalPages}}', | ||
' <li class="next disabled"><a href="{{relative page.dest next.dest}}">Next →</a></li>', | ||
' {{/is}}', | ||
'</ul>' | ||
].join('\n'); | ||
|
||
this.app.render(template, locals, function (err, res) { | ||
if (err) return cb(err); | ||
|
||
return cb(null, res.content); | ||
}); | ||
}); | ||
|
||
/** | ||
* Create custom template types | ||
*/ | ||
|
||
app.create('page'); | ||
app.create('post', { permalinks: { structure: ':year/:month/:day/:key.html'} }); | ||
app.create('include', { viewType: 'partial' }); | ||
app.create('layout', { viewType: 'layout' }); | ||
|
||
/** | ||
* Create additional custom template type for index list pages. | ||
* Use custom loaders to generate index pages. | ||
* These are used just like pages, but provide the layout for a list of pages. | ||
*/ | ||
|
||
app.create('list', { | ||
renameKey: function (fp) { | ||
return path.basename(fp); | ||
} | ||
}); | ||
|
||
/** | ||
* Views | ||
*/ | ||
|
||
app.pages('blog/src/*.hbs'); | ||
// app.posts('blog/src/_posts/*.md'); | ||
// app.layouts('blog/src/_layouts/*.hbs'); | ||
// app.includes('blog/src/_includes/*.hbs'); | ||
|
||
// console.log(app.views.includes) | ||
|
||
// var list = app.posts.list('foo') | ||
// .pagination(function (err, post) { | ||
// // console.log(post) | ||
// }) | ||
|
||
console.log(app.views.posts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var App = require('..'); | ||
var app = new App(); | ||
|
||
/** | ||
* Create a view collection: "pages" | ||
*/ | ||
app.create('pages'); | ||
|
||
/** | ||
* Add pages | ||
*/ | ||
|
||
app.page('a', {path: 'pages/a.md', content: 'aaa...', data: {foo: {bar: 'Nested!'}}}); | ||
app.page('b', {path: 'pages/b.md', content: 'bbb...'}); | ||
app.page('c', {path: 'pages/c.md', content: 'ccc...'}); | ||
|
||
/** | ||
* Get a page | ||
*/ | ||
|
||
var pageA = app.pages.get('a'); | ||
|
||
/** | ||
* Get a property from the page | ||
*/ | ||
|
||
var path = pageA.get('path'); | ||
// => 'pages/a.md'; | ||
|
||
/** | ||
* Get a nested property from the page | ||
*/ | ||
|
||
var data = pageA.get('data.foo.bar'); | ||
//=> 'Nested!'; | ||
|
||
|
||
/** | ||
* Get content | ||
*/ | ||
|
||
var pageB = app.pages.get('b').content; | ||
//=> 'bbb...'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.