【问题标题】:Compile a string as a Compass file将字符串编译为 Compass 文件
【发布时间】:2011-12-20 07:15:10
【问题描述】:

有没有一种简单的方法可以将一串文本编译为罗盘(sass)样式表?

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

【问题讨论】:

    标签: ruby sass compass-sass


    【解决方案1】:

    您可以使用类方法Sass.compile。要使用.sass(缩进)语法,您需要传递:syntax => :sass 选项:

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

    注意: Compass 本身不提供等效功能,因此如果您想要 Compass 的所有好东西,您需要在代码中 @import 'compass'

    【讨论】:

      【解决方案2】:

      sass 有:

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

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

      你可以像这样使用 popen:

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

      并输出:section {\n background: #e6e6e6; }\n

      【讨论】:

        猜你喜欢
        • 2013-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-13
        • 2012-10-02
        • 1970-01-01
        • 2013-07-31
        • 2013-11-10
        相关资源
        最近更新 更多