2013-05-12 58 views
0

当这里是我的LessTransform I类用于分析.less文件转换为.css文件:无点失败默默解析引导2.3.1 CSS

public class LessTransform : IBundleTransform 
{ 
    public void Process(BundleContext context, BundleResponse response) 
    { 
     response.Content = dotless.Core.Less.Parse(response.Content); 
     response.ContentType = "text/css"; 
    } 
} 

我想用我的LessTransform类分析下载bootstrap.css文件。当该方法正在运行时,最初response.Content具有Bootstrap的内容。

拨打dotless.Core.Less.Parse()后,response.Content为空。解析器无声无息地失败。

为什么?

回答

3

您的LESS解析没有任何错误处理,因此所有错误都被默默忽略。如果你处理错误,你会看到以下内容:

Expected '}' on line 577 in file '../bootstrap/mixins.less': 
[576]: 
[577]:  .spanX (@index) when (@index > 0) { 
     --------------------^ 
[578]:  [email protected]{index} { .span(@index); } 

它看起来像引导使用一些带点尚不支持LESS语法。你可以尝试一个较老的Bootstrap版本(我之前使用过Bootstrap 2.0和DotLESS)。

要实现错误处理,您需要添加一个​​实现。事情是这样的:

var config = new DotlessConfiguration 
{ 
    LogLevel = LogLevel.Error, 
    // Put your custom logger implementation here 
    Logger = typeof(LessCssLogger) 
}; 

var lessEngine = new EngineFactory(config).GetEngine(); 
var outputCss = lessEngine.TransformToCss(response.Content, null); 
Response.Content = outputCss; 

LessCssLogger实现​​。 DotLESS附带您可以使用的AspResponseLogger

+0

我在哪里可以找到老版本的Bootstrap?他们在Github repo中的'tags'下载源文件,我不想自己编译这个东西。宁愿只下载一个文件。 – sergserg 2013-05-13 00:22:32

+1

我**删除了官方下载的bootstrap.css文件中的所有'\ 9'实例,并且Dotless现在正确地解析了东西。 任何人都知道'\ 9'究竟是什么,如果它不打算在那里?无论哪种方式,删除'\ 9'解决了这个问题。 – sergserg 2013-05-13 00:57:22

+0

\ 9对于IE来说显然是一种黑客攻击,所以如果你删除它,你会降低与某些版本IE的兼容性。以下是我发现的几个参考文献: http://webdood.com/?p=57 http://webdesignerwall.com/tutorials/css-specific-for-internet-explorer – SteveDonie 2013-09-06 15:34:48