无python编译器
lessc的Python项目详细描述
python包通过 首先对其进行预处理,然后调用nodejslessc程序 实际编译它。预处理解析允许 来自任何地方(包括文件系统)的内容越少, 压缩的egg文件、数据库等。这解决了 nodejs-lessc程序的局限性 依赖项是实际的文件,导入是非绝对的。
有可能,但是不太可能,这个包会变成 纯python实现的更少的编译器。
有关less的更多信息,请参见http://lesscss.org/。
安装
$ npm install less $ exportPATH="`pwd`/node_modules/.bin:$PATH" $ pip install lessc
用法
importlessc# compile a less asset in the "mypackage" python module:css=lessc.compile_asset('mypackage:path/to/style.less')# compile a less file on the filesystemcss=lessc.compile_file('../path/to/style.less')# compile a less file-like object# (if there are any relative imports, specifying `base` is necessary)css=lessc.compile_file(open('../path/to/style.less'))# compile a less string# (if there are any relative imports, specifying `base` is necessary)less=''' @import "mypackage:path/to/style.less"; // ...other less statements... '''css=lessc.compile(less)
对于更多的导入解析控件,可以指定自定义uri 解析器(将相对uri解析为绝对uri)和 自定义uri加载程序(加载绝对uri),使用解析器 以及任何compile*函数的加载器关键字:
importlesscdefresolver(uri,base=None):''' Returns the absolute URI given a base URI and a potentially absolute or relative URI. Note that `base` may be ``None`` when the initial URI is being resolved (depending on the Compiler configuration). '''# calculate the absolute URI...returnabsolute_uridefloader(uri):''' Returns a file-like object that will return the content of the specified URI. '''# fetch the object defined by `uri`returnfile_like_objectcss=lessc.compile_asset(uri,resolver=resolver,loader=loader)
或者可以创建自定义编译器并将其设置为默认编译器:
importlessccompiler=lessc.Compiler(resolver=my_custom_resolver,loader=my_custom_loader)lessc.set_default_compiler(compiler)# this will now use `my_custom_resolver` and `my_custom_loader`# to compile asset `uri`css=lessc.compile_asset(uri)
限制
<>目前,在什么样的情况下存在以下限制 使用较少的语法:不支持递归导入,将被忽略。
仅显式支持以下导入关键字:
- less
- css
- once
- optional
关键字reference、inline和multiple不是 支持。可能支持也可能不支持任何其他关键字(因为 在撰写本文时,只有上述关键词被记录在案, 2015年6月26日)。