Skip to content

Commit 6e7d581

Browse files
committed
Merge pull request #55 from angularity/bugfix/nginject-and-css-embedding
a couple of fixes following 0.3.0 release
2 parents e27f77d + dc718a5 commit 6e7d581

File tree

3 files changed

+66
-55
lines changed

3 files changed

+66
-55
lines changed

lib/build/node-sass.js

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -146,54 +146,65 @@ module.exports = function (bannerWidth, libraryPaths) {
146146
function reworkPlugin(stylesheet) {
147147

148148
// visit each node (selector) in the stylesheet recursively using the official utility method
149-
visit(stylesheet, function (declarations) {
150-
151-
// each node may have multiple declarations
152-
declarations.forEach(function (declaration) {
153-
154-
// reverse the original source-map to find the original sass file
155-
var cssStart = declaration.position.start;
156-
var sassStart = sourceMapConsumer.originalPositionFor({
157-
line: cssStart.line,
158-
column: cssStart.column
159-
});
160-
if (!sassStart.source) {
161-
throw new Error('failed to decode node-sass source map'); // this can occur with regressions in libsass
149+
// each node may have multiple declarations
150+
visit(stylesheet, function visitor(declarations) {
151+
declarations
152+
.forEach(eachDeclaration);
153+
});
154+
155+
/**
156+
* Process a declaration from the syntax tree.
157+
* @param declaration
158+
*/
159+
function eachDeclaration(declaration) {
160+
var URL_STATEMENT_REGEX = /(url\s*\()\s*(?:(['"])((?:(?!\2).)*)(\2)|([^'"](?:(?!\)).)*[^'"]))\s*(\))/g;
161+
162+
// reverse the original source-map to find the original sass file
163+
var cssStart = declaration.position.start;
164+
var sassStart = sourceMapConsumer.originalPositionFor({
165+
line : cssStart.line,
166+
column: cssStart.column
167+
});
168+
if (!sassStart.source) {
169+
throw new Error('failed to decode node-sass source map'); // this can occur with regressions in libsass
170+
}
171+
var sassDir = path.dirname(sassStart.source);
172+
173+
// allow multiple url() values in the declaration
174+
// split by url statements and process the content
175+
// additional capture groups are needed to match quotations correctly
176+
// escaped quotations are not considered
177+
declaration.value = declaration.value
178+
.split(URL_STATEMENT_REGEX)
179+
.map(eachSplitOrGroup)
180+
.join('');
181+
182+
/**
183+
* Encode the content portion of <code>url()</code> statements.
184+
* There are 4 capture groups in the split making every 5th unmatched.
185+
* @param {string} token A single split item
186+
* @param i The index of the item in the split
187+
* @returns {string} Every 3 or 5 items is an encoded url everything else is as is
188+
*/
189+
function eachSplitOrGroup(token, i) {
190+
191+
// we can get groups as undefined under certain match circumstances
192+
var initialised = token || '';
193+
194+
// the content of the url() statement is either in group 3 or group 5
195+
var mod = i % 7;
196+
if ((mod === 3) || (mod === 5)) {
197+
198+
// remove query string or hash suffix
199+
var uri = initialised.split(/[?#]/g).shift();
200+
return uri && encodeRelativeURL(sassDir, uri) || initialised;
162201
}
163-
var sassDir = path.dirname(sassStart.source);
164-
165-
// allow multiple url() values in the declaration
166-
// split by url statements and process the content
167-
// additional capture groups are needed to match quotations correctly
168-
// escaped quotations are not considered
169-
declaration.value = declaration.value
170-
.split(/(url\s*\(\s*)(['"]?)((?:(?!\2|\?|#]).)*(?:(?!\2).)*)(\2\s*\))/g)
171-
.map(eachSplitOrGroup)
172-
.join('');
173-
174-
/**
175-
* Encode the content portion of <code>url()</code> statements.
176-
* There are 4 capture groups in the split making every 5th unmatched.
177-
* @param {string} token A single split item
178-
* @param i The index of the item in the split
179-
* @returns {string} Every 3 or 5 items is an encoded url everything else is as is
180-
*/
181-
function eachSplitOrGroup(token, i) {
182-
183-
// the quoted or unquoted content of the url() statement
184-
if (i % 5 === 3) {
185-
186-
// remove query string or hash suffix
187-
var uri = token.split(/[?#]/g).shift();
188-
return encodeRelativeURL(sassDir, uri) || token;
189-
}
190-
// everything else, including parentheses and quotation (where present) and media statements
191-
else {
192-
return token;
193-
}
202+
// everything else, including parentheses and quotation (where present) and media statements
203+
else {
204+
return initialised;
194205
}
195-
});
196-
});
206+
}
207+
}
197208
}
198209

199210
/**

npm-shrinkwrap.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angularity",
33
"description": "An opinionated NodeJs build system for ECMAScript 6 AngularJs projects",
4-
"version": "0.3.0",
4+
"version": "0.3.1",
55
"tags": [
66
"build",
77
"system",
@@ -112,7 +112,7 @@
112112
},
113113
"devDependencies": {
114114
"angularity-helloworld-es5": "angularity/angularity-helloworld-es5#ci-build-0.2.0-E",
115-
"angularity-todo-es5": "angularity/angularity-todo-es5#ci-build-0.2.0-E",
115+
"angularity-todo-es5": "angularity/angularity-todo-es5#ci-build-0.2.0-F",
116116
"autodocs": "^0.6.8",
117117
"jasmine-diff-matchers": "~2.0.0",
118118
"jasmine-node": "2.0.0-beta4",

0 commit comments

Comments
 (0)