Ejemplo n.º 1
0
		stylesheets.map(function (ss) {
			// First, take all stylesheets that give us new source
			// (as opposed to cacheable local paths) and turn them
			// into promises.
			if (ss.type === "absolute") {
				if (/^data:/.test(ss.url))
					ss = { type: "source", text: qfs.resolve(parseDataUri(ss.url)) };
				else {
					//TODO: Download source using q-http
					throw new Error("I haven't written an HTTP client yet; cannot download stylesheet at " + ss.url);
				}
			}

			if (ss.type === "source") {
				// source-type stylesheets can be promises (external URLs)
				// or raw strings (<style> tags or data: URLs)
				return Q.when(ss.text, function (source) {
					var pss = new ParsedStyleSheet(source, htmlPath, context.options);
					return preprocessor.cachedStyleSheet(pss, context.options);
				});
			} else if (ss.type === "relative") {
				var path = qfs.join(self.baseDir, ss.path);

				return qfs.canonical(path)
						  .then(self.getStylesheet.bind(self));
			} else {
				throw new Error("Unrecognized stylesheet " + JSON.stringify(ss));
			}
		}).map(function (p) {
Ejemplo n.º 2
0
Styliner.prototype.getStylesheet = function (path) {
	if (this.cachedFiles.hasOwnProperty(path))
		return this.cachedFiles[path];

	var format = getExtension(path);
	if (!Styliner.styleFormats.hasOwnProperty(format))
		throw new Error("'" + path + "' is of unsupported format " + format);

	var self = this;
	var fullPath = qfs.join(this.baseDir, path);
	var promise = qfs.read(fullPath)
		.then(function (stream) {
			return Styliner.styleFormats[format](
				stream.toString(),
				fullPath, self.options
			);
		})
		.then(function (source) {
			var pss = new ParsedStyleSheet(source, fullPath, self.options);
			return preprocessor.cachedStyleSheet(pss, self.options);
		});

	this.cachedFiles[path] = promise;
	return promise;
};
Ejemplo n.º 3
0
module.exports = Q.async(function*(latex, baseDir) {
	var svgFiles = getSVGReferences(latex);
	if (!svgFiles.length)
		return latex;

	var tmpDir = yield createTmpDir();

	for (var i = 0; i < svgFiles.length; i++) {
		var fileName = svgFiles[i];
		var resolvedFileName = fs.join(baseDir, fileName);
		var pdfFileName = fs.join(tmpDir, fileName.replace(/\W/g, '_') + '.pdf');
		if (yield fs.exists(pdfFileName))
			continue;

		console.log('Converting ' + resolvedFileName + '.svg to pdf...');
		yield exec('inkscape -z -D --file=' + escapeshell(resolvedFileName + '.svg')
			+ ' --export-pdf=' + escapeshell(pdfFileName));
		latex = latex.replace(
				'\\includegraphics{' + fileName + '.svg}',
				'\\includegraphics{' + pdfFileName + '}');
	}

	return latex;
});
Ejemplo n.º 4
0
Archivo: node.js Proyecto: NV/montage
var findPackage = function (path) {
    var directory = FS.directory(path);
    if (directory === path) {
        throw new Error("Can't find package");
    }
    var packageJson = FS.join(directory, "package.json");
    return FS.stat(path)
    .then(function (stat) {
        if (stat.isFile()) {
            return directory;
        } else {
            return findPackage(directory);
        }
    });
};
Ejemplo n.º 5
0
function loadDirectory(pathname, parse) {
    var documents = {};

    return fs.list(fs.join(__dirname, "..", pathname))
    .then(function (list) {
        return Q.all(list.map(function (filename) {
            var name = path.basename(filename, ".md");
            return fs.read(path.join(pathname, filename))
            .then(function (content) {
                documents[name] = parse(content.toString("utf8"));
            })
            .catch(function (error) {
                error.message = "Could not load " + path.join(pathname, filename) + " because " + error.message;
                throw error;
            });
        })).thenResolve(documents);
    });
}
Ejemplo n.º 6
0
Archivo: joey.js Proyecto: asolove/joey
chain.favicon = function (path) {
    var app;
    // TODO vanity icon
    if (path) {
        path = FS.join(arguments);
        app = Apps.File(path);
    } else {
        app = Apps.notFound;
    }
    return this.use(function (next) {
        return function (request, response) {
            if (request.pathInfo === "/favicon.ico") {
                return app(request, response);
            } else {
                return next(request, response);
            }
        };
    });
};
Ejemplo n.º 7
0
		.map(function (index, elem) {
			if (elem.name === "style") {
				return {
					type: 'source',
					text: cheerio(this).text()
				};
			}

			var href = cheerio(elem).attr('href');
			if (util.hasScheme(href)) {
				return {
					type: "absolute",
					url: href
				};
			} else {
				// If it doesn't have a protocol, assume it's a relative path.
				// Normalize the path to match stylesheetPaths.
				return {
					type: "relative",
					path: qfs.join(relativePath, href)
				};
			}
		}).concat(
Ejemplo n.º 8
0
 testFiles.forEach((filePath) => {
   assert(qfs.join(filePath).startsWith("src"));
 });
Ejemplo n.º 9
0
var path = require('path');
var qfs = require('q-io/fs');
var capsela = require('capsela');
var Styliner = require('..');
require('styliner-less')(Styliner);

var vash = require('vash');

var commander = require('commander');
commander.option('-c, --compact', "Minify generated HTML.");
commander.option('-k, --keep-rules', "Don't inline static CSS rules.");
commander.parse(process.argv);


var styliner = new Styliner(
	qfs.join(__dirname, 'TestFiles/'),
	{
		compact: commander.compact,
		keepRules: commander.keepRules,
		url: function (relativePath, type) {
			return relativePath + "?type=" + encodeURIComponent(type);

			//return Q.delay(relativePath + "?type=" + encodeURIComponent(type), 2000);
		}
	}
);

var VashViewEngine = capsela.View.extend({}, {
	init: function (template) {
		this._super(template);
		this.render = vash.compile(template);
Ejemplo n.º 10
0
Styliner.prototype.processHTML = function (source, relativePath, stylesheetPaths) {
	if (relativePath instanceof Array) {
		stylesheetPaths = relativePath;
		relativePath = ".";
	} else if (arguments.length === 1) {
		relativePath = ".";
	}

	stylesheetPaths = stylesheetPaths || [];

	var context = {
		$: cheerio.load(source, { ignoreWhitespace: this.options.compact }),
		options: this.options,
		folder: qfs.join(this.baseDir, relativePath)
	};
	context.root = context.$.root();

	var stylesheets = context.$('link[rel~="stylesheet"], style')
		.remove()
		.map(function (index, elem) {
			if (elem.name === "style") {
				return {
					type: 'source',
					text: cheerio(this).text()
				};
			}

			var href = cheerio(elem).attr('href');
			if (util.hasScheme(href)) {
				return {
					type: "absolute",
					url: href
				};
			} else {
				// If it doesn't have a protocol, assume it's a relative path.
				// Normalize the path to match stylesheetPaths.
				return {
					type: "relative",
					path: qfs.join(relativePath, href)
				};
			}
		}).concat(
			stylesheetPaths.map(function (p) {
				return { type: "relative", path: p };
			})
		);

	var self = this;

	var htmlPath = qfs.join(context.folder, '-html-');

	var stylesheetsLoaded = Q.all(
		stylesheets.map(function (ss) {
			// First, take all stylesheets that give us new source
			// (as opposed to cacheable local paths) and turn them
			// into promises.
			if (ss.type === "absolute") {
				if (/^data:/.test(ss.url))
					ss = { type: "source", text: qfs.resolve(parseDataUri(ss.url)) };
				else {
					//TODO: Download source using q-http
					throw new Error("I haven't written an HTTP client yet; cannot download stylesheet at " + ss.url);
				}
			}

			if (ss.type === "source") {
				// source-type stylesheets can be promises (external URLs)
				// or raw strings (<style> tags or data: URLs)
				return Q.when(ss.text, function (source) {
					var pss = new ParsedStyleSheet(source, htmlPath, context.options);
					return preprocessor.cachedStyleSheet(pss, context.options);
				});
			} else if (ss.type === "relative") {
				var path = qfs.join(self.baseDir, ss.path);

				return qfs.canonical(path)
						  .then(self.getStylesheet.bind(self));
			} else {
				throw new Error("Unrecognized stylesheet " + JSON.stringify(ss));
			}
		}).map(function (p) {
			return p.then(function (pss) {
				return preprocessor.documentStyleSheet(pss, context);
			});
		})
	);

	return Q.spread(
		[
			stylesheetsLoaded,
			preprocessor.htmlDocument(context)
		],
		function (elements) {
			/// <param name="elements" type="Array">An array of pre-processed arrays of stylesheet elements.  (One array for each stylesheet)</param>
			context.rules = Array.prototype.concat.apply([], elements);
			return applyStyles(context);
		}
	).then(function () { return context.root.html(); });
};
Ejemplo n.º 11
0
		.then(Qx.map(function (p) {
			return qfs.canonical(qfs.join(self.baseDir, p))
					  .then(self.getStylesheet.bind(self));
		}));
Ejemplo n.º 12
0
Styliner.prototype.parseFile = function(filePath) {
	var _this = this, path = qfs.join(this.baseDir,filePath);
	return  qfs.read(path).then(function(content) {
		return _this.processHTML(content, qfs.directory(filePath));
	});
}