本文整理汇总了C#中Microsoft.Ajax.Utilities.Minifier.MinifyStyleSheet方法的典型用法代码示例。如果您正苦于以下问题:C# Minifier.MinifyStyleSheet方法的具体用法?C# Minifier.MinifyStyleSheet怎么用?C# Minifier.MinifyStyleSheet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Ajax.Utilities.Minifier
的用法示例。
在下文中一共展示了Minifier.MinifyStyleSheet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompressContent
public string CompressContent(string content)
{
var minifier = new Minifier();
if (settings != null)
{
return minifier.MinifyStyleSheet(content, settings);
}
return minifier.MinifyStyleSheet(content);
}
示例2: Minify
public string Minify(string content)
{
var minifier = new Minifier();
var stylesheet = string.Empty;
stylesheet = Settings != null
? minifier.MinifyStyleSheet(content, Settings)
: minifier.MinifyStyleSheet(content);
return stylesheet;
}
示例3: Minify
public string Minify(string content)
{
var minifier = new Minifier();
var stylesheet = string.Empty;
if (Settings != null)
{
stylesheet = minifier.MinifyStyleSheet(content, Settings);
}
else
{
stylesheet = minifier.MinifyStyleSheet(content);
}
return stylesheet;
}
示例4: MinifyCss
private static MinificationResult MinifyCss(Config config, string file)
{
string content = File.ReadAllText(file);
var settings = CssOptions.GetSettings(config);
if (config.Minify.ContainsKey("enabled") && config.Minify["enabled"].ToString().Equals("false", StringComparison.OrdinalIgnoreCase))
return null;
var minifier = new Minifier();
// Remove control characters which AjaxMin can't handle
content = Regex.Replace(content, @"[\u0000-\u0009\u000B-\u000C\u000E-\u001F]", string.Empty);
string result = minifier.MinifyStyleSheet(content, settings);
string minFile = GetMinFileName(file);
bool containsChanges = FileHelpers.HasFileContentChanged(minFile, result);
OnBeforeWritingMinFile(file, minFile, containsChanges);
if (containsChanges)
{
File.WriteAllText(minFile, result, new UTF8Encoding(true));
}
OnAfterWritingMinFile(file, minFile, containsChanges);
GzipFile(config, minFile, containsChanges);
return new MinificationResult(result, null);
}
示例5: Minify
/// <summary>
/// Minifies the specified CSS.
/// </summary>
/// <param name="resource">The CSS to minify.</param>
/// <returns>The minified CSS, if minification was successful; otherwise, the original CSS with minification errors appended at the end.</returns>
public string Minify(string resource)
{
if (String.IsNullOrEmpty(resource))
{
return resource;
}
var settings = new CssSettings
{
AllowEmbeddedAspNetBlocks = false
};
var minifier = new Minifier();
try
{
resource = minifier.MinifyStyleSheet(resource, settings);
}
catch
{
var minificationErrors = String.Join(Environment.NewLine, minifier.Errors);
resource = AppendMinificationErrors(resource, minificationErrors);
if (mLogErrors)
{
CoreServices.EventLog.LogEvent("W", "Resource minification", "CssMinificationFailed", minificationErrors);
}
}
return resource;
}
示例6: Execute
public override IEnumerable<PvcCore.PvcStream> Execute(IEnumerable<PvcCore.PvcStream> inputStreams)
{
var minifyStreams = inputStreams.Where(x => Regex.IsMatch(x.StreamName, @"\.(js|css)$"));
var resultStreams = new List<PvcStream>();
foreach (var inputStream in minifyStreams)
{
var fileContent = new StreamReader(inputStream).ReadToEnd();
var minifier = new Minifier();
var resultContent = inputStream.StreamName.EndsWith(".js") ? minifier.MinifyJavaScript(fileContent) : minifier.MinifyStyleSheet(fileContent);
foreach (var error in minifier.ErrorList)
{
Console.Error.WriteLine(error.ToString());
}
var dirName = Path.GetDirectoryName(inputStream.StreamName);
var fileName = Path.GetFileNameWithoutExtension(inputStream.StreamName) + ".min" + Path.GetExtension(inputStream.StreamName);
var resultStream = PvcUtil.StringToStream(resultContent, Path.Combine(dirName, fileName));
resultStreams.Add(resultStream);
}
return inputStreams.Where(x => !minifyStreams.Any(y => y.StreamName == x.StreamName)).Concat(resultStreams);
}
示例7: MinifyString
public static string MinifyString(string extension, string content)
{
if (extension == ".css")
{
Minifier minifier = new Minifier();
CssSettings settings = new CssSettings();
settings.CommentMode = CssComment.None;
if (WESettings.GetBoolean(WESettings.Keys.KeepImportantComments))
{
settings.CommentMode = CssComment.Important;
}
return minifier.MinifyStyleSheet(content, settings);
}
else if (extension == ".js")
{
Minifier minifier = new Minifier();
CodeSettings settings = new CodeSettings()
{
EvalTreatment = EvalTreatment.MakeImmediateSafe,
PreserveImportantComments = WESettings.GetBoolean(WESettings.Keys.KeepImportantComments)
};
return minifier.MinifyJavaScript(content, settings);
}
return null;
}
示例8: MinifyCss
/// <summary>
/// Minifies the CSS.
/// </summary>
/// <param name="css">The CSS.</param>
/// <returns></returns>
public static String MinifyCss(String css)
{
if (String.IsNullOrWhiteSpace(css))
return css;
var min = new Minifier();
return min.MinifyStyleSheet(css);
//return Yahoo.Yui.Compressor.CssCompressor.Compress(css);
}
示例9: CompressContent
public string CompressContent(string content, bool removeComments)
{
var settings = new CssSettings();
if(removeComments)
settings.CommentMode = CssComment.None;
var minifier = new Minifier();
return minifier.MinifyStyleSheet(content, settings);
}
示例10: Compress
protected override string Compress(string source)
{
var minifier = new Minifier();
var minified = minifier.MinifyStyleSheet(source);
if (minifier.Errors.Count > 0)
{
return source;
}
return minified;
}
示例11: Process
public override void Process(BundleContext context, BundleResponse response)
{
response.ContentType = ContentType.JavaScript;
if (context.HttpContext.IsDebuggingEnabled)
{
return;
}
var minifier = new Minifier();
response.Content = minifier.MinifyStyleSheet(response.Content);
}
示例12: Write
public void Write(Module module)
{
var minifier = new Minifier();
textWriter.Write(
minifier.MinifyStyleSheet(
string.Join(
"\r\n",
module.Resources.Select(ReadCss)
)
)
);
}
示例13: MinifiContentToString
public static string MinifiContentToString(string content, ContentType contentType)
{
Minifier minifier = new Minifier();
if (contentType == ContentType.css)
{
content = minifier.MinifyStyleSheet(content);
}
else if (contentType == ContentType.javascript)
{
content = minifier.MinifyJavaScript(content);
}
return content;
}
示例14: MinifyContent
public static byte[] MinifyContent(string content, ContentType contentType)
{
Minifier minifier = new Minifier();
if (contentType == ContentType.css)
{
content = minifier.MinifyStyleSheet(content);
}
else if (contentType == ContentType.javascript)
{
content = minifier.MinifyJavaScript(content);
}
return Encoding.UTF8.GetBytes(content);
}
示例15: Minify
private static void Minify(HttpResponse response, string file, string ext)
{
string content = File.ReadAllText(file);
Minifier minifier = new Minifier();
if (ext == ".css")
{
CssSettings settings = new CssSettings() { CommentMode = CssComment.None };
response.Write(minifier.MinifyStyleSheet(content, settings));
}
else if (ext == ".js")
{
CodeSettings settings = new CodeSettings() { PreserveImportantComments = false };
response.Write(minifier.MinifyJavaScript(content, settings));
}
}