Example #1
0
        public override bool FileExists(string virtualPath)
        {
            var exists      = false;
            var styleResult = ThemeHelper.IsStyleSheet(virtualPath);

            TokenizedSassPath sassPath = null;

            if (styleResult != null)
            {
                exists = _sassCheckedPathStack.Check(styleResult, out sassPath);
                if (exists)
                {
                    // It seems awkward to return false when check result actually says true.
                    // But true in this context means: a check for THIS sass file pattern (e.g. _slick.scss.sass)
                    // yielded true previously (because _slick.scss really exists on disks), therefore _slick.scss.sass
                    // CANNOT exist (or SHOULD not by convention). By returning false we prevent that a real filesystem check
                    // is made against _slick.scss.sass (which is huge performace saver considering that IThemeFileResolver
                    // also does some additional checks).
                    return(false);
                }

                if (styleResult.IsThemeVars || styleResult.IsModuleImports)
                {
                    _sassCheckedPathStack.PushExistingPath(sassPath);
                    return(true);
                }
            }

            exists = base.FileExists(virtualPath);

            if (exists && sassPath != null)
            {
                _sassCheckedPathStack.PushExistingPath(sassPath);
            }

            return(exists);
        }
Example #2
0
 public void PushExistingPath(TokenizedSassPath path)
 {
     _state.GetState().Push(path);
 }
Example #3
0
        /// <summary>
        /// Checks last path existence
        /// </summary>
        /// <returns>true = does exist, no need to check | false = not checked yet</returns>
        public bool Check(StyleSheetResult styleResult, out TokenizedSassPath path)
        {
            path = new TokenizedSassPath(styleResult);

            var state = _state.GetState();

            if (state.Count == 0)
            {
                return(false);
            }

            var currentPath = path;
            var lastPath    = _state.GetState().Peek();

            if (currentPath.Extension.IsEmpty())
            {
                // We dont't allow extension-less Sass files, so no need to check.
                return(true);
            }

            if (lastPath.Dir != currentPath.Dir)
            {
                return(false);
            }

            if (currentPath.StyleResult.IsBaseImport && lastPath.StyleResult.IsBaseImport && currentPath.FileName == lastPath.FileName)
            {
                return(true);
            }

            if (currentPath.StyleResult.IsModuleImports && lastPath.StyleResult.IsModuleImports)
            {
                return(true);
            }

            if (currentPath.StyleResult.IsThemeVars && lastPath.StyleResult.IsThemeVars)
            {
                return(true);
            }

            // slick.scss.(scss|sass|css) > slick.scss
            if (Path.GetExtension(currentPath.FileNameWithoutExtension) == ".scss")
            {
                return(true);
            }

            // slick.(sass|css) > slick.scss
            if (!currentPath.StyleResult.IsBaseImport && _styleExtensions.Contains(currentPath.Extension) && currentPath.FileNameWithoutExtension == lastPath.FileNameWithoutExtension)
            {
                return(true);
            }

            // _slick.scss > slick.scss
            if (currentPath.FileName.StartsWith("_"))
            {
                if (currentPath.FileName.Substring(1) == lastPath.FileName)
                {
                    return(true);
                }
            }

            // slick.(scss|sass|css) > _slick.scss
            if (lastPath.FileNameWithoutExtension.StartsWith("_"))
            {
                if (lastPath.FileNameWithoutExtension == "_" + currentPath.FileNameWithoutExtension)
                {
                    return(true);
                }
            }

            return(false);
        }