Skip to content

Commit

Permalink
examples, tests, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Dec 10, 2018
1 parent 8b8cad7 commit 051785e
Show file tree
Hide file tree
Showing 92 changed files with 3,121 additions and 934 deletions.
12 changes: 0 additions & 12 deletions appveyor.yml

This file was deleted.

4 changes: 2 additions & 2 deletions bench/application/App/methods/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ bench('app-create', true)
app.create('pages');
})
.add('app.create() with options', () => {
app.create('layouts', { kind: 'layout' });
app.create('layouts', { type: 'layout' });
})
.add('view from app.create() collection', () => {
app.create('layouts', { kind: 'layout' });
app.create('layouts', { type: 'layout' });
app.layouts.set('foo', { path: 'foo/bar' });
})
.run();
2 changes: 1 addition & 1 deletion bench/application/Collection/instantiation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ bench('new-collection', true)
new Collection('pages');
})
.add('new Collection() with options', () => {
new Collection('layouts', { kind: 'layout' });
new Collection('layouts', { type: 'layout' });
})
.run();
6 changes: 3 additions & 3 deletions bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let app = new Templates({ asyncHelpers: false });
app.engine('hbs', engine(handlebars));

app.create('pages');
app.create('layouts', { kind: 'layout' });
app.create('layouts', { type: 'layout' });
app.layouts.set({ path: 'foo', contents: Buffer.from('before {% body %} after') });
app.layouts.set({ path: 'base', contents: Buffer.from('before {% body %} after'), layout: 'foo' });
app.layouts.set({ path: 'default', contents: Buffer.from('before {% body %} after'), layout: 'base' });
Expand All @@ -31,7 +31,7 @@ const file = app.pages.set('foo', {

bench('layouts')
.add('collection.renderLayout()', () => {
const collection = new Collection('layouts', { kind: 'layout '});
const collection = new Collection('layouts', { type: 'layout '});
collection.set({ path: 'default', contents: 'before {{name}} after' });
const file = new File({ path: 'foo/bar', contents: 'before {{name}} after' });
})
Expand Down Expand Up @@ -64,7 +64,7 @@ bench('layouts')
// });

// const pages = app.create('pages');
// const layouts = app.create('layouts', { kind: 'layout' });
// const layouts = app.create('layouts', { type: 'layout' });
// layouts.set({ path: 'default.hbs', contents: Buffer.from('before {% body %} after') });

// app.engine('hbs', engine(handlebars));
Expand Down
3 changes: 2 additions & 1 deletion bench/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
console.time('# templates');
require('templates');
console.timeEnd('# templates');
// ~8.45ms - 2018-08-17
// ~8.450ms - 2018-08-17
// ~8.707ms - 2018-11-11
// ~8.644ms - 2018-11-13
4 changes: 2 additions & 2 deletions bench/rendering/_temp-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const runner = require('setup/runner');
});

const pages = app.create('pages');
const partials = app.create('partials', { kind: 'partial' });
const layouts = app.create('layouts', { kind: 'layout' });
const partials = app.create('partials', { type: 'partial' });
const layouts = app.create('layouts', { type: 'layout' });
const wait = (fn, n = 0) => new Promise(resolve => setTimeout(() => resolve(fn()), n));

// app.options.transform = (str, file, layout) => {
Expand Down
6 changes: 3 additions & 3 deletions bench/rendering/app-layouts-async.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';

const handlebars = require('handlebars');
const engine = require('templates/lib/engines');
const engine = require('engine-handlebars');
const runner = require('setup/runner');

