Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Do path resolution before import processing and style inlining
Browse files Browse the repository at this point in the history
Excluded imports did not have the information to modify their paths correctly,
leading to duplication in path.

This also reduces the the complexity of path resolution for style inlining, so a
win all around.

Fixes #27
  • Loading branch information
dfreedm committed Apr 2, 2014
1 parent e86d845 commit 527e4e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
18 changes: 7 additions & 11 deletions lib/vulcan.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function inlineSheets($, inputPath, outputPath) {
$('link[rel="stylesheet"]').each(function() {
var href = this.attr('href');
if (href && !excludeStyle(href)) {
var filepath = path.resolve(inputPath, href);
var filepath = path.resolve(options.outputDir, href);
// fix up paths in the stylesheet to be relative to the location of the style
var content = pathresolver.rewriteURL(path.dirname(filepath), inputPath, readFile(filepath));
var styleDoc = cheerio.load('<style>' + content + '</style>');
Expand Down Expand Up @@ -99,9 +99,9 @@ function concat(filename) {
read[filename] = true;
var $ = readDocument(filename);
var dir = path.dirname(filename);
processImports($, dir);
inlineSheets($, dir, options.outputDir);
pathresolver.resolvePaths($, dir, options.outputDir);
processImports($);
inlineSheets($, dir, options.outputDir);
return $.html();
} else {
if (options.verbose) {
Expand All @@ -110,14 +110,11 @@ function concat(filename) {
}
}

function processImports($, prefix) {
function processImports($) {
$(constants.IMPORTS).each(function() {
var href = this.attr('href');
if (excludeImport(href)) {
// rewrite href to be deduplicated later
this.attr('href', pathresolver.rewriteRelPath(prefix, options.outputDir, href));
} else {
this.replaceWith(concat(path.resolve(prefix, href)));
if (!excludeImport(href)) {
this.replaceWith(concat(path.resolve(options.outputDir, href)));
}
});
}
Expand Down Expand Up @@ -156,15 +153,14 @@ function removeCommentsAndWhitespace($) {

function handleMainDocument() {
// reset shared buffers
imports_before_polymer = [];
read = {};
var $ = readDocument(options.input);
var dir = path.dirname(options.input);
pathresolver.resolvePaths($, dir, options.outputDir);
processImports($, dir);
if (options.inline) {
inlineSheets($, dir, options.outputDir);
}
pathresolver.resolvePaths($, dir, options.outputDir);

// strip scripts into a separate file
if (options.csp) {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"vulcanize": "bin/vulcanize"
},
"dependencies": {
"cheerio": "~0.13.1",
"nopt": "~2.2.0",
"async": "^0.6.2",
"cheerio": "^0.14.0",
"clean-css": "~2.1.0",
"uglify-js": "~2.4.8",
"async": "^0.6.2"
"nopt": "~2.2.0",
"uglify-js": "~2.4.8"
},
"devDependencies": {},
"scripts": {
Expand Down

0 comments on commit 527e4e0

Please sign in to comment.