public override void Transform(IBundleItemTransformContext context) { int startIndex, endIndex = -1; var stringLocations = new List <(int startIndex, int count)>(); while ((startIndex = FindNextString(context.Content, ref endIndex)) >= 0) { stringLocations.Add((startIndex + 1, endIndex - startIndex - 1)); } if (stringLocations.Count == 0) { return; } var sb = new StringBuilder(context.Content); for (var i = stringLocations.Count - 1; i >= 0; i--) { var stringLocation = stringLocations[i]; sb.Remove(stringLocation.startIndex, stringLocation.count); var value = context.Content .Substring(stringLocation.startIndex, stringLocation.count) .Unescape('\\', '\'', '"'); value = _stringLocalizer[value].Value.Escape('\\', '\'', '"'); sb.Insert(stringLocation.startIndex, value); } context.Content = sb.ToString(); }
public override async Task TransformAsync(IBundleItemTransformContext context) { string filePath; IFileProvider fileProvider; if (context is IFileBundleItemTransformContext fileItemContext) { filePath = fileItemContext.FilePath; fileProvider = fileItemContext.FileProvider; } else { filePath = null; fileProvider = null; } PathString pathPrefix = context.BuildContext.BundlingContext.StaticFilesPathPrefix; PathString outputPath = context.BuildContext.BundlingContext.BundlesPathPrefix.Add(context.BuildContext.Bundle.Path); LessCompilationResult result = await _compiler.CompileAsync(context.Content, pathPrefix, filePath, fileProvider, outputPath, context.BuildContext.CancellationToken); context.Content = result.Content ?? string.Empty; if (result.Imports != null && result.Imports.Count > 0) { context.BuildContext.ChangeSources?.UnionWith(result.Imports.Select(import => new AbstractionFile(fileProvider, import))); } }
public override void Transform(IBundleItemTransformContext context) { if (context is IFileBundleItemTransformContext fileItemContext) { UrlUtils.GetFileName(fileItemContext.FilePath, out string basePath); PathString pathPrefix = context.BuildContext.AppBasePath + context.BuildContext.BundlingContext.StaticFilesPathPrefix; context.Content = RewriteUrls(context.Content, basePath, pathPrefix); } }
public override void Transform(IBundleItemTransformContext context) { if (context is IFileBundleItemTransformContext fileItemContext) { UrlUtils.GetFileName(fileItemContext.FilePath, out string basePath); var pathPrefix = context.BuildContext.HttpContext.Request.PathBase + context.BuildContext.BundlingContext.StaticFilesPathPrefix; context.Content = Regex.Replace(context.Content, @"(?<before>url\()(?<url>[^)]+?)(?<after>\))|(?<before>@import\s+)(?<url>['""][^'""]*['""])", m => string.Concat(m.Groups["before"].Value, RebaseUrl(basePath, pathPrefix, m.Groups["url"].Value), m.Groups["after"].Value)); } }
public override void Transform(IBundleItemTransformContext context) { if (context is IFileBundleItemTransformContext fileItemContext) { StringSegment filePathSegment = UrlUtils.NormalizePathSegment(fileItemContext.FilePath.Replace('\\', '/')); UrlUtils.GetFileNameSegment(filePathSegment, out StringSegment basePathSegment); basePathSegment = UrlUtils.NormalizePathSegment(basePathSegment, trailingNormalization: PathNormalization.ExcludeSlash); var virtualPathPrefix = UrlUtils.NormalizePath(context.BuildContext.BundlingContext.StaticFilesPathPrefix, trailingNormalization: PathNormalization.ExcludeSlash); PathString outputPath = context.BuildContext.BundlingContext.BundlesPathPrefix.Add(context.BuildContext.Bundle.Path); context.Content = RewriteUrls(context.Content, basePathSegment.Value, virtualPathPrefix, outputPath); } }
protected virtual async Task <string> ApplyItemTransformsAsync(IBundleItemTransformContext context, IReadOnlyList <IBundleItemTransform> transforms) { if (transforms != null) { var n = transforms.Count; for (var i = 0; i < n; i++) { context.BuildContext.CancellationToken.ThrowIfCancellationRequested(); var transform = transforms[i]; await transform.TransformAsync(context); transform.Transform(context); } } return(context.Content); }
public override async Task TransformAsync(IBundleItemTransformContext context) { string filePath; IFileProvider fileProvider; if (context is IFileBundleItemTransformContext fileItemContext) { filePath = fileItemContext.FilePath; fileProvider = fileItemContext.FileProvider; } else { filePath = null; fileProvider = null; } var pathPrefix = context.BuildContext.HttpContext.Request.PathBase + context.BuildContext.BundlingContext.StaticFilesPathPrefix; context.Content = await _compiler.CompileAsync(context.Content, pathPrefix, filePath, fileProvider); }
public virtual Task TransformAsync(IBundleItemTransformContext context) { return(Task.CompletedTask); }
public virtual void Transform(IBundleItemTransformContext context) { }