Exemple #1
0
        public void CanBundleCssWithNestedLess()
        {
            string importCss =
                @"
                @import 'other.less';
                #header {
                    color: #4D926F;
                }";

            CSSBundle cssBundle = cssBundleFactory
                                  .WithDebuggingEnabled(false)
                                  .WithContents(importCss)
                                  .Create()
                                  .WithPreprocessor(new LessPreprocessor());

            TestUtilities.CreateFile("other.less", "#footer{color:#ffffff}");
            cssBundle
            .Add("~/css/test.less")
            .Render("~/css/output_test.css");

            TestUtilities.DeleteFile("other.less");

            Assert.AreEqual("#footer{color:#fff}#header{color:#4d926f}", cssBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"css\output_test.css")]);
            Assert.Contains(translator.ResolveAppRelativePathToFileSystem("css/other.less"), cssBundle.bundleState.DependentFiles);
        }
Exemple #2
0
        public static Input FromAsset(Asset asset, IPathTranslator pathTranslator, Func<bool> isDebuggingEnabled)
        {
            if (!asset.IsEmbeddedResource)
            {
                if (isDebuggingEnabled())
                {
                    return new Input(pathTranslator.ResolveAppRelativePathToFileSystem(asset.LocalPath), asset.IsRecursive, ResolverFactory.Get<FileSystemResolver>());
                }
                if (asset.IsRemoteDownload)
                {
                    return new Input(asset.RemotePath, false, ResolverFactory.Get<HttpResolver>());
                }
                //this is weird - do we absolutely need to treat as the remote downloads as local when debugging?
                return new Input(pathTranslator.ResolveAppRelativePathToFileSystem(asset.LocalPath), asset.IsRecursive, ResolverFactory.Get<FileSystemResolver>());
            }

            return asset.IsEmbeddedInRootNamespace ? new Input(asset.RemotePath, false, ResolverFactory.Get<RootEmbeddedResourceResolver>())
                : new Input(asset.RemotePath, false, ResolverFactory.Get<StandardEmbeddedResourceResolver>());
        }
Exemple #3
0
        public static Input FromAsset(Asset asset, IPathTranslator pathTranslator, Func <bool> isDebuggingEnabled)
        {
            if (!asset.IsEmbeddedResource)
            {
                if (isDebuggingEnabled())
                {
                    return(new Input(pathTranslator.ResolveAppRelativePathToFileSystem(asset.LocalPath), asset.IsRecursive, ResolverFactory.Get <FileSystemResolver>()));
                }
                if (asset.IsRemoteDownload)
                {
                    return(new Input(asset.RemotePath, false, ResolverFactory.Get <HttpResolver>()));
                }
                //this is weird - do we absolutely need to treat as the remote downloads as local when debugging?
                return(new Input(pathTranslator.ResolveAppRelativePathToFileSystem(asset.LocalPath), asset.IsRecursive, ResolverFactory.Get <FileSystemResolver>()));
            }

            return(asset.IsEmbeddedInRootNamespace ? new Input(asset.RemotePath, false, ResolverFactory.Get <RootEmbeddedResourceResolver>())
                : new Input(asset.RemotePath, false, ResolverFactory.Get <StandardEmbeddedResourceResolver>()));
        }
Exemple #4
0
        string GetNormalizedPath(string path)
        {
            if (String.IsNullOrEmpty(path))
            {
                return(NullPathSurrogate);
            }

            // Normalize the path
            var fileSystemPath = pathTranslator.ResolveAppRelativePathToFileSystem(path);

            // The path is lower cased to avoid different hashes. Even on a case sensitive
            // file system this probably is okay, since it's a web application
            return(Path.GetFullPath(fileSystemPath)
                   .ToLowerInvariant());
        }
Exemple #5
0
        public override IProcessResult Process(string filePath, string content)
        {
            var    engine = _engineBuilder();
            string css    = engine.TransformToCss(content, filePath);

            string dir     = Path.GetDirectoryName(filePath);
            string appPath = string.Empty;

            if (!string.IsNullOrEmpty(dir))
            {
                appPath = pathTranslator.ResolveFileSystemPathToAppRelative(dir);
            }

            var dependencies = engine.GetImports().Select(importPath => {
                return(pathTranslator.ResolveAppRelativePathToFileSystem(Path.Combine(appPath, importPath)));
            });

            return(new ProcessResult(css, dependencies));
        }
        string GetAssetFilePath(string cssFilePath, string url)
        {
            var queryStringPosition = url.IndexOf('?');

            if (queryStringPosition > -1)
            {
                url = url.Substring(0, queryStringPosition);
            }

            if (Platform.Unix)
            {
                url = url.TrimStart('/');
            }

            var resolvedUrl = string.Empty;

            var urlUri = new Uri(url, UriKind.RelativeOrAbsolute);

            if (!urlUri.IsAbsoluteUri)
            {
                if (!url.StartsWith("/"))
                {
                    var resolvedPath = Path.GetDirectoryName(cssFilePath);
                    if (Platform.Unix)
                    {
                        resolvedPath = resolvedPath.Replace("file:", "");
                    }

                    var outputUri = new Uri(resolvedPath + "/", UriKind.Absolute);

                    var resolvedSourcePath = new Uri(outputUri, urlUri);
                    resolvedUrl = resolvedSourcePath.LocalPath;
                }
                else
                {
                    resolvedUrl = pathTranslator.ResolveAppRelativePathToFileSystem(url);
                }

                return(FileSystemResolver.Resolve(resolvedUrl));
            }

            return(urlUri.LocalPath);
        }