コード例 #1
0
        public void Process(BundleContext context, BundleResponse response)
        {
            var builder = new StringBuilder();

            foreach (var file in response.Files)
            {
                IBundleTransform transform = null;

                if (file.Extension.Equals(
                    ".coffee",
                    StringComparison.OrdinalIgnoreCase))
                {
                    transform = new CoffeeScriptTransform(_bare);
                }
                else if (file.Extension.Equals(
                    ".js",
                    StringComparison.OrdinalIgnoreCase))
                {
                    transform = new CommonNoTransform(ContentTypes.JavaScript);
                }

                if (transform == null || !File.Exists(file.FullName))
                    continue;

                response.Content = 
                    File.ReadAllText(file.FullName, Encoding.UTF8);

                transform.Process(context, response);

                builder.AppendLine(response.Content);
            }

            response.ContentType = ContentTypes.JavaScript;
            response.Content = builder.ToString();
        }
        public void Process(BundleContext context, BundleResponse response)
        {
            var builder = new StringBuilder();
            
            foreach (var file in response.Files)
            {
                IBundleTransform transform = null;

                if (file.IncludedVirtualPath.EndsWith(
                    ".coffee",
                    StringComparison.OrdinalIgnoreCase))
                {
                    transform = new CoffeeScriptTransform(_bare);
                }
                else if (file.VirtualFile.VirtualPath.EndsWith(
                    ".js",
                    StringComparison.OrdinalIgnoreCase))
                {
                    transform = new CommonNoTransform(ContentType.JavaScript);
                }

                var path =
                    context.HttpContext.Server.MapPath(
                        file.IncludedVirtualPath);

                if (transform == null || !File.Exists(path))
                {
                    continue;
                }

                response.Content =
                    File.ReadAllText(path, Encoding.UTF8);

                transform.Process(context, response);

                builder.AppendLine(response.Content);
            }

            response.ContentType = ContentType.JavaScript;
            response.Content = builder.ToString();
        }