Comparing version 0.6.3 to 0.6.4
var Q = require('q'); | ||
var debug = require('debug')('cleaver'); | ||
var path = require('path'); | ||
@@ -59,4 +60,8 @@ var marked = require('marked'); | ||
return Q.all([ | ||
helper.load(this.external, { external: true }), | ||
helper.load(this.templates) | ||
helper.load(this.external, { external: true }).then(function () { | ||
debug('loaded input document'); | ||
}), | ||
helper.load(this.templates).then(function () { | ||
debug('loaded templates'); | ||
}) | ||
]); | ||
@@ -76,2 +81,3 @@ }; | ||
this.metadata = yaml.safeLoad(slices[0].content) || {}; | ||
debug('parsed metadata'); | ||
@@ -116,3 +122,6 @@ for (i = 1; i < slices.length; i++) { | ||
if (this.metadata.style) { | ||
promises.push(helper.populateSingle(this.metadata.style, this.external, 'style')); | ||
promises.push(helper.populateSingle(this.metadata.style, this.external, 'style') | ||
.then(function () { | ||
debug('loaded user stylesheet'); | ||
})); | ||
} | ||
@@ -122,3 +131,6 @@ | ||
if (this.metadata.template) { | ||
promises.push(helper.populateSingle(this.metadata.template, this.templates, 'slides')); | ||
promises.push(helper.populateSingle(this.metadata.template, this.templates, 'slides') | ||
.then(function () { | ||
debug('loaded user template'); | ||
})); | ||
} | ||
@@ -128,3 +140,6 @@ | ||
if (this.metadata.layout) { | ||
promises.push(helper.populateSingle(this.metadata.layout, this.templates, 'layout')); | ||
promises.push(helper.populateSingle(this.metadata.layout, this.templates, 'layout') | ||
.then(function () { | ||
debug('loaded user layout'); | ||
})); | ||
} | ||
@@ -144,3 +159,5 @@ | ||
if (this.metadata.theme) { | ||
return helper.loadTheme(this.metadata.theme, this); | ||
return helper.loadTheme(this.metadata.theme, this).then(function () { | ||
debug('loaded theme'); | ||
}); | ||
} | ||
@@ -159,3 +176,5 @@ }; | ||
helper.load(this.resources) | ||
]); | ||
]).then(function () { | ||
debug('loaded static assets'); | ||
}); | ||
}; | ||
@@ -172,3 +191,3 @@ | ||
var putProgress = this.metadata.progress || (this.metadata.progress === undefined); | ||
var style, script; | ||
var style, script, output; | ||
@@ -182,2 +201,4 @@ // Render the slides in a template (maybe as specified by the user) | ||
debug('rendered slides'); | ||
// TODO: handle defaults gracefully | ||
@@ -218,3 +239,7 @@ var title = this.metadata.title || 'Untitled'; | ||
/* Return the rendered slideshow */ | ||
return mustache.render(this.templates.loaded.layout, layoutData); | ||
output = mustache.render(this.templates.loaded.layout, layoutData); | ||
debug('rendered presentation'); | ||
return output; | ||
}; | ||
@@ -221,0 +246,0 @@ |
var Q = require('q'); | ||
var debug = require('debug')('helper'); | ||
var http = require('http'); | ||
@@ -19,12 +20,11 @@ var https = require('https'); | ||
* @param {string} source The source document to load | ||
* @param {!Boolean} failsafe Option to fail gracefully, without raising errors | ||
* @return {Promise.<string>} The file contents | ||
*/ | ||
function loadSingle(source, failsafe) { | ||
function loadSingle(source) { | ||
var promise; | ||
if (source.match(/^https?:\/\//)) { | ||
promise = httpGetPromise(source, failsafe); | ||
promise = httpGetPromise(source); | ||
} else { | ||
promise = readFilePromise(normalizePath(source), failsafe); | ||
promise = readFilePromise(normalizePath(source)); | ||
} | ||
@@ -46,7 +46,6 @@ | ||
* @param {string} key The key to use for storing the loaded data in destination | ||
* @param {!Boolean} failsafe Option to fail gracefully, without raising errors | ||
* @return {Promise} | ||
*/ | ||
function populateSingle(filename, destination, key, failsafe) { | ||
return loadSingle(filename, failsafe) | ||
function populateSingle(filename, destination, key) { | ||
return loadSingle(filename) | ||
.then(function (data) { | ||
@@ -144,6 +143,6 @@ if (data) { | ||
loadSettings(source + 'settings.json', ctx), | ||
populateSingle(source + 'style.css', ctx.external, 'style', true), | ||
populateSingle(source + 'template.mustache', ctx.templates, 'slides', true), | ||
populateSingle(source + 'layout.mustache', ctx.templates, 'layout', true), | ||
populateSingle(source + 'script.js', ctx.external, 'script', true) | ||
populateSingle(source + 'style.css', ctx.external, 'style'), | ||
populateSingle(source + 'template.mustache', ctx.templates, 'slides'), | ||
populateSingle(source + 'layout.mustache', ctx.templates, 'layout'), | ||
populateSingle(source + 'script.js', ctx.external, 'script') | ||
]; | ||
@@ -163,3 +162,3 @@ | ||
function loadSettings(source, ctx) { | ||
return loadSingle(source, true).then(function (data) { | ||
return loadSingle(source).then(function (data) { | ||
if (data) { | ||
@@ -176,19 +175,19 @@ data = JSON.parse(data); | ||
* @param {string} filename The file to load | ||
* @param {!Boolean} failsafe Option to fail gracefully, without raising errors | ||
* @return {Promise.<string>} The file's contents | ||
*/ | ||
function readFilePromise(filename, failsafe) { | ||
function readFilePromise(filename) { | ||
var deferred; | ||
if (!failsafe) { | ||
return Q.nfcall(fs.readFile, filename, 'utf-8'); | ||
} else { | ||
deferred = Q.defer(); | ||
deferred = Q.defer(); | ||
fs.readFile(filename, 'utf-8', function (err, contents) { | ||
fs.readFile(filename, 'utf-8', function (err, contents) { | ||
if (err) { | ||
debug(err + ' ' + filename); | ||
} else { | ||
debug('read ' + filename); | ||
deferred.resolve(contents); | ||
}); | ||
} | ||
}); | ||
return deferred.promise; | ||
} | ||
return deferred.promise; | ||
} | ||
@@ -200,6 +199,5 @@ | ||
* @param {string} url The url to request | ||
* @param {!Boolean} failsafe Option to fail gracefully, without raising errors | ||
* @return {Promise.<string>} The body of the response | ||
*/ | ||
function httpGetPromise(url, failsafe) { | ||
function httpGetPromise(url) { | ||
var deferred = Q.defer(), get; | ||
@@ -210,11 +208,2 @@ | ||
if (res.statusCode !== 200) { | ||
if (failsafe) { | ||
deferred.resolve(); | ||
} else { | ||
deferred.reject(new Error( | ||
'The url (' + url + ') returned with status ' + res.statusCode)); | ||
} | ||
} | ||
res.on('data', function (chunk) { | ||
@@ -225,3 +214,9 @@ data += chunk; | ||
res.on('end', function () { | ||
deferred.resolve(data); | ||
if (res.statusCode !== 200) { | ||
debug(res.statusCode + ': ' + url); | ||
deferred.resolve(); | ||
} else { | ||
debug('fetched ' + url); | ||
deferred.resolve(data); | ||
} | ||
}); | ||
@@ -237,8 +232,4 @@ }; | ||
get.on('error', function (err) { | ||
if (failsafe) { | ||
deferred.resolve(); | ||
} else { | ||
deferred.reject(new Error( | ||
'The url (' + url + ') caused an error')); | ||
} | ||
deferred.resolve(); | ||
debug(err + ': ' + url); | ||
}); | ||
@@ -245,0 +236,0 @@ |
{ | ||
"name": "cleaver", | ||
"preferGlobal": true, | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"author": "Jordan Scales <scalesjordan@gmail.com>", | ||
@@ -31,2 +31,3 @@ "description": "30-second slideshows for hackers", | ||
"devDependencies": { | ||
"debug": "~0.8.0", | ||
"jshint": "~2.3.0" | ||
@@ -33,0 +34,0 @@ }, |
@@ -73,2 +73,20 @@ # Cleaver | ||
Use the `--debug` flag to display debug information: | ||
```bash | ||
$ cleaver --debug examples/basic.md | ||
cleaver loaded input document +0ms | ||
helper read /Users/jordan/Projects/cleaver/templates/layout.mustache +0ms | ||
helper read /Users/jordan/Projects/cleaver/templates/author.mustache +0ms | ||
helper read /Users/jordan/Projects/cleaver/templates/default.mustache +0ms | ||
cleaver loaded templates +3ms | ||
cleaver parsed metadata +4ms | ||
helper read /Users/jordan/Projects/cleaver/resources/default.css +13ms | ||
helper read /Users/jordan/Projects/cleaver/resources/github.css +0ms | ||
helper read /Users/jordan/Projects/cleaver/resources/script.js +0ms | ||
cleaver loaded static assets +9ms | ||
cleaver rendered slides +1ms | ||
cleaver rendered presentation +1ms | ||
``` | ||
## More Info | ||
@@ -75,0 +93,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43872
937
291
2