(async function() {
const Templates = require('templates');
const app = new Templates();

const pages = app.create('pages');
const partials = app.create('partials', { kind: 'partial' });
const layouts = app.create('layouts', { kind: 'layout' });
const partials = app.create('partials', { type: 'partial' });
const layouts = app.create('layouts', { type: 'layout' });

app.data({ site: { title: 'Blog' }});
app.engine('hbs', engine(handlebars.create()));
Expand Down
6 changes: 3 additions & 3 deletions bench/rendering/app-layouts-sync.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const handlebars = require('handlebars');
const engine = require('templates/lib/engines');
const engine = require('engine-handlebars');
const runner = require('setup/runner');
const Templates = require('templates');
const app = new Templates({ sync: true });
Expand All @@ -19,8 +19,8 @@ app.option('engine', 'hbs');
*/

app.create('pages');
app.create('layouts', { kind: 'layout' });
app.create('partials', { kind: 'partial' });
app.create('layouts', { type: 'layout' });
app.create('partials', { type: 'partial' });

/**
* Layouts
Expand Down
14 changes: 7 additions & 7 deletions bench/rendering/app-layouts-sync2.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const pretty = require('pretty-time');
const colors = require('ansi-colors');
const handlebars = require('handlebars');
const engine = require('templates/lib/engines');
const engine = require('engine-handlebars');
const Templates = require('templates');
const app = new Templates({ sync: true, handlers: ['onLoad'] });
const hbs = engine(handlebars);
const cyan = (...args) => colors.cyan(pretty(...args.concat(2)));

app.engine('hbs', hbs);
app.create('pages');
app.create('layouts', { kind: 'layout' });
app.create('partials', { kind: 'partial' });
app.create('layouts', { type: 'layout' });
app.create('partials', { type: 'partial' });
// app.onLoad(/\.hbs$/, hbs.compile.bind(hbs));

/**
Expand Down Expand Up @@ -59,11 +59,11 @@ const increment = (num = 1000, step = 5) => {
};

console.time('total');
let n = 1e4;
let n = 1e5;
let i = 0;

const time = timer();
const count = increment(n, 5);
let time = timer();
let count = increment(n, 5);

while (i++ < n) {
try {
Expand All @@ -77,6 +77,6 @@ while (i++ < n) {
}
}

const total = time();
let total = time();
console.log('rendered:', colors.cyan(n.toLocaleString()), 'pages at', cyan(ns(total) / n), 'each');
console.timeEnd('total');
30 changes: 15 additions & 15 deletions bench/rendering/generate/generate-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const defaults = {
dest: 'content',
count: 1600,
units: 'words',
pages: 1000
pages: 50
};

async function generate(options = {}) {
const generate = async(options = {}) => {
let opts = Object.assign({}, defaults, options);
let contents = loremipsum(opts);
let date = formatDate(opts.startDate);
Expand Down Expand Up @@ -49,23 +49,23 @@ ${contents}
`;

for (let i = 0; i < opts.pages; i++) {
const file1 = page(date(i), contents, i, 1);
const file2 = page(date(i), contents, i, 2);
let file1 = page(date(i), contents, i, 1);
let file2 = page(date(i), contents, i, 2);
await write(dest(file1.path), file1.contents);
await write(dest(file2.path), file2.contents);
}

console.timeEnd(time);
}
};

function page(date, contents, i, n) {
const file = {
let file = {
data: {
title: 'Blog post - ' + i,
title: `Blog post - ${i}`,
description: 'This is a description',
tags: tags(),
date: date,
slug: 'foo-bar-baz-' + n
slug: `foo-bar-baz-${n}`
}
};

Expand All @@ -80,25 +80,25 @@ function stringify(data) {
}

function formatDate(startDate) {
const start = new Date(startDate);
const dayOne = start.getDate();
let start = new Date(startDate);
let dayOne = start.getDate();
return i => {
const day = new Date(start);
let day = new Date(start);
day.setDate(dayOne + i);
return datestamp(day);
};
}

function datestamp(date = new Date()) {
const year = date.getUTCFullYear();
const month = date.getUTCMonth() + 1;
const day = date.getUTCDate();
let year = date.getUTCFullYear();
let month = date.getUTCMonth() + 1;
let day = date.getUTCDate();
return `${year}-${month}-${day}`;
}

// super-simple mock randomness
function tags() {
const arr = [];
let arr = [];
switch (Math.floor(Math.random() * 50)) {
case 3:
case 9:
Expand Down
Loading

0 comments on commit 051785e

Please sign in to comment.