UNPKG

2.7 kBJavaScriptView Raw
1(function() {
2 'use strict';
3 var SlideGenerator, fs, generators, path, slugify,
4 extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5 hasProp = {}.hasOwnProperty;
6
7 fs = require('fs');
8
9 path = require('path');
10
11 generators = require('yeoman-generator');
12
13 slugify = require('underscore.string/slugify');
14
15 module.exports = SlideGenerator = (function(superClass) {
16 extend(SlideGenerator, superClass);
17
18 function SlideGenerator() {
19 generators.Base.apply(this, arguments);
20 this.argument('name', {
21 type: String,
22 required: true
23 });
24 }
25
26 SlideGenerator.prototype.configuring = function() {
27 this.option('notes', {
28 desc: 'Include speaker notes',
29 type: Boolean,
30 "default": false
31 });
32 this.option('markdown', {
33 desc: 'Use markdown',
34 type: Boolean,
35 "default": false
36 });
37 return this.option('attributes', {
38 desc: 'Include attributes on slide sections, e.g. data-background, class, etc.',
39 type: Boolean,
40 "default": false
41 });
42 };
43
44 SlideGenerator.prototype.writing = function() {
45 var fullPath, list;
46 fullPath = this.destinationPath('slides/list.json');
47 list = this.fs.readJSON(fullPath);
48 if (this.options.markdown) {
49 this.filename = (slugify(this.name)) + ".md";
50 this.log.info('Using Markdown.');
51 if (this.options.notes) {
52 this.template('slide-withnotes.md', "slides/" + this.filename);
53 } else {
54 this.template('slide.md', "slides/" + this.filename);
55 }
56 } else {
57 this.filename = (slugify(this.name)) + ".html";
58 this.log.info('Using HTML.');
59 if (this.options.notes) {
60 this.template('slide-withnotes.html', "slides/" + this.filename);
61 } else {
62 this.template('slide.html', "slides/" + this.filename);
63 }
64 }
65 if (this.options.attributes) {
66 this.log.info("Appending slides/" + this.filename + " to slides/list.json.");
67 list.push({
68 filename: this.filename,
69 attr: {
70 'data-background': '#ff0000'
71 }
72 });
73 } else {
74 this.log.info("Appending slides/" + this.filename + " to slides/list.json.");
75 list.push(this.filename);
76 }
77 return fs.writeFileSync(fullPath, JSON.stringify(list, null, 4));
78 };
79
80 return SlideGenerator;
81
82 })(generators.Base);
83
84}).call(this);