简体   繁体   English

将字符串编译为Compass文件

[英]Compile a string as a Compass file

Is there a simple way to compile a string of text as a compass (sass) stylesheet? 是否有一种简单的方法可以将一串文本编译为指南针(sass)样式表?

Example input: "section\\n background: darken(white, 10%)" 示例输入: "section\\n background: darken(white, 10%)"

sass has: 萨斯有:

-s, --stdin   Read input from standard input instead of a n input file

and

--compass  Make Compass imports available and load project configuration.

You could use popen with something like this: 你可以使用popen这样的东西:

output = IO.popen("sass -s --compass", "w+") do |pipe|
  pipe.puts "section\n background: darken(white, 10%)"
  pipe.close_write
  pipe.read
end

and output: section {\\n background: #e6e6e6; }\\n 和输出: section {\\n background: #e6e6e6; }\\n section {\\n background: #e6e6e6; }\\n

You can use the class method Sass.compile . 您可以使用类方法Sass.compile To use .sass (indented) syntax you need to pass the :syntax => :sass option: 要使用.sass (缩进)语法,您需要传递:syntax => :sass选项:

require 'sass'

Sass.compile "section\n background: darken(white, 10%)", syntax: :sass
#=> "section {\n  background: #e6e6e6; }\n"

Note: Compass itself doesn't provide an equivalent function so if you want all of Compass' goodies you'll need to @import 'compass' in your code. 注意:指南针本身不提供等效功能,因此如果您想要所有Compass的好东西,您需要在代码中使用@import 'compass'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM