Skip to content

Commit e2bb479

Browse files
committed
Remove cssRelativeUrl test case, implement cssPrefix option (Fixes #350)
1 parent 77306cc commit e2bb479

File tree

4 files changed

+28
-31
lines changed

4 files changed

+28
-31
lines changed

build/jslib/build.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,12 @@ define(function (require) {
999999
if (!config.out) {
10001000
throw new Error('"out" option missing.');
10011001
}
1002+
if (config.cssPrefix) {
1003+
//Make sure cssPrefix ends in a slash
1004+
config.cssPrefix = endsWithSlash(config.cssPrefix);
1005+
} else {
1006+
config.cssPrefix = '';
1007+
}
10021008
}
10031009
if (!config.cssIn && !config.baseUrl) {
10041010
//Just use the current directory as the baseUrl

build/jslib/optimize.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ function (lang, logger, envOptimize, file, parse,
4343
* @param {String} fileName the file name
4444
* @param {String} fileContents the file contents
4545
* @param {String} cssImportIgnore comma delimited string of files to ignore
46+
* @param {String} cssPrefix string to be prefixed before relative URLs
4647
* @param {Object} included an object used to track the files already imported
4748
*/
48-
function flattenCss(fileName, fileContents, cssImportIgnore, included) {
49+
function flattenCss(fileName, fileContents, cssImportIgnore, cssPrefix, included) {
4950
//Find the last slash in the name.
5051
fileName = fileName.replace(lang.backSlashRegExp, "/");
5152
var endIndex = fileName.lastIndexOf("/"),
@@ -96,7 +97,7 @@ function (lang, logger, envOptimize, file, parse,
9697
included[fullImportFileName] = true;
9798

9899
//Make sure to flatten any nested imports.
99-
flat = flattenCss(fullImportFileName, importContents, cssImportIgnore, included);
100+
flat = flattenCss(fullImportFileName, importContents, cssImportIgnore, cssPrefix, included);
100101
importContents = flat.fileContents;
101102

102103
if (flat.importList.length) {
@@ -125,8 +126,9 @@ function (lang, logger, envOptimize, file, parse,
125126
//a protocol.
126127
colonIndex = fixedUrlMatch.indexOf(":");
127128
if (fixedUrlMatch.charAt(0) !== "/" && (colonIndex === -1 || colonIndex > fixedUrlMatch.indexOf("/"))) {
128-
//It is a relative URL, tack on the path prefix
129-
urlMatch = importPath + fixedUrlMatch;
129+
//It is a relative URL, tack on the cssPrefix and path prefix
130+
urlMatch = cssPrefix + importPath + fixedUrlMatch;
131+
130132
} else {
131133
logger.trace(importFileName + "\n URL not a relative URL, skipping: " + urlMatch);
132134
}
@@ -256,7 +258,7 @@ function (lang, logger, envOptimize, file, parse,
256258

257259
//Read in the file. Make sure we have a JS string.
258260
var originalFileContents = file.readFile(fileName),
259-
flat = flattenCss(fileName, originalFileContents, config.cssImportIgnore, {}),
261+
flat = flattenCss(fileName, originalFileContents, config.cssImportIgnore, config.cssPrefix, {}),
260262
//Do not use the flattened CSS if there was one that was skipped.
261263
fileContents = flat.skippedList.length ? originalFileContents : flat.fileContents,
262264
startIndex, endIndex, buildText, comment;

build/tests/builds.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,25 +1000,6 @@ define(['build', 'env!env/file'], function (build, file) {
10001000
);
10011001
doh.run();
10021002

1003-
//Tests https://github.com/jrburke/r.js/issues/350 CSS optimizer makes
1004-
//url() relative to cssIn option
1005-
doh.register("cssRelativeUrl",
1006-
[
1007-
function cssPrefix(t) {
1008-
file.deleteFile("lib/cssRelativeUrl/output/main-built.css");
1009-
1010-
build(["lib/cssRelativeUrl/build.js"]);
1011-
1012-
t.is(nol(c("lib/cssRelativeUrl/output/expected.css")),
1013-
nol(c("lib/cssRelativeUrl/output/main-built.css")));
1014-
1015-
require._buildReset();
1016-
}
1017-
1018-
]
1019-
);
1020-
doh.run();
1021-
10221003
//Tests https://github.com/jrburke/r.js/issues/296 removeCombined should
10231004
//remove files that have been inlined.
10241005
doh.register("cssRemoveCombined",

dist/r.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @license r.js 2.1.2+ Tue, 15 Jan 2013 01:33:33 GMT Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
2+
* @license r.js 2.1.2+ Wed, 16 Jan 2013 01:24:27 GMT Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
33
* Available via the MIT or new BSD license.
44
* see: http://github.com/jrburke/requirejs for details
55
*/
@@ -21,7 +21,7 @@ var requirejs, require, define;
2121

2222
var fileName, env, fs, vm, path, exec, rhinoContext, dir, nodeRequire,
2323
nodeDefine, exists, reqMain, loadedOptimizedLib, existsForNode,
24-
version = '2.1.2+ Tue, 15 Jan 2013 01:33:33 GMT',
24+
version = '2.1.2+ Wed, 16 Jan 2013 01:24:27 GMT',
2525
jsSuffixRegExp = /\.js$/,
2626
commandOption = '',
2727
useLibLoaded = {},
@@ -21201,9 +21201,10 @@ function (lang, logger, envOptimize, file, parse,
2120121201
* @param {String} fileName the file name
2120221202
* @param {String} fileContents the file contents
2120321203
* @param {String} cssImportIgnore comma delimited string of files to ignore
21204+
* @param {String} cssPrefix string to be prefixed before relative URLs
2120421205
* @param {Object} included an object used to track the files already imported
2120521206
*/
21206-
function flattenCss(fileName, fileContents, cssImportIgnore, included) {
21207+
function flattenCss(fileName, fileContents, cssImportIgnore, cssPrefix, included) {
2120721208
//Find the last slash in the name.
2120821209
fileName = fileName.replace(lang.backSlashRegExp, "/");
2120921210
var endIndex = fileName.lastIndexOf("/"),
@@ -21254,7 +21255,7 @@ function (lang, logger, envOptimize, file, parse,
2125421255
included[fullImportFileName] = true;
2125521256

2125621257
//Make sure to flatten any nested imports.
21257-
flat = flattenCss(fullImportFileName, importContents, cssImportIgnore, included);
21258+
flat = flattenCss(fullImportFileName, importContents, cssImportIgnore, cssPrefix, included);
2125821259
importContents = flat.fileContents;
2125921260

2126021261
if (flat.importList.length) {
@@ -21283,8 +21284,9 @@ function (lang, logger, envOptimize, file, parse,
2128321284
//a protocol.
2128421285
colonIndex = fixedUrlMatch.indexOf(":");
2128521286
if (fixedUrlMatch.charAt(0) !== "/" && (colonIndex === -1 || colonIndex > fixedUrlMatch.indexOf("/"))) {
21286-
//It is a relative URL, tack on the path prefix
21287-
urlMatch = importPath + fixedUrlMatch;
21287+
//It is a relative URL, tack on the cssPrefix and path prefix
21288+
urlMatch = cssPrefix + importPath + fixedUrlMatch;
21289+
2128821290
} else {
2128921291
logger.trace(importFileName + "\n URL not a relative URL, skipping: " + urlMatch);
2129021292
}
@@ -21414,7 +21416,7 @@ function (lang, logger, envOptimize, file, parse,
2141421416

2141521417
//Read in the file. Make sure we have a JS string.
2141621418
var originalFileContents = file.readFile(fileName),
21417-
flat = flattenCss(fileName, originalFileContents, config.cssImportIgnore, {}),
21419+
flat = flattenCss(fileName, originalFileContents, config.cssImportIgnore, config.cssPrefix, {}),
2141821420
//Do not use the flattened CSS if there was one that was skipped.
2141921421
fileContents = flat.skippedList.length ? originalFileContents : flat.fileContents,
2142021422
startIndex, endIndex, buildText, comment;
@@ -23170,6 +23172,12 @@ define('build', function (require) {
2317023172
if (!config.out) {
2317123173
throw new Error('"out" option missing.');
2317223174
}
23175+
if (config.cssPrefix) {
23176+
//Make sure cssPrefix ends in a slash
23177+
config.cssPrefix = endsWithSlash(config.cssPrefix);
23178+
} else {
23179+
config.cssPrefix = '';
23180+
}
2317323181
}
2317423182
if (!config.cssIn && !config.baseUrl) {
2317523183
//Just use the current directory as the baseUrl

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy