Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: autogenerate agenda based on titles of slides #28

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ the following fields.
* **style**: An optional stylesheet to load
* **output**: A location to save the rendered document (default: *FILENAME-cleaver.html*)
* **controls**: A boolean representing whether or not arrow buttons should be included (default: *true*)
* **agenda**: A boolean representing whether or not to create an agenda slide after the title (default: *false*). These will be generated based on the titles of your other slides.

If author is included, the following slide will be automatically inserted
at the end of your presentation:
Expand Down Expand Up @@ -131,6 +132,13 @@ Or click the buttons

* Fork it
* Clone it
* Install dependencies if you don't have them already

npm install q
npm install node-markdown
npm install js-yaml
npm install mustache

* Checkout a release branch (`git checkout -b feature/cool-wordart`)
* Make changes, commit, and push
* Open a pull request!
Expand Down
9 changes: 9 additions & 0 deletions examples/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ author:
twitter: "@jdan"
url: "http://jordanscales.com"
output: basic.html
agenda: true

--

Expand All @@ -27,3 +28,11 @@ This will be in a separate paragraph
* Item gamma

No need for multiple templates!

--

#### A fourth level title

So that you know that the agenda will be properly generated and it will consider your changes of title levels accordingly.

All of them will be at the same level to generate a simple-looking agenda.
31 changes: 30 additions & 1 deletion lib/cleaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function Cleaver(file) {
// TODO: make these constants?
this.templates = {
main: 'layout.mustache',
author: 'author.mustache'
author: 'author.mustache',
agenda: 'agenda.mustache'
};

this.resources = {
Expand Down Expand Up @@ -53,6 +54,11 @@ Cleaver.prototype._parseDocument = function () {
self.slides.push(self._renderAuthorSlide(self.metadata.author));
}

// insert agenda after title (lets make this the second slide)
if (self.metadata.agenda) {
self.slides.splice(1, 0, self._renderAgendaSlide(slices));
}

// maybe load an external stylesheet
if (self.metadata.style) {
return helper.loadSingle(self.metadata.style)
Expand Down Expand Up @@ -108,6 +114,29 @@ Cleaver.prototype._renderAuthorSlide = function (authorData) {
return mustache.render(this.templates.loaded.author, authorData);
}

/*
* Renders the agenda slide
* @param {string} slices The set of slices that had been loaded from the input file
* @return {string} The formatted agenda slide
*/
Cleaver.prototype._renderAgendaSlide = function (slices) {
var titles = [];

for (var i = 0; i < slices.length; i++) { // for each slice
var firstLine = slices[i].split(/(\n|\r)+/)[0]; // get our first line of text
var matches = /^(#+)\s+(.+)$/.exec(firstLine); // parse the level and the title

if (!matches // if we didn't parse anything
|| matches.length != 3 // we didn't find all capture groups
|| matches[1].length <= 2 // this title is a major title or a subtitle
) continue; // then this is not a title to work with

var titleText = matches[2];
titles.push(titleText);
} // for each slice

return mustache.render(this.templates.loaded.agenda, titles);
}

/**
* Returns a chopped up document that's easy to parse
Expand Down
6 changes: 6 additions & 0 deletions templates/agenda.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h3>Agenda</h3>
<ul>
{{#.}}
<li>{{.}}</li>
{{/.}}
</ul>