- 在安装好compass及compass-normalize(gem install compass-normalize)后,对新建的project中的config进行如下配置
require 'compass/import-once/activate'
require 'compass-normalize'
# Require any additional compass plugins here.
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "css"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "js"
- 设置编译后的css格式:
- :expanded 保留原格式
- :nested 样式名在前,一个名字一行,每个定义项各一行
- :compact 简介模式,一个样式一行
- :compressed 压缩模式,所有代码在一行上
# You can select your preferred output style here (can be overridden via the command line):
output_style = :compact
# To enable relative paths to assets via compass helper functions. Uncomment:
relative_assets = true
# To disable debugging comments that display the original location of your selectors. Uncomment:
line_comments = false
# If you prefer the indented syntax, you might want to regenerate this
# project again passing --syntax sass, or you can uncomment this:
# preferred_syntax = :sass
# and then run:
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass
- 使用compass的图片精灵的时候,生成的图片名为所建文件夹的名字,并不再加随机字符
# Get the directory that this configuration file exists in
on_sprite_saved do |filename|
if File.exists?(filename)
# FileUtils.cp filename, filename.gsub(%r{-s[a-z0-9]{10}\.png$}, '.png')
FileUtils.mv filename, filename.gsub(%r{-s[a-z0-9]{10}\.png$}, '.png')
end
end
on_stylesheet_saved do |filename|
if File.exists?(filename)
css = File.read filename
File.open(filename, 'w+') do |buffer|
buffer << css.gsub(%r{-s[a-z0-9]{10}\.png}, '.png')
end
end
end