Skip to content

Commit

Permalink
normalize-uri is required only in windows, and is quite slow
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Apr 6, 2018
1 parent 9566901 commit d072e88
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
22 changes: 14 additions & 8 deletions lib/functions/normalize-uri.js
@@ -1,16 +1,10 @@
"use strict";

var URI = require("../util/URI");
var isWindows = /win32/.test(require("os").platform());

module.exports = function(eyeglass, sass) {
return {
"eyeglass-normalize-uri($uri, $type: web)": function($uri, $type, done) {
var type = $type.getValue();
var uri = $uri.getValue();
// normalize the uri for the given type
uri = URI[type](uri);
done(sass.types.String(uri));
},
var methods = {
"eyeglass-uri-preserve($uri)": function($uri, done) {
var uri = $uri.getValue();
// decorate the uri
Expand All @@ -24,4 +18,16 @@ module.exports = function(eyeglass, sass) {
done(sass.types.String(uri));
}
};

if (isWindows || process.env.EYEGLASS_NORMALIZE_PATHS) {
methods["-eyeglass-normalize-uri($uri, $type: web)"] = function($uri, $type, done) {
var type = $type.getValue();
var uri = $uri.getValue();
// normalize the uri for the given type
uri = URI[type](uri);
done(sass.types.String(uri));
};
}

return methods;
};
7 changes: 7 additions & 0 deletions sass/assets.scss
Expand Up @@ -11,6 +11,13 @@
// output URL which is namespaced to avoid conflicts with application urls.
$eg-registered-assets: () !default;

@function eyeglass-normalize-uri($uri, $type: web) {
@if function-exists(-eyeglass-normalize-uri) {
@return -eyeglass-normalize-uri($uri, $type);
}

@return $uri;
}
// Registers many assets for a module at once.
// @param $module string The name of the module to which these assets belong.
// @param $url the source url of the asset. This is what is passed to asset-url().
Expand Down
7 changes: 3 additions & 4 deletions test/test_assets.js
Expand Up @@ -293,11 +293,10 @@ describe("assets", function () {
var input = "@import 'eyeglass/assets';" +
"@include asset-register(module-a, 'foo/bar.png', 'images/foo/bar.png', " +
"$uri: 'assets/foo/bar.png');" +
".test { foo: inspect($eg-registered-assets); }";
".test { foo: inspect(map-get(map-get($eg-registered-assets, module-a), 'foo/bar.png')); }";
var filepath = path.join("images", "foo", "bar.png").replace(/\\/g, "\\\\");
var expected = ".test {\n foo: (module-a: (foo/bar.png: (" +
'filepath: "' + filepath + '", ' +
'uri: "assets/foo/bar.png"))); }\n';
var expected = '.test {\n foo: (filepath: "' + filepath + '", ' +
'uri: "assets/foo/bar.png"); }\n';
var rootDir = testutils.fixtureDirectory("app_assets");
var eg = new Eyeglass({
data: input,
Expand Down

0 comments on commit d072e88

Please sign in to comment.