Permalink
Browse files

normalize-uri is required only in windows, and is quite slow

  • Loading branch information...
stefanpenner committed Apr 4, 2018
1 parent 9566901 commit d072e887b60a750c2df7ee823ccfb183e20e6c4e
Showing with 24 additions and 12 deletions.
  1. +14 −8 lib/functions/normalize-uri.js
  2. +7 −0 sass/assets.scss
  3. +3 −4 test/test_assets.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
@@ -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;
};
@@ -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().
@@ -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,

0 comments on commit d072e88

Please sign in to comment.