Comparing version 0.3.1 to 0.4.0
@@ -10,4 +10,3 @@ var fs = require('fs'); | ||
function Cleaver(file) { | ||
this.file = file | ||
this.file = file; | ||
if (!file) throw "!! Please specify a file to parse"; | ||
@@ -60,3 +59,3 @@ | ||
var slices = this._slice(self.external.loaded.document); | ||
this.metadata = yaml.safeLoad(slices[0]); | ||
this.metadata = yaml.safeLoad(slices[0]) || {}; | ||
@@ -85,15 +84,21 @@ for (var i = 1; i < slices.length; i++) | ||
Cleaver.prototype._populateResources = function () { | ||
var promises = []; | ||
var promises = [], file; | ||
// maybe load an external stylesheet | ||
if (this.metadata.style) | ||
promises.push(helper.populateSingle(this.metadata.style, this.external, 'style')); | ||
if (this.metadata.style) { | ||
file = this._normalizePath(this.metadata.style); | ||
promises.push(helper.populateSingle(file, this.external, 'style')); | ||
} | ||
// maybe load an external template | ||
if (this.metadata.template) | ||
promises.push(helper.populateSingle(this.metadata.template, this.templates, 'slides')); | ||
if (this.metadata.template) { | ||
file = this._normalizePath(this.metadata.template); | ||
promises.push(helper.populateSingle(file, this.templates, 'slides')); | ||
} | ||
// maybe load an external layout | ||
if (this.metadata.layout) | ||
promises.push(helper.populateSingle(this.metadata.layout, this.templates, 'layout')); | ||
if (this.metadata.layout) { | ||
file = this._normalizePath(this.metadata.layout); | ||
promises.push(helper.populateSingle(file, this.templates, 'layout')); | ||
} | ||
@@ -200,2 +205,15 @@ return Q.all(promises); | ||
for (var i = 0; i < cuts.length; i++) { | ||
/** | ||
* EDGE CASE | ||
* If the slideshow begins with `--`, that is, the metadata is empty and | ||
* the user did *not* include a blank line at the top, we will insert an | ||
* empty slide at the beginning (to represent empty metadata), followed | ||
* by the first slice (with the -- chopped off). | ||
*/ | ||
if (i == 0 && cuts[i].match(/^--/)) { | ||
slices.push(""); | ||
cuts[i] = cuts[i].slice(2); | ||
} | ||
slices.push(cuts[i].trim()); | ||
@@ -209,2 +227,20 @@ } | ||
/** | ||
* Helper method to normalize a path to a given file. This will take the base | ||
* path of `file`, and append it to a given filename. Used for loading | ||
* stylesheets, templates, etc. specified by the user that should be referenced | ||
* relative to the input document. | ||
* | ||
* If a pathname is an absolute path, it is returned as-is. | ||
* | ||
* @param {string} pathname | ||
* @return {string} | ||
*/ | ||
Cleaver.prototype._normalizePath = function (pathname) { | ||
if (pathname[0] == '/') return pathname; | ||
return path.dirname(this.file) + '/' + pathname; | ||
} | ||
/** | ||
* Method to run the whole show. | ||
@@ -229,7 +265,6 @@ * | ||
throw err; | ||
}) | ||
.done(); | ||
}); | ||
} | ||
/* exports */ | ||
module.exports = Cleaver; |
@@ -81,3 +81,3 @@ var Q = require('q'); | ||
/* exports */ | ||
exports.loadSingle = loadSingle; | ||
@@ -84,0 +84,0 @@ exports.populateSingle = populateSingle; |
{ | ||
"name": "cleaver", | ||
"preferGlobal": true, | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"author": "Jordan Scales <scalesjordan@gmail.com>", | ||
@@ -6,0 +6,0 @@ "description": "30-second slideshows for hackers", |
# Cleaver | ||
30-second Slideshows for Hackers | ||
30-second Slideshows for Hackers. http://jdan.github.io/cleaver/ | ||
@@ -54,4 +54,7 @@ ## Intro | ||
``` | ||
```bash | ||
cleaver path/to/something.md | ||
# to recompile on changes: | ||
# cleaver watch path/to/something.md | ||
``` | ||
@@ -69,2 +72,4 @@ | ||
Cleaver also looks great on mobile. | ||
Let's walk through the above example piece by piece. | ||
@@ -195,6 +200,6 @@ | ||
With <3, | ||
With <3,<br/>[@jdan](http://jordanscales.com) | ||
[@jdan](http://jordanscales.com) | ||
-- | ||
[MIT Licensed](https://github.com/jdan/cleaver/blob/master/LICENSE) |
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
24723
17
572
203