nikku / kartoffeldruck

A all-in-one, opinionated, swiss army knife, hackable static site generator.
Other
6 stars 1 forks source link

Implement generation event (fixes #8) #9

Closed jrehwaldt closed 8 years ago

jrehwaldt commented 8 years ago

Implements a generation callback druck.on('generated', function(event) { ... }) with event providing access to {dest, source (not the original source!), locals, rendered, ...custom props}.

The interface from Generator.generate was extended in that it returns the generated output. Additionally, this commit upgrades chai to the latest stable as the functionality expect(result).to.contain.all.keys('dest', 'source', 'rendered', 'locals', 'myCustomProp'); was desired.

General observations: It is to some extend unpredictable what outcome will be available in the callback's argument (but also within the generator#generate) without having knowledge of the internals and the templates. This is for the following reasons:

The rather arguable design decision to implement pagination via locals.items. This value could easily be overridden page/template internally via the front-matter and/or the latter has no effect.

Also, the Kartoffeldruck.prototype.generate method as it stands now provides quite some unexpected behavior:

  1. it discards pagination: 1 property (and probably some others, but which?)
  2. it overrides initial source, which forces the author to specify it twice in the hash provided as options if required within the event callback
jrehwaldt commented 8 years ago

Fixes #8.

nikku commented 8 years ago

Closed via 52aebe21859b383c888d20f15f9960bf0e62f8db.

I changed the implementation of Kartoffeldruck#generate to return the generated contents, too.

This simplified testing by a lot.