Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow options to contain template data

  • Loading branch information...
commit 12e5ca895fe7a92df92075c06ece8e44feefc0e6 1 parent 161ecd3
@mklabs authored
Showing with 16 additions and 7 deletions.
  1. +15 −6 tools/impress2md/lib/impress.js
  2. +1 −1  tools/impress2md/package.json
View
21 tools/impress2md/lib/impress.js
@@ -6,7 +6,8 @@ var fs = require('fs'),
marked = require('marked'),
stream = require('stream'),
Template = require('./template'),
- highlight = require('highlight.js').highlightAuto;
+ highlight = require('highlight.js').highlightAuto,
+ _ = require('underscore');
module.exports = Impress;
Impress.Template = Template;
@@ -25,7 +26,10 @@ function Impress(options) {
this._sections = [];
this.chunks = [];
- this.data = { name: '', page: 0 };
+ this.data = _.defaults(this.options, {
+ name: '',
+ page: 0
+ });
}
util.inherits(Impress, stream.Stream);
@@ -72,7 +76,7 @@ Impress.prototype.sections = function _sections(tokens) {
var sections = this._sections;
// the data object holder passed in to template
- var data = {};
+ var data = this.data;
var last = {};
tokens.forEach(function(t) {
@@ -92,7 +96,6 @@ Impress.prototype.sections = function _sections(tokens) {
});
this._sections = sections;
- this.data = data;
return this;
};
@@ -106,7 +109,7 @@ Impress.prototype.attributes = function attributes(last) {
return {
x : x ? x + 1050 : 1,
y : y || -1000,
- z : z,
+ z : z || 0,
rx : 0,
ry : 0,
rz : 0,
@@ -154,6 +157,8 @@ Impress.prototype.html = function() {
var self = this;
this._sections.forEach(function(section, i) {
section.html = marked.parser(section.tokens);
+ // marked seems to "consume" the tokens while compiling to html
+ delete section.tokens;
var attrs = section.attributes;
section.attributes = [
@@ -172,7 +177,11 @@ Impress.prototype.html = function() {
};
Impress.prototype.output = function() {
- var output = this.assets(this.template.render({ sections: this._sections }));
+ // bring back the template data, and attach there the sections guess from
+ // markdown
+ var data = _.extend(this.data, { sections: this._sections });
+ // compile and render the final html
+ var output = this.assets(this.template.render(data));
this.emit('data', output);
return this;
};
View
2  tools/impress2md/package.json
@@ -2,7 +2,7 @@
"name": "impress2md",
"version": "0.0.0",
"description": "Little helper to generate basic impress based HTML presentation from raw Markdown",
- "main": "bin/impress",
+ "bin": "bin/impress",
"main": "lib/impress",
"directories": {
"test": "test"
Please sign in to comment.
Something went wrong with that request. Please try again.