-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (61 loc) · 2.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const hljs = require('highlight.js');
const bespoke = require('bespoke');
const qsa = require('fdom/qsa');
const shaz = require('shaz');
const _ = require('underscore');
const { render } = require('./lib/render');
const { importStyles } = require('./lib/css');
const { initContainer } = require('./lib/container');
const DEFAULT_PLUGIN_PACKAGES = [require('bespoke-keys'), require('bespoke-touch'), require('bespoke-hash')];
/**
# shazam
Shazam is a simple code driven presentation system. It is designed
primarily to make it easier to write a presentation that has demos and
that sort of thing baked in.
## How it Works
Under the hood shazam just uses
[bespoke.js](https://github.com/markdalgleish/bespoke.js) and a number
of bespoke plugins. All it's really doing is dynamically creating the
HTML with the various builder functions before letting bespoke do
it's thing.
## Example Usage
<<< examples/welcome.js
Then make it go using something like
[beefy](https://github.com/chrisdickinson/beefy):
```
beefy examples/welcome.js
```
**/
const shazam = (opts = {}) => {
const defaultPlugins = DEFAULT_PLUGIN_PACKAGES.map((plugin) => plugin());
const slides = _.flatten(opts.slides || []).map(render(opts));
const getPluginList = () => [
...defaultPlugins,
...(opts.plugins || []),
opts.theme || require('bespoke-theme-voltaire')(),
];
const triggerEvent = (evtName) => (evt) => {
const slide = slides[evt.index];
if (slide && typeof slide.emit === 'function') {
slide.emit(evtName);
}
};
const container = initContainer();
qsa('.slide', container).forEach((el) => el.parentNode.removeChild(el));
slides.forEach((slide) => container.appendChild(slide.el));
// initialise bespoke
const deck = bespoke.from('article', getPluginList());
['activate', 'deactivate'].forEach((evtName) => {
deck.on(evtName, triggerEvent(evtName));
});
// set out title based on the title provided
document.title = (opts || {}).title || 'Untitled Presentation';
importStyles(opts.styles, opts.codeTheme);
qsa('pre code').forEach(hljs.highlightBlock.bind(hljs));
};
// monkey patch any of the shaz plugins onto shazam
Object.keys(shaz).forEach((key) => {
shazam[key] = shaz[key];
});
shazam.blank = shaz.slide;
module.exports = shazam;