コード例 #1
0
        public static byte[] TransformInputFile(PhysicalFileSource source, byte[] inputContent)
        {
            var transformations = FileTransformerRegistry.GetTransformationsFor(source.ResourceType);

            if (transformations.Count() == 0)
            {
                return(inputContent.CloneBytes());
            }

            return(transformations.Aggregate(inputContent, (current, transformation) => transformation.TransformFile(source, current)));
        }
コード例 #2
0
        public static PhysicalFileSource For(FileInfo file, ResourceType resourceType, Mode mode)
        {
            var virtualPathFor = VirtualPathResolver.GetVirtualPathFor(file);

            var physicalFileSource = For(virtualPathFor);

            if (physicalFileSource == null)
            {
                physicalFileSource = new PhysicalFileSource(resourceType,
                                                            virtualPathFor,
                                                            file.FullName,
                                                            mode);

                Set(physicalFileSource);
            }

            return(physicalFileSource);
        }
コード例 #3
0
        public byte[] TransformFile(PhysicalFileSource source, byte[] inputContent)
        {
            Log.WriteLine("Transforming CSS For '{0}'", source.VirtualPath);
            string stringValue = inputContent.ReadString();

            stringValue = Regex.Replace(stringValue, "url\\((?<quotation>['\"]?)(?<capturedUrl>[^\\)]*)", x =>
            {
                var url = x.Groups["capturedUrl"];
                if (url != null)
                {
                    var urlValue = url.Value.Trim();

                    if (!urlValue.StartsWith("~"))
                    {
                        return(x.Value);
                    }

                    var quotation    = x.Groups["quotation"];
                    var quoteWrapper = quotation != null ? quotation.Value : "";

                    if (urlValue.EndsWith(quoteWrapper))
                    {
                        urlValue = urlValue.Substring(0, urlValue.Length - quoteWrapper.Length);
                    }

                    var virtualPath = urlValue;

                    // look for a placeholder in the virtual path
                    if (virtualPath.Contains(RejuicerConfigurationSource.FilenameUniquePlaceholder))
                    {
                        // Look for a configuration
                        if (!RejuicerEngine.HasConfigurationFor(virtualPath))
                        {
                            // Create a configuration for this file
                            OnRequest.ForImage(virtualPath)
                            .Compact
                            .File(virtualPath.Replace(RejuicerConfigurationSource.FilenameUniquePlaceholder, ""))
                            .Configure();
                        }

                        // get the timestamp and write it out into the URL...
                        var config = RejuicerEngine.GetConfigFor(virtualPath);

                        if (config != null)
                        {
                            // don't timestamp the URL in pass through mode
                            virtualPath = RejuicerEngine.IsPassThroughEnabled ? config.GetNonTimestampedUrl(_cacheProvider) : config.GetTimestampedUrl(_cacheProvider);

                            // Need to add a dependency of this CSS file to the now linked image.
                            source.AddDependency(RejuicerEngine.GetConfigFor(urlValue));
                        }
                        else
                        {
                            // Could not configure rejuicer for this file. It may not exist,
                            // so just return the url
                            return(url.Value);
                        }
                    }

                    var outputUrl = _virtualPathResolver.GetRelativeUrl(virtualPath);

                    return(string.Format("url({1}{0}{1}", outputUrl, quoteWrapper));
                }

                return(x.Value);
            });



            return(stringValue.AsBytes());
        }
コード例 #4
0
 public static void Set(PhysicalFileSource fileSource)
 {
     fileSourceRegister[fileSource.VirtualPath] = fileSource;
 }