Between() public static method

public static Between ( string from, string to ) : RelativePathAdapter
from string
to string
return RelativePathAdapter
Exemplo n.º 1
0
        public static string RewriteCssPaths(string outputPath, string sourcePath, string css, ICSSAssetsFileHasher cssAssetsFileHasher, IPathTranslator pathTranslator, bool asImport = false)
        {
            var relativePaths = FindDistinctRelativePathsIn(css);

            if (relativePaths.Any())
            {
                var relativeOutputPath = GetWebPath(outputPath, pathTranslator);
                var relativeSourcePath = GetWebPath(sourcePath, pathTranslator);

                var relativePathAdapter = RelativePathAdapter.Between(relativeOutputPath, relativeSourcePath);

                foreach (var relativePath in relativePaths)
                {
                    var firstIndexOfHashOrQuestionMark = relativePath.IndexOfAny(new[] { '?', '#' });

                    var segmentAfterHashOrQuestionMark = firstIndexOfHashOrQuestionMark >= 0
                                                             ? relativePath.Substring(firstIndexOfHashOrQuestionMark)
                                                             : string.Empty;

                    var capturedRelativePath = segmentAfterHashOrQuestionMark != string.Empty
                                                   ? relativePath.Substring(0, firstIndexOfHashOrQuestionMark)
                                                   : relativePath;

                    var resolvedOutput = relativePathAdapter.Adapt(capturedRelativePath);

                    var newRelativePath = (asImport ? "squishit://" : "") + (resolvedOutput + segmentAfterHashOrQuestionMark);

                    css = ReplaceRelativePathsIn(css, relativePath, newRelativePath);
                }
            }

            //moved out of if block above so that root-relative paths can be hashed as well
            if (cssAssetsFileHasher != null)
            {
                var hashableAssetPaths = FindHashableAssetPaths(css);

                foreach (var hashableAssetPath in hashableAssetPaths)
                {
                    var assetPathWithHash = cssAssetsFileHasher.AppendFileHash(outputPath, hashableAssetPath);

                    if (hashableAssetPath != assetPathWithHash)
                    {
                        css = ReplaceRelativePathsIn(css, hashableAssetPath, assetPathWithHash);
                    }
                }
            }

            if (!asImport)
            {
                css = css.Replace("squishit://", "");
            }

            return(css);
        }
Exemplo n.º 2
0
        public static string RewriteCssPaths(string outputPath, string sourcePath, string css, ICSSAssetsFileHasher cssAssetsFileHasher, bool asImport = false)
        {
            var relativePaths = FindDistinctRelativePathsIn(css);

            if (relativePaths.Any())
            {
                var relativePathAdapter = RelativePathAdapter.Between(outputPath, sourcePath);

                foreach (var relativePath in relativePaths)
                {
                    var firstIndexOfHashOrQuestionMark = relativePath.IndexOfAny(new[] { '?', '#' });

                    var segmentAfterHashOrQuestionMark = firstIndexOfHashOrQuestionMark >= 0
                                                             ? relativePath.Substring(firstIndexOfHashOrQuestionMark)
                                                             : string.Empty;

                    var capturedRelativePath = segmentAfterHashOrQuestionMark != string.Empty
                                                   ? relativePath.Substring(0, firstIndexOfHashOrQuestionMark)
                                                   : relativePath;

                    var resolvedOutput = relativePathAdapter.Adapt(capturedRelativePath);

                    var newRelativePath = (asImport ? "squishit://" : "") + (resolvedOutput + segmentAfterHashOrQuestionMark);

                    css = ReplaceRelativePathsIn(css, relativePath, newRelativePath);
                }

                if (cssAssetsFileHasher != null)
                {
                    var localRelativePathsThatExist = FindDistinctLocalRelativePathsThatExist(css);

                    foreach (var localRelativePathThatExist in localRelativePathsThatExist)
                    {
                        var localRelativePathThatExistWithFileHash = cssAssetsFileHasher.AppendFileHash(outputPath,
                                                                                                        localRelativePathThatExist);

                        if (localRelativePathThatExist != localRelativePathThatExistWithFileHash)
                        {
                            css = css.Replace(localRelativePathThatExist, localRelativePathThatExistWithFileHash);
                        }
                    }
                }
            }

            if (!asImport)
            {
                css = css.Replace("squishit://", "");
            }

            return(css);
        }