Skip to content

Commit

Permalink
Changed lookup of user-specified assets to look in the path relative …
Browse files Browse the repository at this point in the history
…to the input document - fixes #51
  • Loading branch information
jdan committed Oct 2, 2013
1 parent a0d7a37 commit 528d1d3
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions lib/cleaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var helper = require('./helper');

function Cleaver(file) {
this.file = file

if (!file) throw "!! Please specify a file to parse";

// TODO: make these constants?
Expand Down Expand Up @@ -80,19 +79,25 @@ Cleaver.prototype._renderSlides = function () {
* @return {Promise}
*/
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'));
}

return Q.all(promises);
}
Expand Down Expand Up @@ -214,6 +219,24 @@ Cleaver.prototype._slice = function(document) {
}


/**
* 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.
*
Expand Down

0 comments on commit 528d1d3

Please sign in to comment.