コード例 #1
0
        public string Process(Uri cssRootPathUri, System.IO.FileInfo file, string fileContents)
        {
            var distinctRelativePaths = _cssPathRewriter.FindDistinctRelativePaths(fileContents);

            return(_cssPathRewriter.RewriteCssPathsToBeRelativeToPath(distinctRelativePaths,
                                                                      cssRootPathUri,
                                                                      _absoluteUriDirectory, fileContents));
        }
コード例 #2
0
        /// <summary>
        /// Get the processed css of a file.
        ///
        /// Files with extension .less or .less.css will be generated with dotless.
        /// If appentHashToAssets = true, hashes of local existing files will be appending to processed css.
        /// </summary>
        /// <returns>The processed contents of a file.</returns>
        public string GetContents()
        {
            _lock.EnterUpgradeableReadLock();

            try
            {
                if (_contents == null)
                {
                    _lock.EnterWriteLock();
                    try
                    {
                        _contents = RetryableFileOpener.ReadAllText(FileInfo);

                        var fileName = FileInfo.Name.ToLower();

                        if (fileName.EndsWith(".less") || fileName.EndsWith(".less.css"))
                        {
                            _contents = ProcessDotLess(_contents);
                        }

                        var cssRootPathUri        = GetRootPathUri(CssRootUri);
                        var distinctRelativePaths = CssPathRewriter.FindDistinctRelativePaths(_contents);
                        _contents = CssPathRewriter.RewriteCssPathsToBeRelativeToPath(distinctRelativePaths,
                                                                                      cssRootPathUri,
                                                                                      RelativeRootUri, _contents);

                        if (AppendHashToAssets)
                        {
                            _contents = ProcessAppendHash(cssRootPathUri, _contents);
                        }
                    }
                    finally
                    {
                        _lock.ExitWriteLock();
                    }
                }

                return(_contents);
            }
            finally
            {
                _lock.ExitUpgradeableReadLock();
            }
        }