将缩进的sass语法编译为css样式表
isass的Python项目详细描述
isass(缩进sass)编译 SASS-indented-syntax 进入css或scss。
import isass sass = ''' body width: 500px ''' print isass.get_css(sass) print isass.get_scss(sass)
isass使用pyScss作为其 内部编译器,编译scss到css。所以isass是一个sass 到scss转换器,包括:
- All皮斯卡斯 features是 支持
- a**Command Line Interface**
- 自动复制output.css的**Watchdog** 更改一个或多个源文件时。
安装
最新稳定版本:
$ pip install isass # or $ easy_install isass
开发版本:
pip install git+git@github.com:pylover/isass.git
来源:
$ cd source_dir $ python setup.py install
语法参考
线路延伸
以,结尾的行将继续到下一行:
#container, #article_container, #sidebar_container, #footer_container, #useless_container background-color: #DDD
第一行是一整行:
#container, #article_container, #sidebar_container #footer_container, #useless_container { background-color: #DDD; }
进口
一个方便的小命令是@importthat-surprise-supper-imports 将外部.sass文件放入当前.sass文件。
假设你有一个night.sass:
body background-color: black color: white
然后在您的文件中style.sass:
@import night.sass #sunny-message background-color: white color: yellow
产生:
body { background-color: #000000; color: #ffffff; } #sunny-message { background-color: #ffffff; color: #ffff00; }
isass查找与当前工作相关的文件名 目录。请不要滥用进口货,它不会检查通知 进口-那会对你不利。
当然,您希望利用编程语法 sass引入的扩展。这将要求您预先安装 PySCSS模块,然后编译:
import isass s = ''' @mixin box($width) width: $width px body @include box(500) ''' print isass.get_css(s)
变量替换
您可以使用变量,以$:
开头$highlight-color: #999 #big-box border: 1px solid $highlight-color #message color: $highlight-color
这样就更容易传递颜色 css:
#big-box { border: 1px solid #999999; } #message { color: #999999; }
表达式
拼凑简单的表达式:
$big-width: 500 #container width: $big-width px $panel-left float: left width: $big-width/2 px
我们在css中得到:
#container { width: 500 px; } $panel-left { float: left; width: 250 px; }
只要注意/作为除法表达式将是无畏的,所以 如果/出现在url()参数中,请用引号将其括起来 ""。
混入参数
将公共元素组合在一起,并可以接受参数,这些参数是 以@:
开头@mixin left($dist) float: left margin-left: -$dist width: $dist - 20 padding-right: 20 #sidebar @include left(200px)
给出:
#sidebar { float: left; margin-left: -200px; width: 180px; padding-right: 20; }
嵌套
方便的嵌套和自引用&以节省更多的输入:
#article a font: family: Garamond &:link text-decoration: none &:hover text-decoration: underline
展开成:
#article a { font-family: Garamond; } #article a:link { text-decoration: none; } #article a:hover { text-decoration: underline; }
类扩展
以新的方式扩展一个类:
#message border: 1px solid red #bad-message @extend #message background-color: red
很容易创建类似的类:
#bad-message, #message { border: 1px solid #ff0000; } #bad-message { background-color: #ff0000; }
规范语法引用是 sass-lang.com
命令行界面
$ isass --help usage: isass [-h] [-o OUTPUT] [-c] [-l [LIB_DIRS]] [-e [EXTENSION]] [-w] [sources [sources ...]] isass compiles SASS-indented-syntax into CSS or SCSS. positional arguments: sources Source files or directories to process. default: standard input. example: `./*.sass` or `.` optional arguments: -h, --help show this help message and exit -o OUTPUT, --output OUTPUT Output file. default: standard output -c, --scss Skip scss compilation, just return scss contents. -l [LIB_DIRS], --lib-dir [LIB_DIRS] Library dir to search for @imports. -e [EXTENSION], --extension [EXTENSION] Search for this file extension. -w, --watch Watch for source modifications, and update output.
cli示例:
从sources.sass读取sass,并将生成的css写入标准 输出
$ isass < source.sass $ isass < source.sass > out.css
从源中的所有*.sass文件、额外源目录和 然后将生成的css写入标准输出
$ isass sources/ extra-sources/ myfile.sass > out.css
您可以使用-o或-output选项将生成的结果写入 特定文件。
$ isass -o out.css sources/
从sass文件生成scss而不是css
$ isass -c < source.sass
监视源文件中的更改,并自动更新 任何变化。
$ isass -wo out.css source-dir/
看门狗
您可以通过上面提到的cli或代码使用watchdog:
from isass import SassObserver observer = SassObserver() observer.add_output('style.css', dirs='my-source-dir', lib_dirs='sass-libs') observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join()
清单
可以创建有关编译器输入/输出文件的清单文件。看见 示例:
#file: myproject.manifest public: output: 'style.css' libdirs: - libdir sources: - sass_dir1 - sass_dir2 - file1.sass - file2.sass admin: output: minified: 'admin.min.css' normal: 'admin.css' libdirs: - libdir sources: - sass_dir2 - sass_dir3 - file1.sass - file3.sass from isass import SassObserver observer = SassObserver() observer.add_manifest('myproject.manifest') observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join()
评论
注释以/*开头,并在每行上实现 依据:
将给予: