无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

    关键字referenceinlinemultiple不是 支持。可能支持也可能不支持任何其他关键字(因为 在撰写本文时,只有上述关键词被记录在案, 2015年6月26日)。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
用Java学习Eclipse可视化编辑器Swing   eclipse如何找到运行Java程序所需的时间?   JAVA用于在Tomcat 8上运行Jena API的lang.UnsupportedClassVersionError   java在Main中调用字符串方法   javascript“子进程”。exec无法运行Java函数   java如何使用Gmail API获取电子邮件正文内容   java为什么客户端看不到服务器发送的第一条消息?   java无法在安卓 WebView中滚动到顶部   从服务器运行web服务时,java代码中的日期为空   从子任务返回后执行后台任务时发生java错误   java无法一致地处理弹出窗口   java(Android)通过蓝牙向µ控制器发送字节   java无法在emulator中启动AVD?安卓工作室   Android Java应用程序正在冻结,没有返回错误消息   java如何使用TestNg记录测试历史?