从命令行调用`sass`时传入变量值 [英] Passing in variable values when calling `sass` from command line

查看:51
本文介绍了从命令行调用`sass`时传入变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是在几个月前提出的,但最后没有得到答案,所以我想知道那个时候是否有人提出过.

我想使用 mixins 将我的相对 url 转换为绝对 url,而无需在文件中对主机进行硬编码.我没有使用 rails 或 ruby​​ ... 将它独立呈现,由用不同语言编写的 Web 服务器调用.能够在命令行调用期间指定基址/主机会很好——服务器提供正确的协议、主机、端口等,以便 sass 在末尾添加相对 url.

最后一个问题的解决方案"是提问者并不真正需要这个功能.也许我可以用另一种方式做到这一点?

(我也不想用预处理脚本插入整个 sass 文件)

解决方案

您寻求的功能已经是 Compass 的一部分.将 URL 辅助函数用于您的资产(图像、样式表, 字体)

.foo {背景图片:image_url('my-image.png');}

与您的问题相关的 config.rb 选项是:

  • http_path
  • images_dir
  • relative_assets

(查看所有配置变量)

如果您想要针对开发模式和生产模式设置不同的设置,您可以这样做:

if environment == :production相对资产 = 真elsif 环境 == :development相对资产 = 假结尾

要更改模式,您的命令需要添加环境标志:

compass compile -e 制作

This question was asked a few months ago but ended not having an answer so I'm wondering if in that time one has come up.

I want to use mixins to turn my relative url's into absolute ones without hard-coding the host in the file. I'm not using rails or ruby ... rendering it standalone, called by a web server written in a different language. it'd be nice to be able to specify the base/host during the command line call -- with the server supplying the proper protocol, host, port, etc. for sass to just tack on relative url's at the end of.

The 'solution' that the last question had was that the asker didn't really need this functionality. Maybe I can do this another way?

(I'd also rather not interpolate the entire sass file with a pre-processing script)

解决方案

The functionality you seek is already part of Compass. Use the URL helper functions for your assets (images, stylesheets, fonts)

.foo {
    background-image: image_url('my-image.png');
}

The config.rb options relevant to your question are:

  • http_path
  • images_dir
  • relative_assets

(see all configuration variables)

If you want to have settings that are different for development vs production mode, you can do this:

if environment == :production
    relative_assets = true
elsif environment == :development
    relative_assets = false
end

To change modes, your command requires the addition of the environment flag:

compass compile -e production

这篇关于从命令行调用`sass`时传入变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