0

I've got a problem with different .css output path (to specific file) in compass project.

Let's say I've got directory tree like this:

 /
 ..Fonts
 ..Folder
 ..Images
 ..Sass
   .._mixins.scss
   ..[other_stuff]
 ..Styles
 ..config.rb

This is my config.rb:

http_path = "/"
css_dir = "Styles"
sass_dir = "Sass"
images_dir = "Images"
javascripts_dir = "Scripts"
fonts_dir = "Fonts"

output_style = :nested
relative_assets = true
color_output = false

Goal

I need to use sass inside "Folder" dir, I mean some example.scss file has to be compiled into example.css inside "Folder". But, I have to use compass with relative url helpers and some mixins defined in "Sasss/_mixins.scss" file.

Problem

The problem is, I can't specify different output path for example.scss, because output path for scss is specified in config.rb (Styles), right? Ok, so I tried adding ruby code to config.rb in order to move example.css after it is compiled from "Styles" dir to "Folder" dir like this:

require 'fileutils'
on_stylesheet_saved do |file|
  if File.exists?(file) && File.basename(file) == "example.css"
    puts "Moving: #{file}"
    FileUtils.mv(file, File.dirname(file) + "/../Folder/" + File.basename(file))
  end
end

BUT, now relative image-url() does not work properly, because it was compiled in "Styles" dir, thus url is relative to this directory not the "Folder" one.

Solution?

So my question is: what is the best possible way or hack to achieve this?

4

1 回答 1

0

唯一优雅的解决方案是将您的 Galleria 子项目移动到一个单独的项目中。你实际上有两个项目,你为什么要把它们作为一个项目来管理?相反,请将它们分开并在部署期间将它们放在一起。

或者,从子项目中创建一个 Compass 扩展(如果它的结构和您在其中所做的更改量允许)并通过导入它(直接或通过 mixins)将必要的东西注入您的主项目。

一种肮脏的解决方案是使用符号链接:

cd Styles
ln -s ../Folder Folder

然后创建Sass/Folder/foo.sass.

但这会让人compass compile发疯,每次都重新创建整个项目(而不是只覆盖修改过的文件)。

您也可以尝试在相反的方向创建符号链接,但您必须确保您的 Web 服务器允许 以下符号链接

于 2013-07-01T17:22:56.527 回答